akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#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 rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())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;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  int n;
  cin>>n;
  vl a(n);
  cin>>a;
  int m=0;
  rep(i,n){
    if(a[i]<0) m++;
  }
  rep(i,n){
    a[i]=abs(a[i]);
  }
  ll ans=0;
  rep(i,n){
    ans+=a[i];
  }
  if(m%2==1){
    ans -= 2*(*min_element(rng(a)));   
  }
  cout<<ans<<endl;

} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    string T;
    cin >> T;
    int N = T.size();
    for(int i = 0; i < N; i++) {
        if(T[i] == '?') {
            T[i] = 'D';
        }
    }
    cout << T << endl;
}

Measured memory_bytes: 3752
#include<stdio.h>

int main()
{
	int a[3][3],n,b[10],i,j,k;

	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			scanf("%d",&a[i][j]);
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);
	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			for(k=0;k<n;k++)
				if(a[i][j]==b[k])
					a[i][j]+=100;

	for(i=0;i<3;i++)
		if((a[i][0]>100)&&(a[i][1]>100)&&(a[i][2]>100)){
			printf("Yes\n");
			return 0;
		}
	for(j=0;j<3;j++)
		if((a[0][j]>100)&&(a[1][j]>100)&&(a[2][j]>100)){
			printf("Yes\n");
			return 0;
		}
	if((a[0][0]>100)&&(a[1][1]>100)&&(a[2][2]>100)){
		printf("Yes\n");
		return 0;
	}	
	else if((a[0][2]>100)&&(a[1][1]>100)&&(a[2][0]>100)){
		printf("Yes\n");
		return 0;
	}
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
while (True):
    [n, m, a] = list(map(int, input().split()))
    '''
    n: num of vertical bars
    m: num of horizontal lines
    a: bar number to check
    '''
    if [n, m, a] == [0, 0, 0]:
        # terminate
        break

    hashDict = dict()
    maxHeight = -1
    for lineNumber in range(m):
        [h, p, q] = list(map(int, input().split()))
        maxHeight = max(maxHeight, h)
        hashDict[(h, p)] = q
        hashDict[(h, q)] = p

    # Start from the max height
    currentBar = a
    for height in range(maxHeight, 0, -1):
        if (height, currentBar) in hashDict.keys():
            currentBar = hashDict[(height, currentBar)]

    print(currentBar)

Measured memory_bytes: 7912
N, K = map(int, input().split())
array = {}
for i in range(N):
    a, b = map(int, input().split())
    if not a in array:
        array[a] = 0
    array[a] += b

for k, v in sorted(array.items()):
    K -= v
    if K <= 0:
        print(k)
        break

Measured memory_bytes: 14564
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    n, m, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))

    a_sum = b_sum = 0
    a_i = b_i = 0
    while a_i < len(a_list) and a_sum + a_list[a_i] <= k:
        a_sum += a_list[a_i]
        a_i += 1
    ans = a_i

    while a_i > 0:
        # a_sum -= a_list[a_i - 1]  # wrong!
        while b_i < len(b_list) and a_sum + b_sum + b_list[b_i] <= k:
            b_sum += b_list[b_i]
            b_i += 1
            ans = max(ans, a_i + b_i)
        a_sum -= a_list[a_i - 1]  # correct!
        a_i -= 1

    while b_i < len(b_list) and a_sum + b_sum + b_list[b_i] <= k:
        b_sum += b_list[b_i]
        b_i += 1
        ans = max(ans, a_i + b_i)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

// < val の要素数
ll CountLower(const vll &vec, ll val){
    return distance(vec.begin(), lower_bound(ALL(vec), val));
}

int main(){
    ll n, k;
    cin >> n >> k;
    vll v(n);
    rep(i, n){
        cin >> v[i];
    }
    vll lsum(n+1), rsum(n+1);
    lsum[0] = rsum[0] = 0;
    rep(i, n){
        lsum[i+1] = lsum[i]+v[i];
        rsum[i+1] = rsum[i]+v[n-1-i];
    }
    
    // 解説
    ll m = min(n, k);
    ll ansmax = -1LL << 50;
    rep(a, m+1){
        rep(b, m-a+1){
            ll ans = lsum[a]+rsum[b];
            vll have;
            copy(v.begin(), v.begin()+a, back_inserter(have));
            copy(v.end()-b, v.end(), back_inserter(have));
            sort(ALL(have));
            ll z = min(CountLower(have, 0), k-a-b);
            rep(i, z){
                ans -= have[i];
            }
            ansmax = max(ansmax, ans);
        }
    }
    cout << ansmax << endl;
}

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

int main(){
  int N; cin >> N;
  long long Z,W; cin >> Z >> W;
  vector<long long> A(N);
  int ans;
  for(int i=0;i<N;i++)
    cin >> A[i];
  long long a,b;
  ans = abs(W-A[N-1]);
 
  if(N > 1){
  a = A[N-1]-W;
  b = A[N-2]-A[N-1];
  if (a < 0){
    a -= 2*a;
  }
  if (b < 0){
    b -= 2*b;
  }
    ans = max(a,b);
  
   }
  cout << ans << endl;
}
    
  
  
    

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

using ll = long long;

const ll INF = 2e15;

ll func(ll b, ll n) {
	if (b == 1) {
		return -1;
	}
	ll res = 0;
	while (n) {
		res += n % b;
		n /= b;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	ll N, S; cin >> N >> S;
	ll V = ll(sqrt(N));

	ll ans = INF;

	auto check = [&](ll b) -> void {
		if (func(b, N) == S) {
			ans = min(ans, b);
		}
	};

	for (ll b = 2; b <= V; b++) {
		check(b);
	}

	check(N + 1);

	ll D = N-S;
	if (D > 0) {
		for (ll x = 1; x <= V; x++) {
			if (D % x) continue;
			check(x + 1);
			check(D / x + 1);
		}
	}

	if (ans == INF) ans = -1;
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
ll n,a[100010];
int main(){
//	freopen("input.txt","r",stdin);// <--Remove Before Submit
	cin >>n;
	for(ll x=0;x<n;x++){
		cin >> a[x];
	}
	sort(a,a+n);
	ll d=1,n1=0,n2=0;
	for(ll x=n-1;x>=1;x--){
		if(a[x] == a[x-1]){
			d++;
			n2 = n1;
			n1 = a[x];
			a[x] = 0;
			a[x-1]=0;
		}
		if(n1!=0&&n2!=0){
			cout << n1*n2 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
using namespace std;

int main(){

    int H,W;cin>>H>>W;
    vector<pii> purple;
    REP(i,H){
        string a;cin>>a;
        REP(j,W)if(a[j]=='#')purple.push_back({i,j});
    }

    string red[H],blue[H];
    REP(i,H){
        REP(j,W) {
            red[i]+='.';
            blue[i]+='.';
        }
    }
    REP(j,W)red[0][j]='#';
    REP(j,W)blue[H-1][j]='#';

    for(int j=0;j<W;j+=2){
        REP(i,H-1)red[i][j]='#';
    }
    for (int j=1;j<W;j+=2){
        REP(i,H-1)blue[i+1][j]='#';
    }

    REP(i,purple.size()){
        red[purple[i].first][purple[i].second]=blue[purple[i].first][purple[i].second]= '#';
    }

    REP(i,H)cout<<red[i]<<endl;
    cout<<endl;
    REP(i,H)cout<<blue[i]<<endl;


    return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<sstream>

#define reps(i,f,n) for(int i = int(f); i <= int(n); ++i)
#define rep(i,n) reps(i,0,n-1)
#define rep2(i,j,n,m) rep(i,n)rep(j,m)
#define pii pair<int,int>
#define X first 
#define Y second

using namespace std;

const int INF = 1e9;


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

int main(void){
  int t;
  int n,d;
  while(1){
    vector<pii> p;
    int minx=INF, miny=INF;
    int maxx=0, maxy=0;
    cin >> t;
    if(t == 0) break;

    p.push_back(pii(250,250));

    rep(i,t-1){
      cin >> n >> d;
      p.push_back(pii(p[n].X+dx[d], p[n].Y+dy[d]));
    }
    
    rep(i, t){
      minx = min(minx, p[i].X);
      maxx = max(maxx, p[i].X);
      miny = min(miny, p[i].Y);
      maxy = max(maxy, p[i].Y);
    }

    cout << maxx-minx+1 << " " << maxy-miny+1 << endl;
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)


int main() {
    string S;
    cin >> S;
    int y = 0, m = 0, d = 0;
    y += (S[0] - '0') * 1000;
    y += (S[1] - '0') * 100;
    y += (S[2] - '0') * 10;
    y += (S[3] - '0') * 1;
    m += (S[5] - '0') * 10;
    m += (S[6] - '0') * 1;
    d += (S[8] - '0') * 10;
    d += (S[9] - '0') * 1;

    if (m <= 4) {
        cout << "Heisei" << endl;
        return 0;
    }
    cout << "TBD" << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

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

    vector<int> l(3);
    int ans = 0;
    for(int i=0; i<1000; i++){
        l[0] = i%10;
        l[1] = (i/10)%10;
        l[2] = (i/100);
        int k=0;
        for(int j=0; j<S.size(); j++){
            if(S[j]-'0' == l[k]) k++;
            if(k>=3){
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <set>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;


int main()
{
    int64 n;
    cin >> n;
    int64 sqr = (int64)::sqrt(n);

    for (int64 i = sqr; i > 0; --i)
    {
        int64 j = n / i;
        if (i * j == n)
        {
            cout << (i + j - 2) << endl;
            return 0;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

int main(){/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n, k;
    cin>>n>>k;
    cout<<(ll)(log(n) / log(k))+ 1<<"\n"; 

}

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

int main(){
    int A,B;
    char op;
    cin>>A>>op>>B;
    if(op=='+')      cout<<A+B<<endl;
    else if(op=='-') cout<<A-B<<endl;
    else            return 0;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

X = int(input())

go = X//500

ans = go*1000

nokori = (X - go*500)//5

ans += nokori*5

print(ans)


Measured memory_bytes: 3188
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
int main(){
  int x=0,N;
  char S[101];
  scanf("%d",&N);
  scanf("%s",S);
  int l=strlen(S);
  priority_queue<int> que;
  que.push(x);
  for(int i=0;i<l;i++){
    if(S[i]=='I') que.push(++x);
    else que.push(--x);
  }
  printf("%d\n",que.top());
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}
	ans := 1
	min := p[0]

	for i := 1; i < n; i++ {
		tmp := p[i]
		if tmp <= min {
			ans++
		}
		if tmp < min {
			min = tmp
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 5888
import java.util.*;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong(), a = sc.nextLong(), b = sc.nextLong();
		sc.close();
		long ans = n / (a + b);
		ans = ans * a + ((n % (a + b)) <= a ? (n % (a + b)) : a);
		System.out.println(ans);
	}
}


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

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  for(int i=0; i<n; i++){
    ll tmp;
    cin >> tmp;
    b[i] = i+1 - tmp;
    a[i] = tmp + i+1;
  }
  ll ans = 0;
  sort(b.begin(),b.end());
  /*
  for(int i=0; i<n; i++){
    cout << b[i].first << " " << b[i].second << endl;
  }*/
  for(int i=0; i<n; i++){
    auto l = lower_bound(b.begin(),b.end(),a[i]);
    auto r = upper_bound(b.begin(),b.end(),a[i]);
    ans += r-l;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6404
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  int n, m;
  cin >> n >> m;
  int check_x[m], check_y[m], stud_x[n], stud_y[n];
  for(int i = 0; i < n; i++)
    cin >> stud_x[i] >> stud_y[i];
  for(int i = 0; i < m; i++)
    cin >> check_x[i] >> check_y[i];
  for(int i = 0; i < n; i++)
  {
    int min_index = 1;
    int min = abs( check_x[0] - stud_x[i] ) + abs( check_y[0] - stud_y[i] );
    for(int j = 1; j < m; j++)
      if( abs( check_x[j] - stud_x[i] ) + abs( check_y[j] - stud_y[i] ) < min )
      {
        min = abs( check_x[j] - stud_x[i] ) + abs( check_y[j] - stud_y[i] );
        min_index = j + 1;
      }
    cout << min_index << "\n";
  }
}

Measured memory_bytes: 3172
#include <iostream>
#include <string>

using namespace std;

class A {
	int n;
	string ns;
public:
	void solve()
	{
		cin >> n;
		ns = to_string(n);

		if (ns[1] == ns[2])
		{
			if ((ns[0] == ns[1]) || (ns[3] == ns[1])) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let n: usize = iter.read();
	
	println!("{}", 3 * n * n);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn=5100;
const ll mod=1000000000+7;
char sz[maxn];
ll f[maxn];
int n,len;
ll dp[maxn][maxn];

ll fast_pow(ll a,ll b){
    ll res=1;
    while(b){
        if(b%2==1) res=(res*a)%mod;
        a=(a*a)%mod;
        b=b/2;
    }
    return res;
}

int main(){
    scanf("%d",&n);
    scanf("%s",sz+1);
    len=strlen(sz+1);
    f[0]=1;
    for(int i=1;i<=len;i++) f[i]=(f[i-1]*2)%mod;
    dp[0][0]=1;
    dp[1][0]=1;dp[1][1]=2;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            dp[i+1][j+1]=(dp[i+1][j+1]+2*dp[i][j])%mod;
            dp[i+1][max(j-1,0)]=(dp[i+1][max(j-1,0)]+dp[i][j])%mod;
        }
    }
    printf("%lld\n",(dp[n][len]*fast_pow(f[len],mod-2))%mod);
    return 0;
}


Measured memory_bytes: 199296
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
a=primes(110000)
n=int(input())
for i in range(10000):
    if n+i in a:
        print(n+i)
        break

Measured memory_bytes: 4300
#include <bits/stdc++.h>
 
#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, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
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;
  
	//int a, b;
	//cin >> a >> b;
	//bitset<32> b1(a), b2(b);
	//cout << (b1&b2) << '\n' << (b1|b2) << '\n' << (b1^b2) << '\n';
	long long n;
	cin >> n;
	bitset<32> b(n);
	cout << b << '\n' << (~b) << '\n' << (b<<1) << '\n' << (b>>1) << '\n';
    return 0;
}



Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i ++)
#define max(a,b) ((a) > (b) ? (a) : (b))
typedef long long LL;
using namespace std;
const int N = 5e3 + 10, M = 210;
int n, m, b[N][M]; 
LL a[N];
inline void read(int &x) {
	char c = getchar(); x = 0;
	while (c < '0' || c > '9') c = getchar();
	while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
}

LL ans[N];

int s[14][N][M], bin[(1 << 15) + 10];
void init() {
	rep(i,1,n) rep(j,1,m) s[0][i][j] = b[i][j];
	rep(k,1,12) {
		rep(i,1,n) if (i + (1 << k) <= n) rep(j,1,m) 
			s[k][i][j] = max(s[k - 1][i][j], s[k - 1][i + (1 << (k - 1))][j]);
	}
	rep(i,0,12) rep(j,(1<<i),(1<<(i+1))) bin[j] = i;
}

inline void prepare(int mx[], int l, int r) {
	if (l > r) return;
	int len = r - l + 1; int k = bin[len];
	rep(i,1,m) mx[i] = max(s[k][l][i], s[k][r - (1 << k) + 1][i]);
}

int calc(int x, int l, int r) {
	l = max(l, x);
	static int mx[M]; memset(mx, 0, sizeof(mx));
	ans[x] = 0; int mxa = 0;
	prepare(mx, x, l - 1);
	rep(i,l,r) {
		LL s = 0;
		rep(j,1,m) mx[j] = max(mx[j], b[i][j]), s += mx[j];
		s -= a[i] - a[x];
		if (s > ans[x]) ans[x] = s, mxa = i;
	}
	return mxa;
}

void solve(int l, int r, int a, int b) {
	int mid = (l + r) >> 1;
	int t = calc(mid, a, b);
	if (l < mid) solve(l, mid - 1, a, t);
	if (mid < r) solve(mid + 1, r, t, b);
}

int main() {
	read(n), read(m);
	rep(i,2,n) scanf("%lld",a + i), a[i] += a[i - 1];
	rep(i,1,n) rep(j,1,m) read(b[i][j]);
	init();
	solve(1, n, 1, n);
	LL mx = 0; rep(i,1,n) mx = max(mx, ans[i]);
	printf("%lld\n",mx);
	return 0;
}

Measured memory_bytes: 55808
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.container;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(long[] a) {
    a.sort();

    long[] pp, nn;
    foreach (x; a) {
        if (x >= 0) pp ~= x;
        else nn ~= x;
    }

    if (pp.empty) {
        pp = [nn[$ - 1]];
        nn = nn[0..$-1];
    }
    else if (nn.empty) {
        nn = [pp[0]];
        pp = pp[1..$];
    }

    auto ps = new Stack!(long)(pp);
    auto ns = new Stack!(long)(nn);
    long[][] steps;
    while (ps.size > 1 || ns.size > 1) {
        if (ps.size > ns.size) {
            long x = ns.pop();
            long y = ps.pop();
            ns.push(x - y);
            steps ~= [x, y];
        }
        else {
            long x = ps.pop();
            long y = ns.pop();
            ps.push(x - y);
            steps ~= [x, y];
        }
    }

    long x = ps.top;
    long y = ns.top;
    steps ~= [x, y];
    long ans = x - y;
    writeln(ans);
    foreach (s; steps) {
        writeln(s[0], " ", s[1]);
    }
}

void main() {
    readint;
    auto a = reads!long;
    calc(a);
}

class Stack(T) {
    private DList!(T) _dlist;
    private ulong _size;

    this(T[] ary) {
        _dlist = DList!(T)(ary);
        _size = ary.length;
    }

    this() {
        _dlist = DList!(T)();
        _size = 0;
    }

    void push(T x) {
        _dlist.insertBack(x);
        _size++;
    }

    T pop() {
        T x = _dlist.back;
        _dlist.removeBack();
        _size--;
        return x;
    }

    @property T top() {
        return _dlist.back;
    }

    @property ulong size() {
        return _size;
    }

    @property bool empty() {
        return _dlist.empty;
    }
}


Measured memory_bytes: 17988
#include<stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+b==c+d)
	printf("Balanced");
	if(a+b>c+d)
	printf("Left");
	if(a+b<c+d)
	printf("Right");
	return 0;
 } 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int flag[105][20];
int ip[105][11];
int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
	   for(int j = 1;j <= 10;j++)
	       scanf("%d",&flag[i][j]);
	for(int i = 1;i <= n;i++){
		for(int j = 0;j <= 10;j++){
			scanf("%d",&ip[i][j]);
		}
	}
	int f [12];
    int maxx = -2e9;
    for(int i = 1;i < (1<<10);i++)
    {   int sum = 0;
        memset(f,0,sizeof(f));
    	for(int j = 0;j < 10;j++)
    	{
            if(i&(1<<j))
			f[j+1] = 1;    		
		}
		for(int j = 1;j <= n;j++)
		{   int cnt = 0; 
			for(int s = 1;s <= 10;s++)
			if(flag[j][s]&&f[s])
			cnt++;
			sum += ip[j][cnt];
		}
		maxx = max(maxx,sum);
	}
	printf("%d\n",maxx);
	return 0;
}

Measured memory_bytes: 256
class Board:
    def __init__(self,m):
        self.m = m
        self.x = 0
        self.y = 0
        self.d = 'e'

    def dir(self):
        return self.d

    def is_origin(self):
        return (self.x==0) and (self.y==0)
        
    def north_is_wall(self):
        if self.y == 0:
            return False
        else:
            if self.m[2*self.y-1][self.x] == '1':
                return True
            else:
                return False

    def east_is_wall(self):
        if self.x == 4:
            return False
        elif m[2*self.y][self.x] == '1':
            return True
        else:
            return False
    def west_is_wall(self):
        if self.x == 0:
            return False
        elif m[2*self.y][self.x-1] == '1':
            return True
        else:
            return False
    def south_is_wall(self):
#        print("x={},y={}".format(self.x,self.y))
        if self.y == 4:
            return False
        elif self.m[2*self.y+1][self.x] == '1':
            return True
        else:
            return False

    def go_north(self):
        if self.y == 0:
            raise "invalid"
        else:
            self.y -= 1
            self.d = 'n'
        print("U",end="")

    def go_south(self):
        if self.y == 5:
            raise "invalid"
        else:
            self.y += 1
            self.d = 's'
        print("D",end="")

    def go_east(self):
        if self.x == 4:
            raise "go_east"
        else:
            self.x += 1
            self.d = 'e'
        print("R",end="")

    def go_west(self):
        if self.x == 0:
            raise "go_west"
        else:
            self.x -= 1
            self.d = 'w'
        print("L",end="")


def run(m):
    b = Board(m)
    init = True
    while True:
        d = b.dir()
        if d == 'e':
            if   b.north_is_wall():
                b.go_north()
            elif b.east_is_wall():
                b.go_east()
            elif b.south_is_wall():
                b.go_south()
            else:
                b.go_west()
        elif d == 's':
            if   b.east_is_wall():
                b.go_east()
            elif b.south_is_wall():
                b.go_south()
            elif b.west_is_wall():
                b.go_west()
            else:
                b.go_north()
        elif d == 'w':
            if b.south_is_wall():
                b.go_south()
            elif b.west_is_wall():
                b.go_west()
            elif b.north_is_wall():
                b.go_north()
            else:
                b.go_east()
        elif d == 'n':
            if  b.west_is_wall():
                b.go_west()
            elif b.north_is_wall():
                b.go_north()
            elif b.east_is_wall():
                b.go_east()
            else:
                b.go_south()

        if (not init) and b.is_origin():
            print()
            break
        init = False

m = []
for _ in range(9):
    m.append(list(input()))

run(m)




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

using namespace std;

const int roll[10][10] = {
		{3, 2, 6, 1, 5, 4}, //W
		{4, 2, 1, 6, 5, 3}, //E
		{2, 6, 3, 4, 1, 5}, //N
		{5, 1, 3, 4, 6, 2}  //S
};
int main()
{
	int dice[10], NewDice[10], key[200];
	string cmd;
	key['W'] = 0, key['E'] = 1, key['N'] = 2, key['S'] = 3;
	
	for(int i = 0; i < 6; i++)
	{
		cin >> dice[i];
	}
	cin >> cmd;
	
	for(int i = 0; i < cmd.size(); i++)
	{
		for(int j = 0; j < 6; j++)
		{
			NewDice[j] = dice[roll[key[cmd[i]]][j] - 1];
		}
		for(int j = 0; j < 6; j++)
		{
			dice[j] = NewDice[j];
		}
	}
	cout << dice[0] << endl;
	return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define VMAX 100000

void solve(long long N, long long W, vector<long long> w, vector<long long> p){
  vector<vector<long long>> dp(N, vector<long long>(VMAX+1, LLONG_MAX));
  dp[0][0] = 0;
  dp[0][p[0]] = w[0];

  for(long long i = 1; i < N; i++) {
    for(long long j = 0; j <= VMAX; j++) {
      long long source = j - p[i];
      if(source < 0 || dp[i-1][source] == LLONG_MAX) {
        dp[i][j] = dp[i-1][j];
        continue;
      }

      dp[i][j] = min(dp[i-1][j], dp[i-1][source] + w[i]);
    }
  }


  #ifdef DEBUG
  for(long long i = 0; i < N; i++) {
    for(long long j = 0; j <= VMAX; j++) {
      if(dp[i][j] != LLONG_MAX) {
        cout << "[" << i << "][" << j << "]=" << dp[i][j] << " ";
      }
    }

    cout << endl;
  }
  #endif

  for(long long j = VMAX; j >= 0; j--) {
    if(dp[N-1][j] <= W) {
      cout << j << endl;
      break;
    }
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long W;
  scanf("%lld",&W);
  vector<long long> ws;
  vector<long long> ps;
  long long w, p;
  for(int i = 0 ; i < N ; i++){
    cin >> w >> p;
    ws.push_back(w);
    ps.push_back(p);
  }
    solve(N, W, std::move(ws), std::move(ps));
    return 0;
}


Measured memory_bytes: 79488
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    string S;
    string L = "";
    int Q;
    int Qu;
    int F;
    char c;
    bool w = true;
    
    cin >> S;
    cin >> Q;
    
    for(int i=0;i<Q;i++){
        // 入力
        cin >> Qu;
        if(Qu == 2){
            cin >> F >> c;
            
            if(w){
                if(F == 1){
                    L += c;
                }
                else{
                    S += c;
                }
            }
            else{
                if(F == 1){
                    S += c;
                }
                else{
                    L += c;
                }
            }
        }
        else{
            w = !w;
        }
        
        // cout << Qu << F << c << w << endl;
        // cout << S << endl;
    }
    reverse(L.begin(),L.end());
    S = L + S;
    
    if(!w){
        reverse(S.begin(),S.end());
    }
    cout << S << endl;
}


Measured memory_bytes: 1116
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		HashMap<String,String> map = new HashMap<String,String>();
		map.put("A", "1");
		map.put("C", "1");
		map.put("G", "1");
		map.put("T", "1");
		Scanner sc = new Scanner(System.in);
		String[] list = sc.nextLine().split("");
		
		int cnt=0;
		int max_cnt=0;
		for(int i=0;i<list.length;i++) {
			cnt=0;
			if(map.containsKey(list[i])) {
				cnt++;
				for(int j=i+1;j<list.length;j++) {
					if(map.containsKey(list[j])) {
						cnt++;
					}
					else {
						break;
					}
				}
			}
			if(max_cnt<cnt) max_cnt=cnt;
		}
		System.out.println(max_cnt);
	}
}

Measured memory_bytes: 23764
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
int a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  return true;
}

void solve() {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[a[i]] == i) {
      cnt++;
    }
  }
  printf("%d\n", cnt / 2);
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int h,m,s;
  while(cin>>h>>m>>s,h+1){
    int left=60*120-h*3600-m*60-s;
    if(left/3600<10)cout<<0;
    cout<<left/3600<<':';
    if(left/60%60<10)cout<<0;
    cout<<left/60%60<<':';
    if(left%60<10)cout<<0;
    cout<<left%60<<endl;
    left*=3;
 if(left/3600<10)cout<<0;
    cout<<left/3600<<':';
    if(left/60%60<10)cout<<0;
    cout<<left/60%60<<':';
    if(left%60<10)cout<<0;
    cout<<left%60<<endl;

  }
}

Measured memory_bytes: 1160
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back


int MOD=1000000007;
int N;
int A[200005];
int S[200005];
signed main(){
    scanf("%lld",&N);
    int L=0,R=0,sum=0;
    rep(i,N){
        scanf("%lld",&A[i]);
        if(i==0){
            S[i]=A[i];
        }else{
            S[i]=S[i-1]+A[i];
        }
        sum+=A[i];
    }
    int ans=0;
    rep(i,N){
        scanf("%lld",&A[i]);
        if(i==0){
            S[i]=A[i];
            if(S[i]*2>=sum){//一個めがめちゃくちゃでかい
                printf("%lld\n",S[i]*2-sum);
                return 0;
            }
        }else{
            S[i]=S[i-1]+A[i];
            if(S[i]*2>=sum&&S[i-1]*2<=sum){
                L=S[i-1];
                R=S[i];
            }
        }
    }
    ans=min(sum-L*2,R*2-sum);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
int n, s;

int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int sum(int* his, int bs, int bn){
	int i,c;
	if(bn == 0){
		if(bs == s) return 1;
		else return 0;
	}
	int cou = 0;
	for(i = 0; 10 > i; i++){
		int f = 0;
		for(c = 0; n-bn > c; c++){
			if(his[c] == i) f = 1;
		}
		if(!f){
			his[n-bn] = i;
			cou += sum(his, i+bs, bn-1);
		}
	}
	return cou;
}

int main(void) {
	int i,j, cou, his[9] = {-1};
	while(scanf("%d %d", &n, &s)){
		if(n == 0 && s == 0) break;
		printf("%d\n", sum(his, 0, n)/factorial(n));
	}
	return 0;
}

Measured memory_bytes: 600
fun main(args: Array<String>) {
  val A = Array(3) { Array(3) { 0 } }
  for (i in 0 until 3) {
    val a = readInts()
    for (j in 0 until 3) A[i][j] = a[j]
  }
  val N = readInt()
  repeat(N) {
    val B = readInt()
    for (i in 0 until 3) {
      for (j in 0 until 3) {
        if (A[i][j] == B) A[i][j] = -1
      }
    }
  }
  for (i in 0 until 3) {
    var cnt0 = 0
    var cnt1 = 0
    for (j in 0 until 3) {
      if (A[i][j] == -1) cnt0++
      if (A[j][i] == -1) cnt1++
    }
    if (cnt0 == 3 || cnt1 == 3) {
      println("Yes")
      return
    }
  }
  if (A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1) {
    println("Yes")
    return
  }
  if (A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1) {
    println("Yes")
    return
  }
  println("No")
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 37876
#include <iostream>

using namespace std;

int main () {
    int N;
    cin >> N;
    int ac=0;
    int re=0;
    int tle=0;
    int wa=0;
    while(N--){
        string t;
        cin >> t;
        if(t=="AC") ac++;
        else if(t=="RE") re++;
        else if(t=="TLE") tle++;
        else if(t=="WA") wa++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;    
}




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

int main() {

  string n;
  cin >> n;
  
  if(n[0] == n[1] && n[1] == n[2]) {
    cout << "Yes" << endl;
  } else if (n[1] == n[2] && n[2] == n[3]){
    cout << "Yes" << endl;
  }
    else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long;

int main() {
  
	int N;
	cin >> N;
	vector<int> vec(N + 1);

	for (int i = 1; i < N+1; i++) {

		cin >> vec.at(i);

 }
	int count=0;
	int x = 1;/*ボタン*/
	int y;/*次のボタン*/

	for (int i = 1; i < N+1; i++) {

		y = vec.at(x);
		x = y;
		count++;

		if (x == 2) {
			cout << count << endl;
			return 0;
		}

		else if (i == N) {

			cout << -1 << endl;
			return 0;
		}

	}


	return 0;

}


Measured memory_bytes: 3752
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n){
    long long a,b,c,k[20001]={};
    vector<pair<long long,pair<int,int> > > s;
    k[1]=1;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      s.push_back(make_pair(a,make_pair(b,c)));
    }
    sort(s.begin(),s.end());
    for(int i=0;i<m;i++){
      if(k[s[i].second.first]==1)k[s[i].second.second]=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=k[i];
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    vector<vector<ll>> b(22, vector<ll>(n));
    rep(i,n) {
        int idx = 0;
        ll m = a[i];
        while (m>0) {
            b[idx++][i] = m%2;
            m/=2;
        }
    }

    vector<vector<ll>> c(b);
    rep(i,22) {
        for (int j = 1; j < n; ++j) {
            b[i][j] += b[i][j-1];
        }
    }

    ll ans = 0;
    rep(j,n) {
        ll cnt = INF;
        rep(i,22) {
            int see = 2;
            if (c[i][j]) see--; 
            auto itr = lower_bound(b[i].begin()+j, b[i].end(), b[i][j]+see);
            ll tmp = (itr-b[i].begin())-j;
            chmin(cnt, tmp);
        }
        ans += cnt;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 70628
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int n;
int ptr, res;

int main(){
    ptr = 0;
    cin >> n;
    vector<int> a(n,0);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    while ( ptr < n ){
        int cc = a[ ptr ] , f =0;
        while ( ptr < n && a[ ptr ]== cc ) f ++ , ptr ++;
        res += f %2;
    }
    cout << res << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    int n,k;
    cin>>n>>k;

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

    int dp[n],mn;

    dp[0]=0;

    for(int i=1; i<n; i++)
    {
        for(int j=i-1; j>=0 && j>=i-k; j--)
        {
            if(j==i-1)
                mn=abs(a[i]-a[j])+dp[j];
            else
                mn=min(mn,abs(a[i]-a[j])+dp[j]);
        }

        dp[i]=mn;
    }

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

    cout<<dp[n-1]<<endl;




    return 0;
}


Measured memory_bytes: 4420
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;

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

  for(int i=0; i<s.length(); i++){
    if(i % n == 0) cout << s[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>
#include<string>
#include<stack>

using namespace std;


vector<vector<pair<int, int> > > bottomUp(const string &a, const string &b)
{
	int n = a.size(), m = b.size(), i, j;

	vector<vector<int> > dp(n);
	vector<vector<pair<int, int> > > pred(n);


	for(i = 0;i < n;i++)
	{
		dp[i].resize(m);
		pred[i].resize(m);
		for(j = 0;j < m;j++)
		{
			if(i == 0 && j == 0)
			{
				dp[i][j] = (a[i] == b[j] ? 1 : 0);
				pred[i][j].first = -1;
				pred[i][j].second = -1;
			}
			else if(i == 0)
			{
				if(a[i] == b[j])
				{
					dp[i][j] = 1;
					pred[i][j].first = -1;
					pred[i][j].second = j-1;
				}
				else
				{
					dp[i][j] = dp[i][j-1];
					pred[i][j].first = 0;
					pred[i][j].second = j-1;
				}
			}
			else if(j == 0)
			{
				if(a[i] == b[j])
				{
					dp[i][j] = 1;
					pred[i][j].first = i-1;
					pred[i][j].second = -1;
				}
				else
				{
					dp[i][j] = dp[i-1][j];
					pred[i][j].first = i-1;
					pred[i][j].second = 0;
				}
			}
			else
			{
				if(a[i] == b[j])
				{
					dp[i][j] = dp[i-1][j-1] + 1;
					pred[i][j].first = i-1;
					pred[i][j].second = j-1;
				}
				else
				{
					if(dp[i][j-1] > dp[i-1][j])
					{
						dp[i][j] = dp[i][j-1];
						pred[i][j].first = i;
						pred[i][j].second = j-1;
					}
					else
					{
						dp[i][j] = dp[i-1][j];
						pred[i][j].first = i-1;
						pred[i][j].second = j;
					}

				}
			}
		}
	}
	return pred;
}

int main()
{
	string a, b;
	cin>>a>>b;

	vector<vector<pair<int, int> > > pred = bottomUp(a, b);
	pair<int, int> x;

	x.first = a.size() - 1;
	x.second = b.size() - 1;


	stack<char> st;
	while(x.first != -1 && x.second != -1)
	{
		if(a[x.first] == b[x.second])
			st.push(a[x.first]);

		x = pred[x.first][x.second];

	}

	while(st.empty() == false)
	{
		cout<<st.top();
		st.pop();
	}
	return 0;
}


Measured memory_bytes: 105984
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        String S = sc.next();
        if(S.equals("AAA") || S.equals("BBB")){
        	System.out.println("No");
        }else{
        	System.out.println("Yes");
        }
    }
 
 
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int MOD = 1000000007;

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

int num_divisor(int num){
    int res = 0;
    for(int i = 1; i * i <= num; i++){
        if (num % i == 0){
            res++;
            if(i * i != num) res++;
        }
    }
    return res;
}

ll solve(ll N, ll M){
    ll ans = 1;
    for(int i = 1; i * i <= M; i++){
        if (M % i != 0) continue;
        if (M / i >= N) ans = max(ans, i);
        if (i >= N)     ans = max(ans, M / i);
    }
    return ans;
}

int main(void){
    int A, B; cin >> A >> B;
    if (1 <= A && A <= 9 && 1 <= B && B <= 9) cout << A * B << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 256
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}
const int MX=3e5+100;
int n,arr[MX],cm[MX];
int Left,Right,add;
bool can(int x){
 for(int i=1,j=x;j<=n;++i,++j){
  if(cm[j]-cm[i-1]+add>=x){
  Left=i,Right=j;
   return true;}
 }
 return false;
}
bool checkP(int n){
 vector<int>vr;
 while(n!=0){
 int a=n%10;
  n/=10;
 vr.push_back(a);}
 if(vr[0]==vr[4]&&vr[1]==vr[3])
 return true;
 return false;
}
int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);

int n=RD();
char c;
set<char>st;
fr{
cin>>c;
st.insert(c);
}
if(st.size()==3)
cout<<"Three";
else
cout<<"Four";
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ

int main(){
    int n;
    cin>>n;
    vector<int> a;
    int ans=0;
    int i=1;
    while(ans<n){
        ans += i;
        a.push_back(i);
        i++;
    }
    //a[i]=i+1;
    if(ans == n){
        //全部出力
        rep(i,a.size()){
            cout<<a[i]<<endl;
        }
    }
    else{
        //ans-nを削除
        a.erase(a.begin()+ans-n-1);
        rep(i,a.size()){
            cout<<a[i]<<endl;
        }
    }
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <locale.h>
int main()
{
    char s[1000];
    scanf("%s",s);
    int lo = strlen(s);
    int ans=0;
    for(int i=0;i<lo/2;i++){
        if(s[i]!=s[lo-i-1]) ans++;
    }
    printf("%d",ans);
}


Measured memory_bytes: 128