akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7


int main(){
    double a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    double MAX = e / (100 + e);
    double water = 0, sugar = 0, max_ = 0;
    double A, B, C, D, now = 0;
    double answerSugar = 0, answerSum = 0;
    A = B = C = D = 0;
    REP(A, 30){
        REP(B, 30){
            water = a * A * 100 + b * B * 100;
            if(!water)continue;
            REP(C, 100){
                REP(D, 100){
                    sugar = c * C + d * D;
                    now = sugar / (sugar + water);
                    if(water + sugar > f || now > MAX)continue;
                    if(now < max_)continue;
                    max_ = now;
                    answerSum = water + sugar;
                    answerSugar = sugar;
                }
            }
        }
    }
    print(answerSum << " " << answerSugar);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

S = input()
n = len(S)

ans_0 = '01'*(n//2) + '0'*(n%2)
ans_1 = '10'*(n//2) + '1'*(n%2)

c_0 = c_1 = 0

for i in range(n):
    if ans_0[i] != S[i]:
        c_0 += 1
    if ans_1[i] != S[i]:
        c_1 += 1

print(min(c_0, c_1))

Measured memory_bytes: 3316
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int a,b,c,d;
	string s;
	cin >> s;
	string s1 = s;
	reverse(s.begin(), s.end());
	if (s == s1)
		cout << "Yes";
	else
		cout << "No";
	cout << endl;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int N,T,t[200000];
    long long time_ans = 0;
    
    scanf("%d%d",&N,&T);
    
    for(int i = 0; i < N; i++){
        scanf("%d",&t[i]);
    }
    
    time_ans += T;
    for(int i = 1; i < N; i++){
        if(t[i] - t[i-1] > T){
            time_ans += T;
        }
        else{
            time_ans += t[i] - t[i-1];
        }
    }
    
    printf("%lld\n",time_ans);
}

Measured memory_bytes: 896
# -*- coding: utf-8 -*-
import sys
from decimal import *
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    a,b,c=map(Decimal,input().split())
    getcontext().prec=128
    if a.sqrt()+b.sqrt()<c.sqrt():
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 59500
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<algorithm>
using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b;
    cin >> c;
    if(a <= (b*c)){
        
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
	return 0;
}


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

const int MOD = 1000000007;

int main(){
	int n;
	scanf("%d", &n);
	
	vector < vector <long long> > dp = {{1, 0}, {0, 0}};
	
	for(int i = 0; i < n; i++){
		vector < vector <long long> > ndp(2, vector <long long> (2, 0));
		
		for(int a = 0; a <= 1; a++)
		for(int b = 0; b <= 1; b++){
			ndp[a][b] = (ndp[a][b] + dp[a][b] * 8) % MOD;
			ndp[1][b] = (ndp[1][b] + dp[a][b]) % MOD;
			ndp[a][1] = (ndp[a][1] + dp[a][b]) % MOD;
		}
		dp = ndp;
	}
	
	printf("%lld\n", dp[1][1]);
	 
	return 0;
}


Measured memory_bytes: 3744
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int h, n;
int a[10010];
int b[5] = {0b0000, 0b0011, 0b0110, 0b1100, 0b1111};
int c[5] = {0, 1, 1, 1, 2};
int dp[10010][5];
int ans;

int main(){
	scanf("%d %d", &h, &n);
	for(int i=0; i<n; ++i){
		int x, y;
		scanf("%d %d", &x, &y);
		a[y] += 1<<x;
	}
//	for(int i=0; i<h; ++i) printf("%d\t", a[i]);
//	printf("\n");
//	for(int i=0; i<5; ++i) printf("%d\n", b[i]);
	for(int i=1; i<h; ++i)
		for(int j=0; j<5; ++j)
			for(int k=0; k<5; ++k)
				if((a[i-1] & b[j]) == 0 && (a[i] & b[j]) == 0 && (b[k] & b[j]) == 0)
					dp[i][j] = max(dp[i][j], dp[i-1][k] + c[j]);
	for(int i=0; i<5; ++i) ans = max(ans, dp[h-1][i]);
	printf("%d\n", ans);
}

Measured memory_bytes: 2976
n=input()
a,b,c=[0],[0],[0]
for i in range(n):
    k=map(int,raw_input().split())
    a.append(max(b[i],c[i])+k[0])
    b.append(max(a[i],c[i])+k[1])
    c.append(max(b[i],a[i])+k[2])
print max(a[-1],b[-1],c[-1])


Measured memory_bytes: 49820
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split("");
      String[] nyureal=sc.nextLine().split("");


//int num=Integer.parseInt(sn[0]);
//int num2=Integer.parseInt(sn[1]);

int count=0;

for(int i=0;i<nyu.length;i++){
if(nyu[i].equals(nyureal[i])){
count++;
}
}




System.out.println(count);

//System.out.println(a/b);


	}
}

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

int main(){
	int r,g,b;
	cin>>r>>g>>b;
	int k;
	cin>>k;
	int c=0;
	while(g<=r){
		g*=2;
		c++;
	}
	while(b<=g){
		b*=2;
		c++;
	}
	if(c<=k){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3616
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    let mut ans = 0;
    let mut now = 1;
    while now < b {
        now += a - 1;
        ans += 1;
    }
    println!("{}", ans);
}

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

int64_t lucas_num(int n) {
  if (n == 0)
    return 2;
  
  if (n == 1)
    return 1;
  
  int64_t ans = 0;
  int64_t buf0 = 2;
  int64_t buf1 = 1;
  for (int i = 2; i <= n; i++) {
    ans = buf0 + buf1;
    buf0 = buf1;
    buf1 = ans;
  }
  
  return ans;
}

int main() {
  int n;
  
  cin >> n;
  
  cout << lucas_num(n) << endl;
  
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
vector <pair<ll,ll> >stores;
ll n,m;
ll spent;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        ll a,b;cin>>a>>b;
        stores.push_back(make_pair(a,b));
    }
    sort(stores.begin(),stores.end());
    ll buy = 0;
    for(int i=0;i<stores.size();i++){
        ll cost,stock;
        cost=stores[i].first;
        stock=stores[i].second;

        if(buy+stock > m){
            ll p = m - buy;
            spent += p*cost;
            break;
        }
        else{
            buy+=stock;
            spent += stock*cost;
        }
    }
    cout<<spent<<endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>

using namespace std;

int main(){
    int a, b, c, d, i, j, k, l, ans, cnt;
    cin >> a;
    ans = 3 * a * a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// In The Name Of God
#include <bits/stdc++.h>

#define sqr(A) ((A) * (A))
#define X first
#define Y second
#define MP make_pair
#define bsz  __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 2e5 + 100;
const int OFF = 1e5 + 30;
ll a[N], b[N], n, fen[N], ans;
vector<ll> v;

void add(int x) {
	for ( ; x < N; x += x & -x)
		fen[x]++;
}

ll get(int x) {
	ll res = 0;
	for ( ; x; x -= x & -x)
		res += fen[x];
	return res;
}

bool check(int k) {
	memset(fen, 0, sizeof fen);
	ll res = 0, mi = 0, mx = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] >= k)
			b[i] = +1;
		else
			b[i] = -1;
	for (int i = 1; i <= n; i++) {
		b[i] += b[i - 1];
		mi = min(mi, b[i]);
	}
	for (int i = 0; i <= n; i++) {
		b[i] = b[i] - mi + 1;
		mx = max(mx, b[i]);
	}
	add(b[0]);
	for (int i = 1; i <= n; i++) {
		res += get(b[i]);
		add(b[i]);
	}
	return res >= n * (n + 1) / 4LL;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		v.push_back(a[i]);
	}
	sort(all(v));
	v.resize( unique(all(v)) - v.begin() );
	int l = v[0], r = v.back();
	while (r - l >= 0) {
		int mid = (l + r) / 2;
		if (check(mid))
			ans = mid, l = mid + 1;
		else
			r = mid - 1;
	}
	cout << ans << endl;
}














































Measured memory_bytes: 5236
N, A, B = map(int, input().split())
ans = 0

for i in range(1,N+1):
    if i < 10:
        if A<=i<=B:
            ans += i
    elif i < 100:
        a = i // 10
        b = i - a*10
        s = a+b
        if A<=s<=B:
            ans+=i
    elif i < 1000:
        a = i // 100
        b = (i-a*100)//10
        c = i-a*100-b*10
        s = a+b+c
        if A<=s<=B:
            ans+=i
    elif i < 10000:
        a = i // 1000
        b = (i-a*1000)//100
        c = (i-a*1000-b*100)//10
        d = i-a*1000-b*100-c*10
        s = a+b+c+d
        if A<=s<=B:
            ans+=i
    else:
        s = 1
        if A<=s<=B:
            ans+=i

print(ans)


Measured memory_bytes: 9220
#include <bits/stdc++.h>
#include<string.h>
#define ll long long int
using namespace std;
int main() {
    int d,t,s;
    cin>>d>>t>>s;
    double ans=t*s;
    if(ans>=d)
    cout<<"Yes\n";
    else
    cout<<"No\n";
}



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

int main(){
	char type[] = {'y','u','i','o','p','h','j','k','l','n','m'};
	string str;
	while(cin >> str , str != "#"){
		int now = -1,i;
		int ans = 0;
		int len = str.size();
		for(int k=0;k<len;k++){
			for(i=0;i<=10;i++){
				if(str[k] == type[i]){
					if(now == 1) ans++;
					now = 0;
					break;
				}
			}
			if(i == 11) {
				if(now == 0) ans++;
				now = 1;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1184
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Arc {
    // accessible to the reverse edge
    size_t src, dst;
    Weight capacity, flow;
    size_t rev;
    Arc() {}
    Arc(size_t src, size_t dst, Weight capacity):
        src(src), dst(dst), capacity(capacity), flow(0), rev(-1)
    {}
    Weight residue() const {
        return capacity - flow;
    }
};

bool operator<(const Arc &e, const Arc &f) {
    if (e.capacity != f.capacity) {
        return e.capacity > f.capacity;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Arcs=vector<Arc>;
using Node=vector<Arc>;
using FlowNetwork=vector<Node>;

void connect(FlowNetwork &g, size_t s, size_t d, Weight c=1) {
    g[s].push_back(Arc(s, d, c));
    g[d].push_back(Arc(d, s, 0));

    g[s].back().rev = g[d].size()-1;
    g[d].back().rev = g[s].size()-1;
}

void join(FlowNetwork &g, size_t s, size_t d, Weight c=1) {
    g[s].push_back(Arc(s, d, c));
    g[d].push_back(Arc(d, s, c));

    g[s].back().rev = g[d].size()-1;
    g[d].back().rev = g[s].size()-1;
}

Weight max_flow(FlowNetwork &g, size_t s, size_t t) {
    /* Edmonds-Karp */
    size_t V=g.size();

    Weight mflow=0;
    while (true) {
        queue<size_t> q; q.push(s);
        vector<Arc *> prev(V, NULL);
        while (!q.empty() && prev[t]==NULL) {
            size_t u=q.front(); q.pop();
            for (Arc &e: g[u]) {
                if (e.dst != s && prev[e.dst] == NULL && e.residue() > 0) {
                    prev[e.dst] = &e;
                    q.push(e.dst);
                }
            }
        }
        if (prev[t] == NULL) return mflow;

        Weight incr=INF;
        for (Arc *e=prev[t]; e!=NULL; e=prev[e->src])
            incr = min(incr, e->residue());

        mflow += incr;
        for (Arc *e=prev[t]; e!=NULL; e=prev[e->src]) {
            e->flow += incr;
            g[e->dst][e->rev].flow -= incr;
        }
    }
}

Weight max_match(FlowNetwork g, size_t x, size_t y) {
    size_t V=g.size();
    g.resize(V+2);
    for (size_t i=0; i<x; ++i)
        connect(g, V, i);

    y += x;
    for (size_t i=x; i<y; ++i)
        connect(g, i, V+1);

    return max_flow(g, V, V+1);
}

int main() {
    size_t X, Y, E;
    scanf("%zu %zu %zu", &X, &Y, &E);

    FlowNetwork g(X+Y);
    for (size_t i=0; i<E; ++i) {
        size_t x, y;
        scanf("%zu %zu", &x, &y);

        connect(g, x, X+y);
    }

    printf("%lld\n", max_match(g, X, Y));
    return 0;
}

Measured memory_bytes: 5188
#include <iostream>

using namespace std;

int N;
long long int a[100005];

int main(void) {

	cin >> N;

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

	int count = 0;
	for (int i = 1; i <= N; i++) {
		if (a[i] % 2 == 0) { count++; }
	}

	if (count == N) {
		cout << "second" << endl;
	}
	else {
		cout << "first" << endl;
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
icase=0
if icase==0:
    n,m=map(int,input().split())
    a=[]
    for i in range(m):
        ai,bi=map(int,input().split())
        a.append(ai)
        a.append(bi)
    for i in range(1,n+1):
        icnt=0
        for nn in a:
            if nn==i:
                icnt=icnt+1
        print(icnt)

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

int main()
{
    int n;
    int max = 0, ans = 0;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        if (h[i] >= max) {
            max = h[i];
            ans++;
        }
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(string s;cin>>s;){
		rep(i,s.size())
			s[i]=s[i]<'D'?s[i]+23:s[i]-3;
		cout<<s<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import math
X = int(input())

def is_prime(x):
    a = int(math.sqrt(X)) + 1
    for i in range(2,a):
        if x % i == 0:
            return False
    return True

for j in range(X,X+100):
    if is_prime(j):
        ans = j    
        break
print(ans)

Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

typedef long long int ll;
typedef string str;

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;   
    while (y) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll nCrModP(ll n, ll r, ll p) 
{ 
    if (!r) 
      return 1; 
  
	ll fac[n+1]; 
   	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p; 
}

ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);
}

void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll func(ll n){
	ll i=0;
	ll j=n;
	while(j>0)
	{
		i+=j%2;
		j/=2;
	}
	return n%i;
}

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m=0,k,i,a,b,j;
	cin >> n;
	str s;
	cin >> s;
	ll arr[n+2]={0};
	bool ab[n+2];
	for(i=0;i<n;i++)
	{
		if(s[i]=='1')
		{
			ab[i]=1;
			m++;
		}
		else
			ab[i]=0;
	}
	a=0,b=0;
	for(i=0;i<n;i++)
	{
		if(ab[i])
		{
			if(m>0)
			{
				a+=power(2,n-1-i,m+1);
				a%=(m+1);
			}
			if(m>2)
			{
				b+=power(2,n-1-i,m-1);
				b%=(m-1);
			}
		}
	}
	// cout << a << " " << b << "\n";
	for(i=0;i<n;i++)
	{
		ll val;
		if(ab[i]==0)
		{
			if(m==0)
				val=1;
			else
			{
				t=power(2,n-i-1,m+1);
				val=(a+t)%(m+1);
				arr[i]++;
			}
		}
		else
		{
			if(m>=2)
			{
				t=power(2,n-i-1,m-1);
				k=(t/(m-1))+1;
				t=((k*(m-1))-t)%(m-1);
				val=(b+t)%(m-1);
				arr[i]++;
			}
			else
			{
				val=0;
			}
		}
		while(val>0)
		{
			arr[i]++;
			val=func(val);
		}
	}
	for(i=0;i<n;i++)
	{
		cout << arr[i] << "\n";
	}
	return 0;
}

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

def sumOfSeries(a,s,e):
    n = (e-a)//s+1
    return n*(a+e)//2

def solve(N: int):
    s = 0
    for i in range(1,N+1):
        # biggest N divided by i
        e = N - N % i
        s += sumOfSeries(i,i,e)
    print(s)
    return



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

if __name__ == '__main__':
    main()

Measured memory_bytes: 63656
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5+100)
from collections import *

def dfs(v, pv, de):
    for nv in G[v]:
        if nv==pv:
            continue
        
        dfs(nv, v, de+1)
        left[v] = max(left[v], left[nv]-1)
        right[v] = min(right[v], right[nv]+1)
    
    if v in d:
        if d[v]<left[v] or right[v]<d[v] or (d[v]-d[root])%2!=de%2:
            print('No')
            exit()
        else:
            left[v] = d[v]
            right[v] = d[v]
    
def dfs2(v, pv, now):
    ans[v] = now
    
    for nv in G[v]:
        if nv==pv:
            continue
        
        if left[nv]<=now-1<=right[nv]:
            dfs2(nv, v, now-1)
        else:
            dfs2(nv, v, now+1)
    
N = int(input())
G = [[] for _ in range(N)]

for _ in range(N-1):
    A, B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)

d = defaultdict(int)
K = int(input())

for _ in range(K):
    V, P = map(int, input().split())
    d[V-1] = P
    root = V-1

left = [-10**18]*N
right = [10**18]*N
dfs(root, -1, 0)
ans = [-1]*N
dfs2(root, -1, d[root])
print('Yes')

for ans_i in ans:
    print(ans_i)


Measured memory_bytes: 193748
# -*- coding: utf-8 -*-

n,m=map(int,input().split())
ka=[list(map(int,input().split())) for _ in range(n)]
ans=[0 for _ in range(m)]

for i in range(n):
    for j in range(ka[i][0]):
        ans[ka[i][j+1]-1]+=1
print(ans.count(n))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
#define INT_MAX 1<<30
const ll mod = 1e9+7;

int main(){
	ll n; cin >> n;
	string s; cin >> s;
	vl l(26,0), r(26,0);
	string left = s.substr(0,n), right = s.substr(n,n);
	rep(i,n){
		l[left[i]-'a']++;
		r[right[i]-'a']++;
	}
	reverse(all(right));
	rep(i,26){
		if(l[i] != r[i]){
			cout << 0 << endl;
			return 0;
		}
	}
	ll ans = 0;
	rep(bit,1<<n){
		l = r;
		string t,u;
		rep(i,n){
			if(bit>>i & 1) t.push_back(s[i]);
			else u.push_back(s[i]);
		}
		ll m = t.size();
		vvl dp(n+1,vl(m+1,0));
		dp[0][0] = 1;
		rep(i,n){
			rep(j,m){
				if(i<j) break;
				if(right[i]==u[i-j]) dp[i+1][j] += dp[i][j];
				if(right[i]==t[j]) dp[i+1][j+1] += dp[i][j];
			}
		}
		ans += dp[n][m] * 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,m,d;
    cin>>n>>m>>d;
    cout<<fixed<<setprecision(10)<<((d==0)?1.:2.)*(n-d)/n*(m-1)/n;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define SI(a) scanf("%d",&a)
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long ll;
const int mod = 1e9+7;
const int maxn = 1e8;
using namespace std;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
ll quick_pow(ll x,ll n,ll mod){
	ll res = 1;
	while(n > 0){
		if(n & 1)	res = res * x % mod;
		x = x * x % mod;
		n >>= 1;//相当于n=n/2.详情请参考位移运算符。
	}
	return res;
}
string str;
int vis[30];
int main(){
    cin>>str;
    int len = str.length();
//cout<<len<<endl;
    if(len%2 == 1)cout<<"No"<<endl;
    else{
        ms(vis,0);
        for(int i = 0;i < len;i++)
        {
            vis[str[i]-'a']++;
            //cout<<str[i]-'a'<<endl;
        }
        bool flag = true;
        for(int i = 0;i < 26;i++)
              if(vis[i]%2!=0){
            cout<<"No"<<endl;flag = false;break;
        }
        if(flag)cout<<"Yes"<<endl;
    }
    return 0;
}


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

int main(void)
{
   int i=0, f=0, x;
   char s[11];

   scanf("%s",s);

   while(i<strlen(s)){
      x=0;
      while((s[i]=='A')||(s[i]=='C')||(s[i]=='G')||(s[i]=='T')){
         i++;
         x++;
      }
      if(x==0)
         i++;
      if(f<x)
         f=x;
   }

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

Measured memory_bytes: 128
import numpy as np
S=list(input())
U=[]
for i in range(len(S)-2):
    A=int(S[i])*100+int(S[i+1])*10+int(S[i+2])
    U.append(A)
U=np.array(U)
D=U-753
print(min(abs(D)))

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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int mxn = 2e5+7;

int a[mxn];

int main(){
	setIO();
	int n, x = 0; cin >> n;
	for (int i = 0; i < n && cin >> a[i]; i++) x ^= a[i];
	for (int i = 0; i < n; i++) cout << (x^a[i]) << " ";
	cout << endl;
}

Measured memory_bytes: 4432
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

const int N = 205;
const int M = 1e7 + 5;

int x[N], pos[N];

class BipartialGraph {
private :
  bool G[N][N], vis[N];
  int lkn[N];
public :
  BipartialGraph() {
    memset(G, 0, sizeof G);
  }
  inline void Add(int x, int y) {
    G[x][y] = 1;
  }
  inline bool Match(int x) {
    for (int i = 0; i < N; i ++)
      if (G[x][i] && !vis[i]) {
	vis[i] = 1;
	if (lkn[i] == -1 || Match(lkn[i])) {
	  lkn[i] = x;
	  return 1;
	}
      }
    return 0;
  }
  inline int MaxMatch() {
    int ret = 0;
    memset(lkn, -1, sizeof lkn);
    for (int i = 0; i < N; i ++) {
      memset(vis, 0, sizeof vis);
      if (Match(i)) ret ++;
    }
    return ret;
  }
} solver;

bool notp[M];
int prime[700000];

inline void  make_prime(int Max) {
  int tot = 0;
  for (int i = 2; i <= Max; i ++) {
    if (!notp[i]) prime[++ tot] = i;
    for (int j = 1; j <= tot && i * prime[j] <= Max; j ++) {
      notp[i * prime[j]] = 1;
      if (i % prime[j] == 0) break;
    }
  }
  notp[0] = notp[1] = notp[2] = 1;
}

int main() {
  int n, m = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++) scanf("%d", &x[i]);
  for (int i = 1; i <= n; i ++) {
    if (i == 1 || x[i - 1] != x[i] - 1) pos[++ m] = x[i];
    if (i == n || x[i + 1] != x[i] + 1) pos[++ m] = x[i] + 1;
  }
  make_prime(pos[m] - pos[1]);
  for (int i = 1; i <= m; i ++) {
    if (pos[i] & 1) continue;
    for (int j = 1; j <= m; j ++)
      if ((pos[j] & 1) && !notp[abs(pos[j] - pos[i])]) solver.Add(i, j);
  }
  int k = solver.MaxMatch(), ev = 0, od = 0;
  for (int i = 1; i <= m; i ++) {
    if (pos[i] & 1) od ++;
    else ev ++;
  }
  ev -= k; od -= k;
  int ans = k + (ev / 2 + od / 2) * 2 + 3 * (ev & 1);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  string ans = "APPROVED";
  REP(i, n){
    if(!(a[i]%2)){
      if(a[i]%3 != 0 && a[i]%5 != 0) ans = "DENIED";
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val d = Scanner(System.`in`).nextInt()
  	if(d==22){
       print("Christmas Eve Eve Eve")
    }
  else if(d==23){
     print("Christmas Eve Eve")
  }
  else if(d==24){
     print("Christmas Eve")
  }
  else{
    print("Christmas")
  }
}


Measured memory_bytes: 31264
from collections import defaultdict
D=int(input())
clist=list(map(int,input().split()))
smat=[[int(x) for x in input().split()] for _ in range(D)]
#print(clist)
#print(smat)

last_dic=defaultdict(int)
answer=0
for d in range(D):
  t=int(input())
  answer+=smat[d][t-1]
  last_dic[t]=d+1

  for i in range(26):
    answer-=clist[i]*(d+1-last_dic[i+1])
    
  print(answer)

Measured memory_bytes: 9524
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long n;
	cin>>n;
	long long a[n],b[n],sum=0,c[n];
	for(long long i=0;i<n;++i){
		cin>>a[i]>>b[i];
		sum-=b[i];
		c[i]=a[i]+b[i];
	}
	sort(c,c+n,greater<long long>());
	for(long long i=0;i<n;i+=2)
		sum+=c[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	{
		if(a[0]) {
			printf("0\n");
			return 0;
		}

		std::map<int, int> mp;
		for(int i = 0; i < n; i++) {
			if(++mp[a[i]] > 3 or a[i] > i) {
				printf("0\n");
				return 0;
			}
		}
	}

	i64 ans = 1;
	const int MOD = 1e9 + 7;
	std::map<int, int> mp; mp[-1] = 3;
	for(int i = 0; i < n; i++) {
		(ans *= mp[a[i] - 1]--) %= MOD;
		mp[a[i]]++;
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
int main()
{
	int n;
	cin>>n;
	vector<ll> a(n);

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

	map<ll,ll> mp;

	ll count=0;

	for(int i=0;i<n;i++)
	{
		ll temp=-(a[i]-i);

		count+=mp[temp];

		mp[a[i]+i]++;
	}

	cout<<count<<endl;

	return 0;
}

Measured memory_bytes: 27336
#include<stdio.h>

int main(void){


int w,h,x,y,r;


scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);


if(x>=-100&&x<=100&&y>=-100&&y<=100&&w>0&&w<=100&&h>0&&h<=100&&r>0&&r<=100){


if(x-r>=0&&x+r<=w&&y-r>=0&&y+r<=h){


printf("Yes\n");


}


else{


printf("No\n");


}


}


return 0;


}

Measured memory_bytes: 584
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <math.h>
#define rep(i, n)               \
    for (int i = 0; i < n; i++) \
        ;
using namespace std;
typedef long long ll;

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

    int N;
    string S;
    cin >> N >> S;

    int cnt = 0;

    for (int i = 0; i < N - 2; i++)
    {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
            cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;
int n, m, i, j, k;
char c[5];
int main(){
	for(i = 1; i <= 3; i++){
		scanf("%c", &c[i]);
		if(c[2] == 'B') c[2] = 'R';
		else c[2] = 'B';
		printf("%c", c[i]);
	}
	return 0;
}

Measured memory_bytes: 3168
def solve(a):
	l = len(a)
	h = l//2 + l%2
	a0 = [a[2*i] for i in range(h)]
	b = a.copy()
	b.sort()
	b0 = [b[2*i] for i in range(h)]

	a0 = set(a0)
	b0 = set(b0)

	return len(a0 - b0)
n = int(input())
a = [int(input()) for i in range(n)]
print(solve(a))


Measured memory_bytes: 14648
n = int(input())
a =list(map(int, input().split()))
b =list(map(int, input().split()))
ans = 0
for i in range(n):
    amari =max(b[i]-a[i], 0)
    ans += min(b[i], a[i]+a[i+1])
    a[i+1] = max(0, -amari+a[i+1])
print(ans)


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> T(H,vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> T.at(i).at(j);
    }
  }
  //１周目
  vector<vector<char>> Tre(W);
  //int K=0;
  for (int i=0; i < H; i++) {
    for (int j=0; j < W;j++) {
      if (T.at(i).at(j) == '#') {
        for (int jj=0; jj < W; jj++) {
          Tre.at(jj).push_back(T.at(i).at(jj));
        }
        break;
      }
    }  
    //if (j<W-1)
      //K++;
  } //i<Hについて終了
  
  //以下２周目
  vector<vector<char>> Trere(Tre.at(0).size());
  //int Kre=0;
  for (int i=0; i < W; i++) {
    for (int j=0; j < Tre.at(0).size();j++) {
      if (Tre.at(i).at(j) == '#') {
        for (int jj=0; jj < Tre.at(0).size(); jj++) {
          Trere.at(jj).push_back(Tre.at(i).at(jj));
        }
        break;
      }
    }  
    //if (j<K-1)
      //Kre++;
  
  } //i<Wについて終了
  
  //cout << Trere.size() << endl;
  //cout << Trere.at(0).size() << endl;
  //cout << Trere.at(0).at(0) << endl;
 //cout << Kre << endl;
  
  for (int i = 0; i < Trere.size(); i++) {
    for (int j = 0; j < Trere.at(0).size(); j++) {
      cout << Trere.at(i).at(j);
      if (j==Trere.at(0).size()-1)
        cout << endl;
    }
  } 
  
 
}

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

using namespace std;

struct Cake {
	int age, w, h;
	Cake() {};
	Cake(int a, int w, int h) :age(a), w(w),h(h) {};
	bool operator < (const Cake& c) {
		if (age != c.age) return age < c.age;
		return w * h < c.w*c.h;
	}
};

int main() {
	int n, w, d;
	while (cin >> n >> w >> d) {
		if (n == 0 && w == 0 && d == 0) break;
		//cout << n << " " << w << " " << d << endl;
		vector<Cake> c;
		c.push_back({ -1, w, d });
		for (int i = 0; i < n; i++) {
			int a, s;
			cin >> a >> s;
			a--;
			int x = c[a].w, y = c[a].h;
			s %= (x + y);
			//cout << a << " " << s << endl;
			if (s < x) {
				c[a] = { i, s, y };
				c.push_back({ i, x - s, y });
			}
			else {
				s -= x;
				c[a] = { i, x, s };
				c.push_back({ i,x,y - s });
			}
			sort(c.begin(), c.end());
			/*for (int i = 0; i < c.size(); i++) {
				cout << " " << c[i].w << " " << c[i].h << endl;
			}*/
			//cout << endl;
		}
		vector<int> ans;
		for (int i = 0; i < c.size(); i++) ans.push_back(c[i].h*c[i].w);
		//cout << " " << c.size() << " " << ans.size() << endl;
		sort(ans.begin(), ans.end());
		for (int i = 0; i < ans.size(); i++) {
			if (i != 0) cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 3056
import sys
sys.setrecursionlimit(500000)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    A = list(mi())
    A.sort(reverse=True)
    ans = A[0]
    if N%2:
        ans += 2*sum(A[1:N//2+1])-A[N//2]
    else:
        ans += 2*sum(A[1:N//2])

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{  
	int n;
	string s;
	cin >> n >> s;
	long long r, g, b;
	r = g = b = 0;
	for (int i = 0; i < n; i++) {
		if (s[i]=='R') {
			r++;
		}
		else if (s[i] == 'G') {
			g++;
		}
		else {
			b++;
		}
	}
	long long ans = r * g * b;
	int a=0;
	for (int i = 0; i < n-2; i++) {
		for (int j = i+1; j < n-1; j++) {		
			int k = 2 * j - i;
				if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]&&k<n) {
					a++;
				}
		}
	}
	cout << ans-a << endl;
	return 0;
}

Measured memory_bytes: 3628
def factorize(n):
    #https://python.ms/factorize/#%E5%AE%9F%E8%A3%85
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append([b, e])
        b, e = b + 1, 0
    if n > 1:
        fct.append([n, 1])
    return fct

n = int(input())

num = 1
for i in range(1,n+1):
    num *= i

fact = factorize(num)
#print(fact)
ans = 1
for i in range(len(fact)):
    ans *= (fact[i][1]+1)

print(ans%(10**9+7))

Measured memory_bytes: 9156
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

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

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

  	int a, c;
  	long long max = -99999999999;
  	long long ttt, sss, hhh;
  	vector<int> mmm, www, xxx;
	ttt = 0;
  	for (int i = -1; i < k; i++) {

      if (i < n) {

        if (i >= 0) {	// -1 の時は取得しない
          a = aaa[i];
          ttt += a; if (max < ttt) { max = ttt; }
          if (a < 0) { mmm.push_back(a); }

          c = min((int)mmm.size(), k - (i + 1));
          if (c > 0) {
            hhh = ttt;
            xxx = mmm;
            sort(xxx.begin(), xxx.end(), std::greater<int>());
            vector<int>::reverse_iterator itr = xxx.rbegin();
            for (int q = 0; q < c; q++) {
              a = *itr++;
              hhh -= a; if (max < hhh) { max = hhh; }
            }
          }
        }

        sss = ttt;
      	www = mmm;
        for (int j = 0; j < k - (i + 1); j++) {

          if (i + 1 + j < n) {
	        a = aaa[n - 1 - j];
	        sss += a; if (max < sss) { max = sss; }
	        if (a < 0) { www.push_back(a); }
      	  }

          c = min((int)www.size(), k - (i + 1 + j + 1));
          if (c > 0) {
            hhh = sss;
	      	xxx = www;
    	    sort(xxx.begin(), xxx.end(), std::greater<int>());
            vector<int>::reverse_iterator itr = xxx.rbegin();
	        for (int q = 0; q < c; q++) {
              a = *itr++;
		      hhh -= a; if (max < hhh) { max = hhh; }
            }
          }
        }
      }
    }

    cout << max << endl;
  
	return(0);
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
	int N;
	cin >> N;

	vector<int> H(N);
	for(int i=0; i<N; i++){
		cin >> H.at(i);
	}

	int max=0;
	int cnt=0;
	for(int i=0; i<N; i++){
		if(H.at(i)>=max){
			cnt++;
			max = H.at(i);
		}
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n=int(input())
    A=np.array(list(map(int, input().split())),dtype='int64')
    ans = 0
    mod = 10**9 + 7
    for i in range(60):
        q = int((A >> i & 0b1).sum())
        ans += q*(n-q)*pow(2, i, mod)
        ans %= mod
    print(ans)
 
if __name__=='__main__':
    main()

Measured memory_bytes: 68864
t = int(input())
for i in range(t):
    n, k  = map(int, input().split()) # n = len(xlist)
    xlist = list(map(int, input().split()))
    if (n <= k):
        print(0)
    else:
        betweenx = [xlist[i+1] - xlist[i] for i in range(n-1)]
        betweenx.sort()
        print(sum(betweenx[:n-k]))
        


Measured memory_bytes: 21752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << x
#define print(x) cout << x << '\n'
#define debug(x) cerr << #x << ": " << x << '\n'
ll gcd(ll a, ll b){
    return b != 0 ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, z, w, ans = 0, cnt = 0, mx = 0, mn = INF;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        ll x[n], y[n], h[n];
        ll g[3] = {-1, -1, -1};
        vector<tuple<ll, ll, ll>> vec;
    	rep(i, n){
    		cin >> x[i] >> y[i] >> h[i];
    		if(h[i] >= 1){
                g[0] = x[i], g[1] = y[i], g[2] = h[i];
            }
    	}
    	rep(i, 101){
    		rep(j, 101){
    			ll v = g[2] + abs(g[0] - i) + abs(g[1] - j);
                maxs(v, 0LL);
                bool flag = true;
    			rep(k, n){
    				ll vv = v - abs(x[k] - i) - abs(y[k] - j);
                    maxs(vv, 0LL);
    				if(h[k] != vv){
                        flag = false;
                        break;
                    }
    			}
    			if (flag == true){
                    vec.pb(make_tuple(i, j, v));
                }
    		}
    	}
    	if (vec.size() == 1) {
    		cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
    	}
    }
}



Measured memory_bytes: 256
import collections
H,W=map(int,input().split())
s=[list(str(input()))for i in range(H)]

ss=[['' for j  in range(W+2)]for i in range(H+2)]
for i in range(H):
    for j in range(W):
        ss[i+1][j+1]=s[i][j]

for i in range(H):
    for j in range(W):
        if ss[i][j]=='#':
            if ss[i][j-1]=='#' or ss[i][j+1]=='#' or ss[i-1][j]=='#' or ss[i+1][j]=='#':
                continue
            else:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 9448
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<vector<pair<int, int> > > v(n + 1);
  //vector<pair<int, int> e(n);
  for(int i = 1; i < n; i++){
    int a, b; cin >> a >> b;
    //e[i] = make_pair(a, b);
    v[a].push_back(make_pair(b, i));
    v[b].push_back(make_pair(a, i));
  }

  vector<set<int> > cl(n + 1);
  vector<int> visited(n + 1, false), pc(n + 1), p(n + 1), ans(n + 1);

  queue<int> q;
  q.push(1);

  pc[1] = -1;
  p[1] = -1;
  int c, nx, maxj = 0, en;
  while(q.size() > 0){
    c = q.front();
    q.pop();
    int j = 1;
    for(int i = 0; i < v[c].size(); i++){
      nx = v[c][i].first;
      en = v[c][i].second;
      if(nx == p[c]) continue;
      if(j == pc[c]) j++;
      cl[c].insert(j);
      pc[nx] = j;
      p[nx] = c;
      ans[en] = j;
      maxj = max(maxj, j);
      j++;
      q.push(nx);
    }
  }
  cout << maxj << endl;
  for(int i = 1; i < n; i++){
    cout << ans[i] << endl;
  }
  /*for(int i = 1; i <= n; i++){
    cout << i << " -> ";
    for(auto it = cl[i].begin(); it != cl[i].end(); it++){
      cout << *it << " ";
    }
    cout << endl;
  }*/
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 17408
#include <stdio.h>

int main(void) {
	int N;
	int mareitaso = 0;
	if (scanf("%d", &N) != 1) return 1;
	while (N > 0) {
		mareitaso += N % 10 == 2;
		N /= 10;
	}
	printf("%d\n", mareitaso);
	return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int64;
 
int main()
{
  int N, W;
  int w1;
  cin >> N >> W;
 
  vector< int > st[4];
  for(int i = 0; i < N; i++) {
    int w, v;
    cin >> w >> v;
    if(i == 0) w1 = w;
    st[w - w1].push_back(v);
  }
  for(int i = 0; i < 4; i++) {
    sort(begin(st[i]), end(st[i]));
    st[i].push_back(0);
    reverse(begin(st[i]), end(st[i]));
    for(int j = 1; j < st[i].size(); j++) {
      st[i][j] += st[i][j - 1];
    }
  }
 
  int ret = 0;
  for(int64 i = 0; i < st[0].size(); i++) {
    for(int64 j = 0; j < st[1].size(); j++) {
      for(int64 k = 0; k < st[2].size(); k++) {
        for(int64 l = 0; l < st[3].size(); l++) {
          int64 fact = w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l;
          if(fact <= W) {
            ret = max(ret, st[0][i] + st[1][j] + st[2][k] + st[3][l]);
          }
        }
      }
    }
  }
 
  cout << ret << endl;
}

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

using namespace std;


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

    string start = S.substr(0, 2);
    int startInt = atoi(start.c_str());;
    string end = S.substr(2, 2);
    int endInt = atoi(end.c_str());;

    // MM 1 - 12
    // YY 0 - 99

    bool MMYY = false;
    if (1<= startInt && startInt <= 12 && 0 <= endInt && endInt <= 99) {
        MMYY = true;
    }

    bool YYMM = false;
    if (0 <= startInt && startInt <= 99 && 1 <= endInt && endInt <= 12) {
        YYMM = true;
    }

    if (YYMM && MMYY) {
        cout << "AMBIGUOUS" << endl;
        return 0;
    }

    if (YYMM) {
        cout << "YYMM" << endl;
        return 0;
    }

    if (MMYY) {
        cout << "MMYY" << endl;
        return 0;
    }

    cout << "NA" << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef long long ll;
typedef long double lf;
ll n,arr[100004],dp[100004];
ll solve(ll idx)
{
	if(idx == n-1)
	return 0;
	if(dp[idx] != -1)
	return dp[idx];
	ll ans=0;
	if(idx<n-2)
	{
		ans=min(abs(arr[idx]-arr[idx+1])+solve(idx+1),abs(arr[idx]-arr[idx+2])+solve(idx+2));
	}
	else
	ans=abs(arr[idx]-arr[idx+1])+solve(idx+1);
	return dp[idx]=ans;
}
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(ll i=0;i<n;i++)
	cin>>arr[i];
	cout<<solve(0);
	return 0;
}

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

using namespace std;

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    vector<int> ans;
    for(int i=1;i<101;i++){
        if(a%i == 0 && b%i ==0){
            ans.push_back(i);
        }
    }
    vector<int>::iterator ansitr = ans.end()-k;
    cout << *ansitr << endl;
}

Measured memory_bytes: 256