akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <algorithm>
#include <fstream>
#define mp make_pair
#define BIT(x) __builtin_popcount(x)
#define lg(x) (31 - __builtin_clz(x))
#define Debug(...) fprintf(stdout, __VA_ARGS__)

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;

const int MOD = 1e9 + 7;
const int MAXM = 17;
const int MAXN = 1 << 16 | 1;
const int sig[] = {1, MOD - 1};

inline void proc_status() {
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline T read() {
	T res = 0, flag = 1; char in = getchar();
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

template<typename T> inline void chkmax(T &a, T b) { if(a < b) a = b; }
template<typename T> inline void chkmin(T &a, T b) { if(a > b) a = b; }

int fac[MAXN], ifac[MAXN], inv[MAXN];

inline void Add(int &x, int y) { x += y; (x >= MOD) ? x -= MOD : 0; }

inline int C(int n, int m) {
	if(n < 0 || n < m) return 0;
	return (LL) fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;
}

int n, m, a[MAXN];
int All;
int mul[MAXN], cnt[MAXN];

inline int lowbit(int x) { return x & (-x); }

inline void init() {
	mul[0] = fac[0] = ifac[0] = inv[1] = 1;
	for(int i = 1; i < MAXN; ++i) fac[i] = (LL) fac[i - 1] * i % MOD;
	for(int i = 2; i < MAXN; ++i) inv[i] = (LL) (MOD / i) * (MOD - inv[MOD % i]) % MOD;
	for(int i = 1; i < MAXN; ++i) ifac[i] = (LL) inv[i] * ifac[i - 1] % MOD;
	for(int i = 1; i < MAXM; ++i) mul[i] = mul[i - 1] << 1;
	
	n = read<int>(); m = read<int>(); All = (1 << n) - 1;
	for(int i = 1; i <= m; ++i) a[i] = read<int>();
	sort(a + 1, a + m + 1, greater<int>());

//	cout << (LL) fac[100] * ifac[100] % MOD;

	for(int i = 1; i <= All; ++i) { int u = lowbit(i); cnt[i] = cnt[i ^ u] + mul[lg(u)]; }
//	cout << cnt[4] << endl;
}

int dp[MAXM][MAXN];

inline void solve() {

	dp[0][0] = 1;

	for(int i = 0; i < m; ++i) {
		for(int S = 0; S <= All; ++S) if(dp[i][S]) {
			Add(dp[i + 1][S], dp[i][S]);
			for(int j = 0; j < n; ++j) {
				if(!((S >> j) & 1)) {
//					if(All - a[i + 1] - cnt[S] + 1 < mul[j] - 1) break;
					Add(dp[i + 1][S | (1 << j)], (LL) dp[i][S] * C(All - a[i + 1] - cnt[S] + 1, mul[j] - 1) % MOD * fac[mul[j]] % MOD);
//					if(i == 0 && S == 0 && j == 1) {
//						cout << "FF " << A(All - a[i + 1] - cnt[S] + 1, mul[j]) % MOD << endl;
//					}
				}
			}
		}
	}

	for(int S = 0; S < All; ++S) {
//		cout << dp[m][S] << endl;
		dp[m][S] = (LL) dp[m][S] * fac[cnt[All ^ S]] % MOD;
	}
//	cout << dp[1][2] << endl;

	int ans = 0;

	for(int S = 0; S <= All; ++S) {
		Add(ans, (LL) sig[BIT(S) & 1] * dp[m][S] % MOD);
	}

	ans = (LL) ans * mul[n] % MOD;
	printf("%d\n", ans);
}

int main() {

	init();
	solve();

	return 0;
}



Measured memory_bytes: 4864
#include<stdio.h>
int main(void)
{
	int a[4],b,i,j,Hit,Blow,x=0;

	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF)
	{
		Hit=0;
	    Blow=0;

		for(i=0;i<4;i++)
		{
			scanf("%d",&b);
			if(b==a[i])
				Hit++;
			else
				for(j=0;j<4;j++)
				{
					if(b==a[j])
					{
						Blow++;
						break;
					}
				}
		}
		printf("%d %d\n",Hit,Blow);
	}
  return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <iostream>

int main()
{
  long long N;
  std::cin >> N;
  long long M = static_cast<long long>(sqrt(static_cast<double>(N)));
  long long T = 1 + N;
  for (long long i = 2; i <= M; ++i)
    if (0 == N%i)
      if (i + N/i < T)
        T = i + N/i;
  std::cout << T - 2 << std::endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int ans[200000 + 5];
int use[200000 + 5];
int main()
{
	int n;
	int flg = 0, a;
	scanf("%d%d", &n, &a);
	if (a == 1 || a == 2 * n - 1)
	{
		puts("No");
		return 0;
	}
	if (a < n)
	{
		a = 2 * n - a;
		flg = 1;
	}
	for (int i = 1; i < n; i++)
	{
		ans[i] = i;
		use[i] = true;
	}
	ans[n] = a;
	ans[n + 1] = a + 1;
	use[a] = use[a + 1] = true;
	int curr = n;
	for (int i = n + 2; i <= 2 * n - 1; i ++)
	{
		while (use[curr]) curr++;
		ans[i] = curr;
		use[curr] = 1;
	}
	puts("Yes");
	for (int i = 1; i <= n * 2 - 1; i++)
		printf("%d\n", flg ? n * 2 - ans[i] : ans[i]);
	return 0;
}


Measured memory_bytes: 3072
N,C,K = map(int,input().split())
T = []
for i in range(N):
    T.append(int(input()))
T.sort()
i = 0
ans = 0
while i < N:
    Ti = T[i]
    cnt = 0
    while i < N and T[i] <= Ti + K and cnt < C:
        i += 1
        cnt += 1
    ans += 1
print(ans)

Measured memory_bytes: 7384
#include <iostream>
using namespace std;
int main() {
  int w, h, x, y;
  cin >> w;
  cin >> h;
  cin >> x;
  cin >> y;
  cout << double(w) * double(h) / 2.0 << " " << (2 * x == w && 2 * y == h) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    int x[n];
    int p;
    int ans=0;
    float ave=0;
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
        ave=ave+(float)x[i];
    }
    if(ave/n-(int)ave/n>0.5){
        p=(int)ave/n+1;
    }else p=(int)ave/n;
    for(int i=0;i<n;i++){
        ans=ans+(x[i]-p)*(x[i]-p);
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
/*
  RMQ and RUQ
  区間の最小値を得る(RMQ)
  区間の値を変更する(RUQ)
 */

template<typename dtype>
class RMQ{
public : 
  dtype initValue; //範囲外の時に返す値
  
  struct data{
    bool type; //0 - empty   , 1 - update
    dtype value;
  };
  
  int n,n_;
  vector<dtype> dat;
  vector<data> td;
  int toMax;          //0 -> RangeMin 1->RangeMax;
  
  RMQ(){n=-1;}
  RMQ(int n_, dtype initValue, int toMax = 0):n_(n_),initValue(initValue),toMax(toMax){
    n=1;
    while(n<n_)n*=2;
    td.resize(2*n-1,(data){0,initValue});
    dat.resize(2*n-1,initValue);
  }

  inline dtype merge(dtype a, dtype b){return toMax? max(a, b):min(a, b);}
  
  
  dtype dfs(int a,int b,dtype x,bool flag,int k,int l,int r){
    if(r <= a || b <= l) return flag? dat[k]:initValue;
    if(a <= l && r <= b){
      if(flag == true){
        td[k]=(data){1,x};
        dat[k]=x;
      }
      return dat[k];
    }
    
    if(td[k].type){
      td[k].type = 0;
      dat[k*2+1] = dat[k*2+2] = td[k].value;
      td[k*2+1] = td[k*2+2] = (data){1,td[k].value};
    }

    dtype vl=dfs(a, b, x, flag, k*2+1, l, (l+r)/2);
    dtype vr=dfs(a, b, x, flag, k*2+2, (l+r)/2, r);
    return flag? (dat[k] = merge(vl, vr)):min(vl,vr);
  }
  
  //[l,r)の値をxに変更　update(l,r,x)
  void update(int l,int r,dtype x){
    assert(l <= r), assert(l <= n && r <= n), assert(l >= 0 && r >= 0);
    dfs(l, r, x, true, 0, 0, n);
  }
  
  //[l,r)の最小値を得る　find(l,r);
  dtype get(int l,int r){
    assert(l <= r), assert(l <= n && r <= n), assert(l >= 0 && r >= 0);
    return dfs(l, r, initValue , false, 0 , 0 ,n);
  }
};


int main(){
  int q,n;
  cin>>n>>q;
  typedef long long ll;
  RMQ <ll> T(n, INT_MAX);
  
  while(q--){
    int cmd,s,t,x;
    scanf("%d%d%d",&cmd,&s,&t);
    if(cmd==0)cin>>x,T.update(s,t+1,x);
    else cout <<T.get(s,t+1)<<endl;
  }
  return 0;
}



Measured memory_bytes: 8896
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> A(N);
    vector<int> sum(N+1, 0);
    for (int i = 0; i < N; i++) {
        cin >> S[i] >> A[i];
        sum[i+1]= sum[i] + A[i];
    }
    string T;
    cin >> T;
    int ans;
    for (int i = 0; i < N; i++) {
        if (S[i] == T) {
            ans = sum[N] - sum[i+1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    int H,W;
    cin>>H>>W;
    char A[H+1][W+1];
    for(int i=0; i<=H; i++){
        for(int j=0; j<=W; j++){
            if(i==H || j==W){
                A[i][j]=='.';
            }else{
                cin>>A[i][j];
            }
        }
    }
    
    A[H][W-1]='#';
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(A[i][j]=='#'){
                int ue=0;
                int hidari=0;
                if(i<=0 || A[i-1][j]=='#'){
                    ue=1;
                }
                if(j<=0 || A[i][j-1]=='#'){
                    hidari=1;
                }
                if(!(ue|hidari)){
                    cout<<"Impossible"<<endl;
                    return 0;
                }
                
                if(A[i+1][j]=='#' xor A[i][j+1]=='#'){
                    
                }else{
                    cout<<"Impossible"<<endl;
                    return 0;
                }
            }
        }
    }
    
    cout << "Possible"<<endl;
    return 0;
}


Measured memory_bytes: 256
n,k = gets.chomp.split.collect{ |item| item.to_i}

mmin = n-1
kmax = (n-1)*(n-2)/2
if k > kmax
  puts -1
else
  addline = kmax - k
  m = mmin + addline
  puts m
  center = 1
  mmin.times do |mi|
    puts "#{center} #{mi+2}"
  end
  u = 2
  v = 3
  addline.times do |addi|
    puts "#{u} #{v}"
    v += 1
    if v > n
      u += 1
      v = u+1
    end
  end
end

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll N;
	cin >>N;
	ll NN=N;
	ll I=1;
	ll L=26;
	while (N>L) {
		I++;
		N -=L;
		L *=26;
	}
	N--;
	vector<char> NA;
	Rep0(i, I) {
		NA.push_back((char)('a'+N%26));
		N /=26;
	}
	Rev(NA);
	Rep0(i, I)
		cout <<NA.at(i);
	cout <<endl;
	return 0;
}



Measured memory_bytes: 3652
#include <stdio.h>

int def(int x,int y){
  if(y==0){
    return x;
  }else{
    return def(y, x%y);
  }

}


int main(){

  int w,h,c,num,a;

  scanf("%d%d%d",&w,&h,&c);

  if(w<h){
    a = def(h,w);
  }else{
    a = def(w,h);
  }


  num = (w/a)*(h/a);


  printf("%d\n",num*c);

  return 0;

}

Measured memory_bytes: 596
#include <iostream>

int main() {
  uint32_t N = 0, count = 0;
  std::cin >> N;
  for (size_t i = 0; i < N; i++) {
    uint32_t A = 0;
    std::cin >> A;
    count += A % 2;
  }
  std::cout << (count % 2 == 0 ? "YES" : "NO") << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int X; cin >> X;
  if(X>=30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>ostream&operator<<(ostream &o,const vector<T>&t){o<<'[';FOR(i,t){if(i!=t.begin())o<<',';o<<*i;}return o<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)output(a[i],i!=n-1?',':10);}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}

int C[1000];
vector<pii> g[1000];
int dp[1000];

void dfs(int v, int p) {
  FOR(it, g[v]) {
    if (it->first == p) continue;
    dfs(it->first, v);
  }
  dp[v] = 0;
  FOR(it, g[v]) {
    if (it->first == p) continue;
    int cost = it->second;
    int u = it->first;
    int tmp = INF; 
    if (C[u]) {
      tmp = cost;
    } else {
      tmp = dp[u];
      chmin(tmp, cost);
    }
    dp[v] += tmp;
  }
}
int main() {
  int n;
  while(cin >> n) {
    REP(i,n) g[i].clear();
    REP(i,n-1) cin >> C[i+1];
    REP(i,n-1) {
      int a,b,c;
      input(a,b,c);
      g[a].push_back(pii(b,c));
      g[b].push_back(pii(a,c));
    }
    dfs(0,-1);
    cout << dp[0] << endl;
  }
}

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


int main(){
	long long ans=0;
	string S; cin >> S;
	for(int i=1; i<S.size(); i++){
		if(S[i-1]==S[i]){
			ans+=1;
			if(S[i]=='0')
			S[i]='1';
			else
			S[i]='0';
		}
	}
cout << ans << endl;
}

Measured memory_bytes: 512
#!/usr/bin/env python
N = int(input())
S = [input() for i in range(N)]
c1, c2, c3, c = 0, 0, 0, 0
for s in S:
    if s[-1] == 'A' and s[0] == 'B':
        c1 += 1
    elif s[-1] != 'A' and s[0] == 'B':
        c2 += 1
    elif s[-1] == 'A' and s[0] != 'B':
        c3 += 1
    c += s.count('AB')

if c1 == 0:
    print(c + min(c2, c3))
elif c2 + c3 > 0:
    print(c + c1 + min(c2, c3))
else:
    print(c + c1 -1)



Measured memory_bytes: 3700
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
int cnt1=0,cnt2[100050],cnt3=0;
int main()
{
    int n,m;
    int vis[100050]={0};
    int p;
    char s[10];
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%s",&p,s);
        if(!vis[p])
        {
            if(strcmp(s,"AC")==0)
            {
                cnt1++;
                cnt3+=cnt2[p];
                vis[p]=1;
            }
            else
            {
                cnt2[p]++;
            }
        }
    }
    printf("%d %d\n",cnt1,cnt3);
}


Measured memory_bytes: 1024
package main
import "fmt"
func main() {
  var a,b,c,d,f int
  var e,per,tmp float64
  fmt.Scan(&a,&b,&c,&d,&e,&f)
  set := make(map[SugarWater]struct{})
  for i:=0;i<=f/(100*b);i++ {
    var w int = i*100*b
    for j:=0;j<=(f-w)/(100*a);j++ {
      if i == 0 && j == 0 { continue }
      set[SugarWater{0,w+j*100*a}] = struct{}{}
    }
  }
  max := SugarWater{0,100*a}
  per = 0.0
  for sw,_ := range set {
    var w int = sw.water
    for i:=0;i<=(f-w)/d;i++ {
      for j:=0;j<=(f-w-i*d)/c;j++ {
        tsw := SugarWater{i*d+j*c,w}
        if tsw.ratio() > e { break }
        if tsw.total() > f { break }
        tmp = tsw.concentration()
        if per < tmp {
          per = tmp
          max = tsw
        }
      }
    }
  }
  fmt.Println(max.total(),max.sugar)
}
type SugarWater struct {
  sugar int
  water int
}
func(sw SugarWater) total() int {
  return sw.sugar+sw.water
}
func(sw SugarWater) ratio() float64 {
  return float64(sw.sugar)/float64(sw.water/100)
}
func(sw SugarWater) concentration() float64 {
  return float64(100*sw.sugar)/float64(sw.sugar+sw.water)
}

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

int main(){
    int i, j;
    string s, t, s2;
    cin >> s >> t;
    s2 = s + s;
    for(i=0; i<t.length(); i++){
        for(j=0; j<t.length(); j++){
            if(s2[i+j] != t[j]){
                break;
            }
            if(j == t.length()-1){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}

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

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

  int n;
  string s;
  cin >> n >> s;

  map<char,ll> mp;
  for (int i = 0; i < n; ++i) ++mp[s[i]];

  ll ans = mp['R'] * mp['G'] * mp['B'];

  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      int k = j + (j - i);
      if (k >= n) continue;
      
      if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) --ans;
    }
  }

  cout << ans << '\n';

  return (0);
}


Measured memory_bytes: 3644
(n,k) = gets.chomp.split(" ")
n = n.to_i
k = k.to_i
h = gets.split(" ").map!{|i | i.to_i} 
if n-k <= 0
  sum = 0
else
  h = h.sort.slice(0..(n-k-1))
  sum = h.inject(:+)
end
puts sum

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

typedef unsigned long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = N;
    ll c1 = N;
    ll c4, c5;
    if ((B - A) % 2 == 0) {
        c1 = (B - A) / 2;
        c4 = (A + B - 2) / 2;
        c5 = (2 * N - A - B) / 2;
    } else {
        c4 = (A + B - 2 + 1) / 2;
        c5 = (2 * N - A - B + 1) / 2;
    }
    ans = min(ans, c1);
    ans = min(ans, c4);
    ans = min(ans, c5);
    cout << ans << endl;
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int a[3]={};
  for(int i=0;i<s.size();i++){
    a[s[i]-'a']++;
  }
  int c=min({a[0],a[1],a[2]});
  r(i,3)a[i]-=c;
  sort(a,a+3);
  if(a[2]>1||a[1]>1)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int a = 0;
  int b = n;
  int c = 100000000;
  for (int i = 0; i < 9; i++) {
    a += b / c;
    b %= c;
    c /= 10;
  }
  
  if (n % a == 0)
    cout << "Yes" << endl;
  
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 256
import java.util.*;

class Main{

    int[] par, rank;

    void init(int n){
        par = new int[n];
        rank = new int[n];
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }

    int find(int x){
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }

    void unit(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return;

        if(rank[x]<rank[y]) par[x] = y;
        else{
            par[y] = x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    boolean same(int x, int y){
        return find(x) == find(y);
    }

    void solve(){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        while(n!=0 || m!=0){
            if(m==0){
                System.out.println("-1");
                n = sc.nextInt();
                m = sc.nextInt();
                continue;
            }

            int[][] edge = new int[m][3];
            for(int i=0; i<m; i++){
                edge[i][0] = sc.nextInt()-1;
                edge[i][1] = sc.nextInt()-1;
                edge[i][2] = sc.nextInt();
            }

            Arrays.sort(edge, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        return a[2] - b[2];
                    }
                });

            int max = Integer.MAX_VALUE;            
            int min = edge[0][2];
            for(int i=0; i<m; i++){
                init(n);
                min = edge[i][2];
                int maxx = 0;
                int cnt = 0;
                for(int j=i; j<m; j++){
                    if(same(edge[j][0], edge[j][1])) continue;
                    maxx = edge[j][2] - min;
                    unit(edge[j][0], edge[j][1]);
                    cnt++;
                    if(cnt==n-1) break;
                }
                if(cnt==n-1) max = Math.min(max, maxx);
                //while(i+1<n && edge[i+1][2]==min) i++;
            }

            if(max==Integer.MAX_VALUE) System.out.println("-1");
            else System.out.println(max);

            n = sc.nextInt();
            m = sc.nextInt();
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 76048
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long H, cnt=0, sum=0;
  cin >> H;
  if(H==1){
    cout << 1 << endl;
    return 0;
  }
  else{
    while(1){
        if(H == 1){
            break;
        }
      H = H / 2;
      cnt ++;
  }
  for(int i = 0; i <= cnt; i++){
      sum += pow(2, i);
  }
  cout << sum << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) 0;
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

void err() { std::cout << "NO" << std::endl; exit(0); }
#define require(exp) do { if (!(exp)) { err(); } } while(false)

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s; std::cin >> s;
  std::vector< std::string > cand{
    "er",
    "eras",
    "erase",
    "dream"
  };
  std::vector< int > a;
  while (!s.empty()) {
    bool ckd = false;
    rep(i,0,4) {
      std::string t = cand.at(i);
      if (s.back() == t.back()) {
        require(t.length() <= s.length() && s.substr(s.length() - t.length(), t.length()) == t);
        loop(t.length()) s.pop_back();
        a.push_back(i);
        ckd = true;
      }
    }
    require(ckd);
  }
  std::reverse(all(a));
  // debug(a);
  int n = a.size();
  rep(i,0,n-1) {
    int x = a.at(i), y = a.at(i + 1);
    if (x == 0 && y == 0) err();
    if (x == 1) require(y == 0);
    if (x == 2) require(y != 0);
  }
  std::cout << "YES" << std::endl;
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


bool prime[300001]={false};
void isPrime(){
	prime[1]=true;
	for(int i=2;i*i<300000;i++){
		if(!prime[i]){
			for(int j=2*i;j<300000;j+=i){
				prime[j]=true;
			}
		}
	}

	return;
}

int main(){
	isPrime();
	int N;
	while(cin>>N,N){
		int count=0;
		REP(i,N+1,2*N+1){
			if(!prime[i]) count++;
		}
		p(count);
	}
	return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
#define M 1000000007
int n,x;
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        x+=a%2;
    }
    if(x%2)printf("NO\n");
    else printf("YES\n");
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<vector>
#include<stdio.h>
typedef int long long ll;
using namespace std;

int main(){
    ll n,k;
    cin>>n>>k;
    
    vector<ll> h(n);
    for(ll i=0;i<n;i++){
        ll x;cin>>x;
        h[i]=x;
    }
    vector<ll> a(n);
    a[0]=0;
    for(ll i=1;i<n;i++){
        ll mi=1e+14;
        for(ll j=i-1;j>=0&&j>=i-k;j--){
            mi=min((abs(h[i]-h[j])+a[j]),mi);
        }
        a[i]=mi;
    }
    
    cout<<a[n-1]<<endl;
    
    
    
   /* a[1]=abs(h[1]-h[0]);
    if(n==2){cout<<a[1];return 0;}
    for(int i=2;i<n;i++){
        a[i]=min((abs(h[i]-h[i-1])+a[i-1]),abs(h[i]-h[i-2])+a[i-2]);
    }
    cout<<a[n-1]<<endl;*/
    
    return 0;
}


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

int main() {
    ll N, K; cin >> N >> K;
    if (K % 2 == 0) {
        ll ans =(N / K) * (N / K) * (N / K);
        if (N >= K / 2) ans += ((N - K/2) / K + 1) * ((N - K/2) / K + 1) * ((N - K/2) / K + 1);
        cout << ans<< endl;
    } else {
        cout << (N / K) * (N / K) * (N / K)  << endl;
    }
}


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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v(n+m);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v[i] = make_pair(a, 1);
    }
    for (int i = 0; i < m; i++) {
        int b, c;
        cin >> b >> c;
        v[n+i] = make_pair(c, b);
    }
    sort(v.rbegin(), v.rend());
    int64_t ans = 0;
    int cur = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < v[i].second; j++) {
            cur++;
            ans += v[i].first;
            if (cur >= n) {
                cout << ans << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 1792
# include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
using namespace std;

int main() {
	int m;
	while (cin >> m&&m != 0) {
		vector<int>fx, fy, px, py;
		int a, b;
		for (int i = 0; i < m; i++) {
			cin >> a >> b;
			fx.emplace_back(a);
			fy.emplace_back(b);
		}
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			px.emplace_back(a);
			py.emplace_back(b);
		}
		for (int i = 0; i < n; i++) {
			int movex = px[i] - fx[0], movey = py[i] - fy[0];
			int count = 0;
			for (int j = 0; j < m; j++) {
				for (int o = 0; o < n; o++) {
					if (fx[j] + movex == px[o] && fy[j] + movey == py[o]) {
						count++;
					}
				}
			}
			if (count == m) {
				cout << movex << " " << movey << endl;
			}
		}
	}
}

Measured memory_bytes: 3104
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
namespace Dango
{
	const int MAXN=100005;
	vector<int> cir;
	int n,m;
	int head[MAXN],to[MAXN<<1],nxt[MAXN<<1];
	int fa[MAXN];
	int d[MAXN],tfa[MAXN];
	int rt,ed;
	int res[MAXN];
	long long ans;
	int read()
	{
		int x=0,f=0;
		char ch=getchar();
		while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
		while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
		return f?-x:x;
	}
	int ffind(int a){return fa[a]==a?a:fa[a]=ffind(fa[a]);}
	void add(int u,int v)
	{
		static int cnt;
		cnt++;
		to[cnt]=v;
		nxt[cnt]=head[u];
		head[u]=cnt;
	}
	void dfs(int u,int f)
	{
		d[u]=d[f]+1;
		tfa[u]=f;
		res[u]+=d[u]&1?1:-1;
		for(int i=head[u];i;i=nxt[i])
		{
			int v=to[i];
			if(v==f)continue;
			dfs(v,u);
			res[u]+=res[v];
		}
	}
	void solve_tree()
	{
		dfs(1,0);
		if(res[1]!=0)ans=-1;
		else
			for(int i=1;i<=n;i++)
				ans+=res[i]<0?-res[i]:res[i];
		printf("%lld",ans);
	}
	void solve()
	{
		dfs(rt,0);
		for(int i=ed;i;i=tfa[i])cir.push_back(res[i]);
		if(cir.size()&1)
		{
			if(res[rt]&1)ans=-1;
			else
			{
				for(int i=ed;i;i=tfa[i])
					res[i]-=res[rt]>>1;
				for(int i=1;i<=n;i++)
					ans+=res[i]<0?-res[i]:res[i];
			}
		}
		else
		{
			if(res[rt])ans=-1;
			else
			{
				sort(cir.begin(),cir.end());
				int mid=cir.size()>>1;
				for(int i=ed;i;i=tfa[i])
					res[i]-=cir[mid];
				for(int i=1;i<=n;i++)
					ans+=res[i]<0?-res[i]:res[i];
			}
		}
		printf("%lld",ans);
	}
	int work()
	{
		n=read();m=read();
		for(int i=1;i<=n;i++)
			fa[i]=i;
		for(int i=1;i<=m;i++)
		{
			int u=read(),v=read();
			int a=ffind(u),b=ffind(v);
			if(a!=b)
			{
				add(u,v);add(v,u);
				fa[a]=b;
			}
			else{rt=u;ed=v;}
		}
		if(m==n-1)solve_tree();
		else solve();
		return 0;
	}
}
int main()
{
	return Dango::work();
}

Measured memory_bytes: 9084
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll max(ll a, ll b){
	if(a>b)return a;
	else return b;
}

int main(){
    int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d){
    	cout<<"Yes"<<endl;
	}else
	cout<<"No"<<endl;
}

Measured memory_bytes: 3528
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]
for a, b in AB:
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)


# @debug
def solve(v, parent=None):
    # 子供の grundy とったらいい
    xor = 0
    for u in graph[v]:
        if parent == u:
            continue
        xor ^= solve(u, parent=v) + 1
    return xor


ans = solve(0)
if ans == 0:
    print('Bob')
else:
    print('Alice')


Measured memory_bytes: 147944
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  rep(i, N) cin >> p[i];
  int count = 0;
  rep(i, N) {
    if(p[i] != i+1)
      count++;
  }
  if(count <= 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
	$input = trim(fgets(STDIN));
	list($r, $c) = explode(" ", $input);

	$cell = array_fill(0, $r+1, array_fill(0, $c+1, 0));

	for ($i = 0; $i < $r; $i++) {
		$row = trim(fgets(STDIN));
		$row = explode(" ", $row);

		for ($j = 0; $j < $c; $j++) {
			$cell[$i][$j] = $row[$j];
			$cell[$r][$j] += $row[$j];
		}
		$cell[$i][$c] = array_sum($row);
		echo implode(" ", $cell[$i]) . "\n";
	}

	$cell[$r][$c] = array_sum($cell[$r]);
	echo implode(" ", $cell[$r]) . "\n";

Measured memory_bytes: 8420
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

int main()
{
    string o, e;
    cin >> o >> e;

    string ans = "";
    rep(i,o.length()) {
        cout << o[i];
        if (i < e.length())
            cout << e[i];
    }

    cout << endl;
    return 0;
}


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

int linearSearch(int A[], int n, int key){
   A[n] = key;
   int i=0; 
   while(A[i] != key) i++;
   return i != n;
}

int main()
{
   int n, q, key, sum = 0;
   int S[10000+1];
   cin >> n;
   for(int i=0; i<n; i++) cin >> S[i];
   
   cin >> q;
   for(int i=0; i<q; i++){
      cin >> key;
      if(linearSearch(S, n, key)) sum++;
   }
   cout << sum << endl;
}


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
vector<int> g[100005];
queue<int> ne;
bool use[100005][4];
int ans[100005];

void dfs(int v, int d, int s) {

  if(d == 3 && !use[v][3]) {
    ans[v] = min(ans[v],ans[s] + 1);
    use[v][3] = true;
    ne.push(v);
    return;
  }

  use[v][d] = true;

  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if(d + 1 < 4 && !use[u][d+1]) dfs(u,d+1,s);
  }
  return;
}

int main() {
  int n,m;
  int s,t;
  cin >> n >> m;

  for(int i = 0; i < m; i++) {
    int u,v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
  }

  cin >> s >> t;
  s--;
  t--;
  ne.push(s);
  use[s][0] = true;

  for(int i = 0; i < n; i++) ans[i] = 1000000;
  ans[s] = 0;
  
  while(!ne.empty()) {
    
    int V = ne.front();
    // cout << "V = " << V << endl;
    if(V == t) break;
    ne.pop();
    dfs(V,0,V);
  }

  if(ans[t] != 1000000) cout << ans[t] << endl;
  else cout << -1 << endl;
}
  
  


Measured memory_bytes: 6528
import math
n=int(input())
A=[]
#print(A)
for i in range(2):
	A.append(input().split())

#Manhattan=|x1-y1|+|x2-y2|+|x3-y3|
Manhattan=0
#Euclidean
Euclidean=0
#Minkowski_3
Minkowski_3=0
#Chebyshev
Chebyshev=[]
for i in range(n):	
	a=math.fabs(int(A[0][i])-int(A[1][i]))
	Manhattan+=a
	Euclidean+=a**2
	Minkowski_3+=a**3
	Chebyshev.append(a)




Euclidean=math.sqrt(Euclidean)
Minkowski_3=Minkowski_3**(1/3)
Chebyshev.sort()
Chebyshev.reverse()
print(Manhattan)
print(Euclidean)
print(Minkowski_3)
print(Chebyshev[0])

Measured memory_bytes: 7828
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n,T;cin>>n>>T;
  vector<ll> c(n),t(n);
  ll ans=INF;
  rep(i,n){
    cin>>c[i]>>t[i];
    if(t[i]<=T){
      ans=min(ans,c[i]);
    }
  }
  if(ans==INF){
    cout<<"TLE"<<endl;
  }else{
    cout<<ans<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret

# 全探索だと
# 3^N通りになってTLEだこれ

# 制限がなければ、iごとにmaxを取っておわりO(N)

# iの時の最善の状態が[i,j](jは行動)のとき、i+1最善の状態は[i+1,k](k!=j)となる
# これはDPで実装できそう！


# import numpy as np

# N = read_a_int()
# ABC = np.array(read_matrix(N))
# # A, B, C = read_col(N, 3)

# dp = np.full((N, 3), 0, dtype='int16')
# # 0->a,1->b,2->c

# dp[0, :] = ABC[0]

# for i in range(N - 1):
#     for j, abc in enumerate(ABC[i+1]):
#         dp[i + 1, j] = dp[i, [k for k in range(3) if k != j]].max() + abc

# # print(dp)
# print(dp[-1].max())

# TLEしたのでpypy3仕様にかきなおし

N = read_a_int()
ABC = read_matrix(N)

# dp = np.full((N, 3), -float('inf'))
dp = [[-float('inf') for _ in range(3)] for _ in range(N)]
# 0->a,1->b,2->c

for i in range(3):
    dp[0][i] = ABC[0][i]

for i in range(N - 1):

    for j in range(3):
        dp[i+1][j] = max([dp[i][k] + ABC[i+1][j] for k in range(3) if k != j])

print(int(max(dp[-1])))


Measured memory_bytes: 84828
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;

int main() {fio;
	ll n, k;
	cin >> n >> k;
	ll g = n;
	n %= k;
	int iter = 3233;
	while(iter--) {
		n = abs(n - k);
		g = min(g, n);
	}
	cout << g << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

for i in range(4) :
   t, n = map(int, input().split())
   if t == 1:
      print(n * 6000)
   elif t == 2:
      print(n * 4000)
   elif t == 3:
      print(n * 3000)
   else:
      print(n * 2000)


Measured memory_bytes: 5596
N = int(raw_input())
h_str = raw_input()
h = []
for h_i in h_str.split(" "):
    h.append(int(h_i))

dp = [10 ** 9 + 1] * N
dp[0] = 0
for i in range(N):
    for j in (i + 1, i + 2):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[N-1])

Measured memory_bytes: 12784
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <limits>
#include <utility>

typedef long long ll;

ll solvebit(std::vector<ll> &a, const int bit)
{
    const int n = a.size();
    const ll d = 1000000007;
    const ll bitmap = 1LL<<bit;

    std::vector<int> bitcount(n);
    bitcount[0] = 0;

    for (int i = 1; i < n; i++) {
        bitcount[i] = bitcount[i - 1] + ((a[i - 1] & bitmap)?1:0);
    }

    ll sum = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] & bitmap) { // 1用の処理
            ll c = i - bitcount[i];
            sum += (c % d) * (bitmap % d);
        } else { // 0用の処理
            ll c = bitcount[i];
            sum += (c % d) * (bitmap % d);
        }
        sum %= d;
    }

    return sum;
}

ll solve(std::vector<ll> &a)
{
    const int n = a.size();
    const ll d = 1000000007;

    ll sum = 0;

    for (int i = 0; i < 60; i++) {
        sum = (sum + solvebit(a, i)) % d;
    }

    return sum;
}

int main(int argc, char *argv[])
{
    int n;
    std::vector<ll> a;
    ll ans;

    // input
    std::cin >> n;
    a.resize(n);

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

    ans = solve(a);

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3820
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    s = input().rstrip()
    l, r = 0, 0
    res = 0
    while r < n:
        r += 1
        if not s[l:r] in s[r:]:
            l += 1
            res = max(res, r-l)
    print(res)

if __name__ == '__main__':
    main()


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

int main()
{
	//?°´?????????
	int num1=0,num2=0,num3=0,num4=0,num5=0,x=0,y=0;
	cin>>num1>>num2>>num3>>num4>>num5;
	x=num1*num5;
	if(num3>num5){
		y=num2;
		if(x<y){
			cout<<x;
		}
		if(x>y){
			cout<<y;
		}
	}
	if(num3<num5){
		y=num2+num4*(num5-num3);
		if(x<y){
			cout<<x;
		}
		if(x>y){
			cout<<y;
		}
	}
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<bits/stdc++.h>
#include<map>
#include<iterator>
#include<string>
#include<string.h>
#include<math.h>
#include<vector>
#define ll long long
#define mod 1000000007
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    int a,b;
  	cin>>a>>b;
  	if(2*b>=a)
      cout<<0<<endl;
  	else
      cout<<(a-(2*b))<<endl;
  return 0;
}

Measured memory_bytes: 256
#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+r>W || x>=W) {
 
       printf("No\n");
 
}else if(y+r>H || y>=H){
      printf("No\n");    
}else if(x-r<0 || x<=0){
      printf("No\n");
}else if(y-r<0 || y<=0){
      printf("No\n");
}else{
      printf("Yes\n");
}
 return 0;
 
}
 

 

Measured memory_bytes: 580
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>


using namespace std;
using ll = long long int; 

int main(void){

    int a[3][3];
    int b[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            int x;
            cin>>x;
            a[i][j] = x;
            b[i][j] = 0;
        }
    }

    int n;
    cin>>n;

    for(int i=0;i<n;i++){
        int x;
        cin>>x;

        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(a[i][j]==x)b[i][j]++;
            }
        }
    }
    // for(int i=0;i<3;i++){
    //     for(int j=0;j<3;j++){
    //         cout<<b[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    //tate
    int calc1=1, calc2=1, calc3=1;
    for(int i=0;i<3;i++){
        calc1 *= b[0][i];
        calc2 *= b[1][i];
        calc3 *= b[2][i];
    }
    if(calc1!=0 || calc2!=0 || calc3!=0){
        cout<<"Yes"<<endl;
        return 0;
    }

    //yoko
    calc1=1, calc2=1, calc3=1;
    for(int i=0;i<3;i++){
        calc1 *= b[i][0];
        calc2 *= b[i][1];
        calc3 *= b[i][2];
    }
    if(calc1!=0 || calc2!=0 || calc3!=0){
        cout<<"Yes"<<endl;
        return 0;
    }

    //naname
    calc1=1, calc2=1, calc3=1;
    calc1 = b[0][0]*b[1][1]*b[2][2];
    calc2 = b[0][2]*b[1][1]*b[2][0];
    if(calc1!=0 || calc2!=0){
        cout<<"Yes"<<endl;
        return 0;
    }

    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Go to School
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    scanf("%d", &ps[i].first), ps[i].second = i + 1;
  sort(ps, ps + n);

  for (int i = 0; i < n; i++) {
    if (i) putchar(' ');
    printf("%d", ps[i].second);
  }
  putchar('\n');
  return 0;
}


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

int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    if(A*B*C == 175){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}   

Measured memory_bytes: 256
cnt = 0

def main():
    n = int(input())
    m = len(str(n))
    nl = len(str(n))

    def cal(A):
        l = len(A) - 1
        ans = 0
        for idx, i in enumerate(A):
            ans += i*10**(l - idx)
        return ans

    def dfs(A):
        global cnt
        if len(A) == m:
            if len(list(set(A) & set([3, 5, 7]))) == 3:
                if (cal(A)) <= n:
                    # print(cal(A))
                    cnt += 1
            return
        for i in (3, 5, 7):
            A.append(i)
            dfs(A)
            A.pop()
    for m in range(nl+1):
         dfs([])
    print(cnt)

if __name__ == '__main__':
    main()

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++)
    cin >> h.at(i);
  sort(h.begin(), h.end());
  int min = 2000000000;
  for (int i = 0; i < N - K + 1; i++){
    int difference = h.at(i + K - 1) - h.at(i);
    if (difference < min)
      min = difference;
  }
  cout << min << endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {

        int N = NextInt();
        long x = NextLong();
        long[] a = LineLong();
        long[] b = a.ToArray();
        //全部飼う
        long ans = a.Sum();
        for (int k = 0; k < N; k++)
        {
            //k回魔法唱える
            long cost = k * x;
            for (int i = 0; i < N; i++) b[i] = Math.Min(b[i], a[(i - k + N) % N]);
            cost += b.Sum();

            ans = Math.Min(ans, cost);
        }
        Console.WriteLine(ans);
    }

    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}


public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13568