akhauriyash/Code-Regression huggingface dataset:
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<=ll(b);++i)
#define ALL(f,x,...) ([&](decltype((x)) xxxx) { return (f)(begin(xxxx), end(xxxx), ## __VA_ARGS__); })(x)
#define lim 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define MSG(msg1,msg2,flag) cout<<((flag)? msg1:msg2);

#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}
vector<char> 
string_to_vector_char(const string& input){vector<char> out(input.length());rep(i,input.length()){out[i]=input[i];}return out;}
template <class T> map<T,int> 
count_same_elements(const vector<T>& v){map<T,int>cmap; for_each(v.begin(),v.end(),[&cmap](auto x){cmap[x]++;}); return cmap; }
template<class A,class B> vector<B> 
mapf(const vector<A>& v,const function<B(A)>& func){vector<B> v_(v.size());rep(i,v.size()){ v_[i]=func(v[i]); }return v_;}
template<class A,class B> vector<B> 
adjacent_map(const vector<A>& v,const function<B(A,A)>& func){vector<B> v_(v.size()-1);rep(i,v.size()-1){ v_[i]=func(v[i+1],v[i]); }return v_;}
template<class A> bool
all_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]<1){flag=false;}; }return flag;}
template<class A> bool
any_of(const vector<A>& v){bool flag=false;rep(i,v.size()){ if(v[i]>0){flag=true; break;}; }return flag;}
template<class A> bool
none_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]>0){flag=false;}; }return flag;}
template<class T>
void scan_vector(long long size,vector<T>& vector){
    vector.resize(size);
    for(long long i=0;i<size;++i){
        cin>>vector[i];
    }
}
int n,t,a;
vector<int> p;
void input(){
    cin>>n;
    scan_vector(n,p);
}
void src(){
    cout<<accumulate(p.begin(),p.end(),0)-*max_element(p.begin(),p.end())/2;
}   

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll,ll> tllll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t; cin >> t;
  vector<string> ans(t);
  rep(i,t){
    ll a,b,c,d; cin >> a >> b >> c >> d;
    bool f=1;
    if(a<b||b>d||(a%b)>c) f=0;
    if(gcd(b,d)==1&&b-c>1) f=0;
    if((c-(a%b))/gcd(b,d)*gcd(b,d)+(a%b)+gcd(b,d)<b) f=0;
    if(f) ans[i]="Yes";
    else ans[i]="No";
  }
  rep(i,t){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 3528
#include <iostream>
#include <vector>
using namespace std;
long long int N,Y;
int main(){
	cin >> N >> Y;
	for(long long int x=0;x<=N;x++){
		for(long long  y=0;x+y<=N;y++){
				if(1000*x+5000*y+10000*(N-x-y) == Y){
					printf("%d %d %d\n",(N-x-y),y,x);
					return 0;
				}
		}
	}
	printf("-1 -1 -1\n");
	return 0;
}


Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    p = 0
    for j in range(m):
        p += a[i][j] * b[j]
    if p + c > 0:
        ans += 1
print(ans)


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

int N, M;
vector<int> T, P, X;
int sum;

int main(void) {
	cin >> N;
	T.resize(N);
	sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> T[i];
		sum += T[i];
	}

	cin >> M;
	P.resize(M);
	X.resize(M);
	for (int i = 0; i < M; ++i)
		cin >> P[i] >> X[i];
	
	for (int i = 0; i < M; ++i)
		cout << (sum - T[P[i] - 1] + X[i]) << '\n';
	return 0;
}


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

typedef intmax_t ll;

int main(){
    ll x, a = 0, b;
    cin >> x;
    bool flag = true;

    while(flag){
        a++;
        ll aa = a * a * a * a * a;
        ll m = abs(x - aa);
        b = 0;
        ll bb = 0;

        while(bb <= m){
            bb = b * b * b * b * b;
            if(bb == m){
                flag = false;
                break;
            }
            b++;
        }
    }

    if(a * a * a * a * a < x) b = -b;
    cout << a << ' ' << b << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

unsigned int gcd(unsigned int n1, unsigned int n2)
{
  unsigned int n3;

  while (n1 != 0){
    n3 = n2;
    n2 = n1;
    n1 = n3 % n2;
  }

  return n2;
}

int main(void)
{
  unsigned int a, b;
  unsigned int i, j;

  i = 0;
  while (scanf("%d%d", &a, &b) != EOF){
    printf("%d %d\n", gcd(a, b), (a / gcd(a, b) * b)); 
  }
  return 0;
}

Measured memory_bytes: 596
N = int(input())
A = list(map(int, input().split()))
num = 1
for i in range(0,N):
    if A[i]==0:
      	num=0
      	break
for i in range(0,N):
    if num>10**18:
        break
    else:
        num *=A[i]
if num>10**18:
    print(-1)
else:
    print(num)

Measured memory_bytes: 21588
#include <stdio.h>

int main()
{
  int x, y, r, tmp;

  scanf("%d %d", &x, &y);

  if(x < y){
    tmp = x;
    x = y;
    y = tmp;
  }
  
  r = x % y;

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

  printf("%d\n", y);

  return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {
    static int mod = 1000000007;
    static long[] nFactorial;
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);

        int n, k;

        n = cin.nextInt();
        k = cin.nextInt();

        if (k >= n - 1) {
            System.out.println(choose(2 * n - 1, n -1));
        } else {
            long sum = 0;
            nFactorial = new long[n];
            fill();
            for (int i = 0; i <= k; i++) {
                sum = (sum + term(n, i)) % mod;
                sum %= mod;
            }
            System.out.println(sum);
        }
    }

    public static long pow(long n, int m) {
        long prod = 1;
        while (m > 0) {
            if ((m & 1) == 1) {
                prod = (prod * n) % mod;
            }
            n = (n*n) % mod;
            m >>= 1;
        }
        return prod;
    }

    public static void fill () {
        nFactorial[0] = 1;
        for (int i = 1; i < nFactorial.length; i++) {
            nFactorial[i] = (nFactorial[i - 1] * i) % mod;
        }
    }

    public static long choose(int a, int b) {
        long numerator = 1;
        long denominator = 1;
        for (int i = 1; i <= b; i++) {
            numerator *= a - i + 1;
            denominator *= b - i + 1;
            numerator %= mod;
            denominator %= mod;
        }
        return (numerator * pow(denominator, mod - 2)) % mod;
    }

    public static long term(int n, int i) {
        long numerator = 1;
        long denominator = 1;
        numerator = (n * pow(nFactorial[n - 1], 2)) % mod;
        denominator = (((n - i) * pow(nFactorial[i], 2)) % mod * pow(nFactorial[n - i - 1], 2)) % mod;
        return (numerator * pow(denominator, mod - 2)) % mod;
    }
}


























Measured memory_bytes: 25556
using System;
using System.Linq;

namespace diverta2019_2
{
    class A
    {

        static void Main(string[] args)
        {
            var input = Input.IntArray();
            var N = input[0];
            var K = input[1];

            if (K == 1) {
                Console.WriteLine(0);
            } else {
                Console.WriteLine(N - K);
            }
            

        }


        /** Input Class */
        internal static class Input
        {
            /** input int */
            public static int Int() => int.Parse(Console.ReadLine());

            /** input str */
            public static string Str() => Console.ReadLine();

            /** input array of int */
            public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            /** input array of string */
            public static string[] StrArray() => Input.Str().Split(' ');

            /** input array of char */
            public static char[] charArray() => Input.Str().ToCharArray();
        }

    }
}


Measured memory_bytes: 13396
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>

using namespace std;

int n;
char s[200001];
int z[200001];
long long ans[26];

void calc(long long c, long long g, long long f) {
    int i;
    
    for (i = 0; i < g; i++) ans[s[i] - 'a'] += c / g * f;
    for (i = 0; i < c % g; i++) ans[s[i] - 'a'] += f;
}

void calc2(long long c, long long x, long long y, int f) {
    int i;
    vector <long long> v;
    map <long long, long long> mp;
    map <long long, long long>::reverse_iterator it;
    
    v.push_back(x);
    v.push_back(y);
    
    while (v.back() < c) {
        v.push_back(v[v.size() - 1] + v[v.size() - 2]);
    }
    
    mp[c] += f;
    
    for (it = mp.rbegin(); it != mp.rend(); it++) {
        long long x = it->first;
        
        for (i = 0; ; i++) {
            if (v[i] >= x) break;
        }
        
        if (v[i] <= n) {
            calc(x, v[i], it->second);
        } else {
            mp[v[i - 1]] += it->second;
            mp[x - v[i - 1]] += it->second;
        }
    }
}

int main() {
    int x, y, i, j, k;
    long long l, r;
    
    scanf("%s", s);
    scanf("%lld %lld", &l, &r);
    
    n = strlen(s);
    
    i = 1, j = 0;
    z[0] = n;
    
    while (i < n) {
        while (i + j < n && s[j] == s[i + j]) j++;
        
        z[i] = j;
        
        if (j == 0) {
            i++;
            
            continue;
        }
        
        k = 1;
        
        while (i + k < n && k + z[k] < j) {
            z[i + k] = z[k];
            k++;
        }
        
        i += k;
        j -= k;
    }
    
    x = n / 2;
    y = n;
    
    for (i = n - 1; i > n / 2; i--) {
        if (i + z[i] == n) y = i;
    }
    
    calc2(r, x, y, 1);
    calc2(l - 1, x, y, -1);
    
    for (i = 0; i < 26; i++) {
        if (i > 0) putchar(' ');
        
        printf("%lld", ans[i]);
    }
    puts("");
    
    return 0;
}


Measured memory_bytes: 1280
a, b, c, k = [int(i) for i in input().split(' ')]

sum = 0
if k >= a:
  sum += a
  k -= a
elif k < a:
  sum += k
  print(sum)
  exit()
if k >= b:
  k -= b
elif k < b:
  sum += k
  print(sum)
  exit()
if k >= c:
  sum -= c
elif k < c:
  sum -= k
  print(sum)
  exit()

print(sum)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll m; cin >> m;
    cout << 24+(24-m) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 2e5 + 5;
const int INF = 1e9 + 5;

int n, a[N];

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	bool ok = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if(a[i] & 1) continue;
		if(a[i] % 3 != 0 && a[i] % 5 != 0) {
			ok = 0;
		}
	}
	if(ok) cout << "APPROVED";
	else cout << "DENIED";
	return 0;
}
/*
	If you only do what you can do, 
	You will never be more than you are now!
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define all(x) (x).begin(), (x).end()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;

    int ans = 0;
    rep(i, 0, n) {
        if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) ans += 2;
        else if (a[i] == b[i] && b[i] == c[i]) continue;
        else ans++;
    }

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


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

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

	unordered_set<int> us;
	us.insert(s);
	int index = 1;
	while (true)
	{
		if (s % 2 == 0)
		{
			s /= 2;
			index++;
		}
		else
		{
			s = 3 * s + 1;
			index++;
		}

		if (us.find(s) != us.end())
		{
			cout << index << endl;
			return 0;
		}

		us.insert(s);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
typedef unsigned int uint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=100010;
inline uint lowbit(uint x){
	return x&-x;
}
inline uint highbit(uint x){
	for(;x!=(x&-x);x^=x&-x);
	return x;
}
namespace T{
	const int E=N<<1;
	int to[E],bro[E],head[N],e=0;
	inline void init(){
		memset(head,-1,sizeof(head));
	}
	inline void ae(int u,int v){
		to[e]=v,bro[e]=head[u],head[u]=e++;
	}
	inline void add(int u,int v){
		ae(u,v),ae(v,u);
	}
	uint dfs(int x,int fa){
		uint ans=0,hb=1;
		for(int i=head[x],v;~i;i=bro[i]){
			if((v=to[i])!=fa){
				uint cur=dfs(v,x);
				apmax(hb,highbit(cur&ans)<<1);
				ans|=cur;
			}
		}
		for(;hb&ans;hb<<=1);
		return hb|(ans&~(hb-1));
	}
}
int main(){
	int n=ni;
	T::init();
	for(int i=1;i<n;T::add(ni,ni),i++);
	uint tmp=T::dfs(1,0);
	int ans=0;
	for(;tmp>1;tmp>>=1,ans++);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define height(i) (abs(X[i]-x)+abs(Y[i]-y)+h[i])
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> X(N),Y(N),h(N);
  for(int i=0;i<N;i++)cin>>X[i]>>Y[i]>>h[i];
  
  for(int x=0;x<=100;x++){
    for(int y=0;y<=100;y++){
      int ch=-1;
      for(int i=0;i<N;i++){
        if(h[i]==0)continue;
        if(ch==-1){ch=height(i);continue;}
        if(ch!=height(i)){ch=-2;break;}
      }
      if(ch>0){
        for(int i=0;i<N;i++)if(h[i]!=max(ch-abs(X[i]-x)-abs(Y[i]-y),0)){ch=-2; break;}
        if(ch>0){cout<<x<<" "<<y<<" "<<ch<<endl;return 0;}
      }
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>

int main(void) {
  long double a,b,c;
  scanf("%Lf %Lf %Lf",&a,&b,&c);
  if (a+b+2*sqrtl(a*b)<c) printf("Yes");
  else printf("No");

 return EXIT_SUCCESS;
}

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

using namespace std;

typedef long long LL;

LL dp[66000];
LL sum[66000];
int a[20][20];
int n;

int main() {
    cin>>n;
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++) scanf("%d", &a[i][j]);
    for (int i=0;i<(1<<n);i++) {
        sum[i]=0;
        for (int j=0;j<n;j++)
            if (i&(1<<j))
                for (int k=j+1;k<n;k++)
                    if (i&(1<<k)) sum[i]+=a[j][k];
    }
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for (int i=0;i<(1<<n);i++) {
        int superset=(1<<n)-1-i;
        for (int j=superset;j>0;j=(j-1)&superset)
            dp[i+j]=max(dp[i+j], dp[i]+sum[j]);
    }
    cout<<dp[(1<<n)-1]<<endl;
}

Measured memory_bytes: 1280
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] h = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

        int ans = 0;
        for (int i = 1; i <= 100; i++)
        {
            bool flag = false;
            for (int j = 0; j < n; j++)
            {
                if (!flag && h[j] >= i) flag = !flag;
                if (flag && (h[j] < i || j == n - 1))
                {
                    flag = !flag;
                    ans++;
                }
            }
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
input = gets.split
a = input[0].to_i
b = input[1].to_i
c = input[2].to_i
d = input[3].to_i
cd = c.lcm d
print(b - a+ 1- b / c+ (a - 1) / c- b / d+ (a - 1) / d+ b / cd- (a - 1) / cd)

Measured memory_bytes: 1916
#include <iostream>
using namespace std;
int main(void){
        int p[4] = {6000,4000,3000,2000};
        int t,n;
        for(int i = 0 ; i < 4 ; i++){
            cin >> t >> n;
            cout << p[t-1]*n <<endl;
        }
    return 0;
    }


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e18
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  printf("%d %d %lf\n", a / b, a % b, a / 1.0 / b);

  return 0;
}



Measured memory_bytes: 3224
rs c [] [] x = x
rs c a b x =
  if c > length a
  then rs c b [] (x++a)
  else rs c b (drop c a) (x++(take c a))

rshuf [] x = x
rshuf (c:cs) x =
  let l = length x
      n = (l `div` 2)
      f = drop n x
      b = take n x
      r = rs c f b []
  in
    rshuf cs r
    
ans [] = []
ans ((n:_):cs:xs) =
  let s = last $ rshuf cs [0..(n-1)]
  in 
    s:(ans xs)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ print o

Measured memory_bytes: 4812
import io.StdIn.{readInt, readLine}
object Main extends App {
  val k = readInt
  
  if (k%2 == 0 || k%5 == 0) println("-1")
  else {

    var target = k
    var determined_digit = 0
    while (target != 0) {
      
      if (target%10==7) {
        while (target%10 == 7) {
          target = target/10
          determined_digit += 1
        }
      } else {
        while (target%10 != 7) {
          target = target + k
        }
      }

    }

    val result = determined_digit
    println(result)

  }
}

Measured memory_bytes: 54600
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

h, w, k = nm()
c = [[c for c in input()] for _ in range(h)]
ans = 0

for i in range(1 << h):
    for j in range(1 << w):
        black = 0
        check_h = []
        check_w = []
        now_i = i
        now_j = j
        for row in range(h):
            is_delete_i = now_i % 2
            check_h.append(is_delete_i)
            now_i = now_i >> 1
        for col in range(w):
            is_delete_j = now_j % 2
            check_w.append(is_delete_j)
            now_j = now_j >> 1
        for row in range(h):
            for col in range(w):
                if not(check_h[row] == 1 or check_w[col] == 1) and c[row][col] == "#":
                    black += 1
        if black == k:
            ans += 1

print(ans)

Measured memory_bytes: 9256
//F
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int n;
	scanf("%d", &n);
	vector<int> v[n + 1];
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (x > y) swap(x, y);
		v[y].pb(x);
	}
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += (LL)i * (LL)(n - i + 1);
	}
	for (int i = 1; i <= n; i++) {
		int l1 = v[i].size();
		for (int j = 0; j < l1; j++) {
			LL kiri = v[i][j], kanan = n - i + 1;
			if (j > 0) kiri -= v[i][j - 1];
			ans -= kiri * kanan * (LL)(l1 - j);
		}
	}
	printf("%lld\n", ans);
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int N;
int bit[maxn];
void inc(int i) {
    while (i<=N) {
	bit[i]++;
	i+=i&-i;
    }
}
int get(int i) {
    int res=0;
    while (i) {
	res+=bit[i];
	i-=i&-i;
    }
    return res;
}

int n;
ll k;
ll a[maxn];

ll ans;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>k;
    for (int i=0; i<n; i++) {
	cin>>a[i];
	a[i]-=k;
    }
    vector<ll> pref={0};
    for (int i=0; i<n; i++) {
	pref.push_back(pref.back()+a[i]);
    }

    pref.push_back(-2e18);
    sort(pref.begin(),pref.end());
    pref.erase(unique(pref.begin(),pref.end()),pref.end());
    N=pref.size();

    inc(lower_bound(pref.begin(),pref.end(),0)-pref.begin());
    ll acc=0;
    for (int i=0; i<n; i++) {
	acc+=a[i];
	int id=lower_bound(pref.begin(),pref.end(),acc)-pref.begin();
	ans += get(id);
	inc(id);
	//watch(ans);
    }
    cout<<ans<<endl;
  

    return 0;
}


Measured memory_bytes: 7664
// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	N := sc.nextInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N-1; i++ {
		A[i] = sc.nextInt()
		B[A[i]-1]++
	}

	for _, b := range B {
		fmt.Println(b)
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 7288
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define alf(i) for (char i = 'a';i < 'z'; ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll a, b;
  cin >> a >> b;
  ll now = 1;
  ll ans = 0;
  while(now < b)
  {
    now += (a - 1);
    ans++;
  }
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
using ll = long long int;

const int C_NUM = 26;
const int D_MAX = 366;
int D;
int c[C_NUM+5];
int s[D_MAX][C_NUM+5];

int t[D_MAX];
int last[C_NUM+5];

int main(){
    cin >> D;
    for(int i = 1; i <= C_NUM; i++)cin >> c[i];
    for(int i = 1; i <= D; i++){
        for(int j = 1; j <= C_NUM; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 1; i <= D; i++){
        cin >> t[i];
    }
    memset(last, 0, sizeof(last));
    ll v = 0;
    for(int i = 1; i <= D; i++){
        v += s[i][t[i]];
        last[t[i]] = i;
        for(int j = 1; j <= C_NUM; j++){
            v -= c[j] * (i - last[j]);
        }
        cout << v << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  ll n;cin>>n;
  string s = "";

  while(n){
    n -= 1;
    s = (char)('a' + ((n) % 26)) + s;
    n /= 26;
  }

  print(s);
  return 0;
}


Measured memory_bytes: 3508
// https://atcoder.jp/contests/abc124/tasks/abc124_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int A, B, score = 0;
  cin >> A >> B;

  REP(i, 2)
  {
    if (A < B)
    {
      score += B;
      B--;
    }
    else
    {
      score += A;
      A--;
    }
  }

  cout << score << '\n';

  return 0;
}


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

using namespace std;


int main(void){

    long long n, t;
    cin >> n >> t;
    
    vector<int> t_i(n);
    for(int i=0; i<n; i++) cin >> t_i[i];
    
    long long result = 0;
    for(int i=0; i<n-1; i++) {
        if(t_i[i+1]-t_i[i]<t) result += t_i[i+1]-t_i[i];
        else result += t;
    }
    result += t;

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 1024
x,y = map(int, input().split())

crain = (4*x-y)/2
tar = -1*(2*x-y)/2

#print(crain)
#print(tar)

if (crain.is_integer() and crain > 0 and crain <= x) or (tar.is_integer() and tar > 0 and tar <= x):
#if (crain.is_integer() and crain > 0):
    print("Yes")
else:
    print("No")
    
    


Measured memory_bytes: 61888
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ.Volume0
{
    public class EnglishSentence
    {
        public static void Main()
        {
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) { break; }
                var input = line.Split(' ');

                var counter = new Dictionary<string, int>();
                string max_length = "";
                foreach (var w in input)
                {
                    if (counter.ContainsKey(w)) { counter[w]++; }
                    else { counter.Add(w, 1); }
                    if (w.Length > max_length.Length) { max_length = w; }
                }
                int max = counter.Max(x => x.Value);
                string max_count = counter.First(x => x.Value == max).Key;

                Console.WriteLine(max_count + " " + max_length);
            }
        }
    }
}

Measured memory_bytes: 9300
#include <cstdio>
#include <cstdlib> 
#include <queue>
#include <algorithm> 
using namespace std;
#define N 100005
struct rec{
	int x,y;
	rec(int _,int __):x(_),y(__){}
	bool operator < (const rec &rhs) const{
		return y > rhs.y;
	}
};
priority_queue<rec> q;
int k,vis[N]={0};

int main()
{
	scanf("%d",&k);
	q.push(rec(1,1));
	for (;!q.empty();){
		int num = q.top().x;
		int val = q.top().y;
		q.pop();
		if (vis[num]) continue;
		vis[num] = 1;
		if (num==0){
			printf("%d",val);
			break;
		}
		q.push(rec(num*10%k,val));
		q.push(rec((num+1)%k,val+1));
	}
	return 0;
}

Measured memory_bytes: 4104
//IOI 2021

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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

ll n, ans;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	ans = n - 1;
	for (ll i = 2; i * i <= n; i++)
		if (n % i == 0)
			ans = min(ans, i + (n / i) - 2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

string s;
int a, b, c, d, x;

int main()
{
	cin >> s;
	int ans = 0;

	for (int i = 0;i < 4;i++) {
		if (s[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = Long.parseLong(sc.next());
        long count = 1;
        int i = 1;
        while(H > 1) {
            H /= 2;
            count += Math.pow(2, i);
            i++;
        }
        System.out.println(count);
    }
}

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

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define count_one(a) __builtin_popcount(a)  // Returns the number of set bits(1) in a number(a). In long long use __builtin_popcountll(a)
#define parity(i)   __builtin_parity(i)  //even parity 0 and odd parity 1
#define blz(a)   __builtin_clz(a) //Returns the number of leading zeroes in a number(a)
#define btz(a)   __builtin_ctz(a) //Returns the number of trailing zeroes in a number(a)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main()
{
     IOS
     ll n,a;
     cin>>n;
     if(n<500)
     {
          a = n/5;
          cout<<a*5<<endl;
     }
     else
     {
          a= n%500;
          cout<<(n/500)*1000+(a/5)*5<<endl;
     }
     return 0;
}



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

int main()
{
  int N,M,s,c,ans,p;
  p=0;
  ans=0;
  cin >> N >> M;
  map<int,int> X;
 
   
  auto iter =X.find(0);
  
  for(int i=0;i<M;i++)
  {
    cin >> s >> c;
    if(s==1&&N>1&&c==0)
    {
      ans=1;
    }
    if(X.count(s))
    {
      iter=X.find(s);
      if(iter->second!=c)
      {
        ans=1;
      }
    }
    X[s]=c;
  }

  
  
  if(ans==1)
  {
    cout << -1;
  }
  else if(N==1)
  {
    if(X.count(1))
    {
      iter=X.find(1);
      cout << iter->second;
    }else
    {
      cout << 0<<endl;
    }
    
  }
  else if(N==2)
  {
    if(X.count(1))
    {
      iter=X.find(1);
      p=iter->second;
      p=p*10;
    }else
    {
      p=10;
    }
    if(X.count(2))
    {
      iter=X.find(2);
      p=p+iter->second;
    }
    
    cout << p;
  }
  else if(N==3)
  {
     if(X.count(1))
    {
      iter=X.find(1);
      p=iter->second;
      p=p*10;
    }else
    {
      p=10;
    }
    if(X.count(2))
    {
      iter=X.find(2);
      p=p+iter->second;
      p=p*10;
    }else
    {
      p=p*10;
    }
    if(X.count(3))
    {
     iter=X.find(3);
      p=p+iter->second;
      cout << p << endl;
    }else
    {
      cout << p <<endl;
    }
    
  }
  
  
  
  
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100005
#define NIL -1
// 親名と子の一番左と自分と同じ高さの右のデータ
typedef struct {int p, l, r;} Node;

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i,c;
    // ノード番号出力
    printf("node %d: ",u);
    // 親番号の出力
    printf("parent = %d, ",T[u].p);
    // 自分の深さ出力
    printf("depth = %d, ",D[u]);

    // もし親がいなかったら根になる
    if( T[u].p == NIL ) printf("root, ");
    // もし子がいなかったら葉になる
    else if( T[u].l == NIL ) printf("leaf, ");
    // 上の二つに合わなかったら節点になる
    else printf("internal node, ");

    printf("[");
    // .lから順番に右に行くことで子を全部出力することができる
    for(i=0, c=T[u].l; c != NIL; i++, c=T[c].r) {
        if(i) printf(", ");
        printf("%d",c);
    }
    printf("]\n");
}

void rec(int u, int p) {
    // 各ノードの深さを記憶する
    D[u] = p;
    // 右側にノードがあったらそっちに行く
    if(T[u].r != NIL) rec(T[u].r,p);
    // 子がいたらそっちに行く
    if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void) {
    int i,j,d,v,c,l,r;
    // ノードが何個あるか取得
    scanf("%d",&n);
    // ノードの個数分のデータ用意
    for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
    for(i=0;i<n;i++) {
        // 親データと何個の子データがあるか取得
        scanf("%d %d",&v,&d);
        for(j=0;j<d;j++) {
            // 子データを取得する
            scanf("%d",&c);
            // 一個目は必ず左のデータになる
            if(j==0) T[v].l=c;
            // 二個目以降は必ず前回のデータの右データになる
            else T[l].r =c;
            // 次のデータのために記憶
            l = c;
            // 親データを入力
            T[c].p = v;
        }
    }
    for(i=0;i<n;i++) {
        // 親データがなかった場合そこが根となるため番号を記憶
        if(T[i].p == NIL) r = i;
    }
    // 再起関数にぶち込む
    rec(r,0);
    // 出力
    for(i=0;i<n;i++) print(i);

    return 0;
}


Measured memory_bytes: 6540
#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define N 500009
#define inf 999999999999
#define pb push_back
#define M (L+R)/2
using namespace std;

ll n,a[N],b[N],c[N];

bool check(ll x){

	for(int i=1;i<2*n;i++){
		if(a[i]<x)c[i]=0;
		else c[i]=1;
	}

	ll left=0,right=0;
	int j=n;
	while(j>1 && c[j]!=c[j-1]){
		j--;
		left++;
	}
	j=n;
	while(j<2*n-1 && c[j]!=c[j+1]){
		j++;
		right++;
	}	

	if(left>right)left=right;
	if(left%2==0){
		if(c[n]==1)return true;
		else return false;
	} else {
		if(c[n]==1)return false;
		else return true;
	}
}

int main(){

	ios::sync_with_stdio(0);

	cin>>n;
	for(int i=1;i<2*n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	
	sort(b+1,b+2*n);
	
	ll L=1,R=2*n-1,pas=0;
	
	while(L<=R){
		
		if(check(M)){
			pas=M;
			L=M+1;
		} else {
			R=M-1;
		}
		
	}
	
	cout<<pas<<endl;
	
	return 0;
}


Measured memory_bytes: 9984
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	string s;
	cin>>s;
	const int n=s.size();
	int m=n;
	int t=0;
	vector<int> rm(n);
	for(int i=0;i<n;){
		if(s[i]=='1'){
			i+=2;
			continue;
		}
		rm[i]=1;
		++i;
		--m;
		++t;
	}
	ll re=0;
	int cnt=0;
	rep(i,n){
		if(s[i]=='1'){
			if(i%2==0) re+=(cnt+1)/2;
			else re+=cnt/2;
		}
		if(rm[i]){
			++cnt;
			continue;
		}
		if(s[i]=='1' && (i-cnt)%2==0) re+=n-(i-cnt)-cnt;
	}
	// out(rm,m,1);
	// for(;m;--m) re+=(m+1)/2;
	cout<<re NL;
  return 0;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main(){
	cin.tie(0); ios::sync_with_stdio(0);
	
	int n;
	cin >> n;
	int x, y;
	vector< pair<double, pair <ll, ll>>> pt(n);
	
	for(int i = 0; i< n; i++){
		cin >> x >> y;
		double ang = 0;
		if(x == 0 && y == 0) ang = 0;
		else ang = atan2(x, y);
		pt[i] = {ang, {x, y}};
	}
	sort(pt.begin(), pt.end());
	double ans = 0;
	
	/*
	for(int i = 0; i< n; i++){
		cout << pt[i].first << " " << pt[i].second.first << " " << pt[i].second.second << endl;
	}
	/**/
	
	for(int i = 0; i < 2*n; i++){
		ll sumx = 0, sumy = 0;
		for(int j = i; j < i + n; j++){
			sumx += pt[j%n].second.first;
			sumy += pt[j%n].second.second;
			ans = max(ans, sqrt(sumx * sumx + sumy * sumy));
		}
	}
	
	printf("%.20f\n", ans);
	/**/
	/**/
}

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

int abss(int x)
{
    if (x < 0)
        return -x;
    else
        return x;
}

int main()
{
    int n, kmax, a[100010];

    std::cin >> n >> kmax;

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

    int dp[100010];
    dp[1] = 0;

    for (int i = 2; i <= n; ++i)
    {
        dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
        for (int j = 1; i - j >= 1 && j <= kmax; ++j)
            dp[i] = std::min(dp[i], dp[i - j] + abss(a[i] - a[i - j]));
    }

    std::cout << dp[n];
}


Measured memory_bytes: 1024
import java.io.*;
public class Main{
	private static int bubble(int a[]){
		int count=0;
		for(int i = 0 ; i < a.length-1 ; i++){
			for(int j = a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int temp=a[j];
					a[j]=a[j-1];
					a[j-1]=temp;
					count++;
				}
			}
		}
		return count;
	}
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] strdata = new String[n];
		String str = br.readLine();
		strdata = str.split(" ");
		int[] data = new int[n];
		for(int i = 0 ; i < n ; i ++)
			data[i] = Integer.parseInt(strdata[i]);
		int count = bubble(data);
		for(int i = 0 ; i < n-1; i++){
			System.out.print(data[i]+" ");
		}
		System.out.println(data[n-1]);
		System.out.println(count);
	}
}

Measured memory_bytes: 17064
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
# visual studio code shortcut https://qiita.com/TakahiRoyte/items/cdab6fca64da386a690b
# delete line: Ctrl+Shift+k
# choose same words: Ctrl+Shift+l
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

from itertools import combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from math import factorial
def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)
# set the inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
    # R = lambda: map(int, input().split()) :it's fashionable, isn't it?
    # ex1) n, k = R()
    # ex2) v = list(R())
    # ex3) bc = [list(R()) for i in range(m)]

# n = 3
# ab = [[1, 3],[2, 3]]
# c = [1, 2, 3]
# c.sort(reverse=True)

R = lambda: list(map(int, input().split()))
n = int(input())
ab = [R() for i in range(n-1)]
c = R()
c.sort(reverse=True)

# calculate
dic = {}
l = deque()
for a, b in ab:
    dic.setdefault(a, []).append(b)
    dic.setdefault(b, []).append(a)

m = sum(c) - max(c)
d = [-1] * n
l.extend(dic[1])
d[0] = c[0]
i = 1
while l:
    deq = l.popleft()
    if d[deq-1] >= 0:
        pass
    else:
        if deq in dic:
            l.extend(dic[deq])
        d[deq-1] = c[i]
        i += 1
print(m)
print(*d)



Measured memory_bytes: 9604
n, m = map(int, input().split())

adj = [[] for i in range(n)]

for i in range(m):
    s, t = map(int, input().split())
    adj[s].append(t)
    adj[t].append(s)

groups = [None] * n


def dfs(u, group_num):
    path = []
    path.append(u)
    groups[u] = group_num
    while path:
        u = path[-1]
        if adj[u]:
            v = adj[u].pop(0)
            if not groups[v]:
                groups[v] = group_num
                path.append(v)
        else:
            path.pop()


g_n = 1
for i in range(n):
    if not groups[i]:
        dfs(i, g_n)
        g_n += 1

def isConnected(v1, v2):
    if groups[v1] == groups[v2]:
        print('yes')
    else:
        print('no')


q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    isConnected(s, t)

Measured memory_bytes: 27244
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}

import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Data.Array
import Control.Monad

main = do
  li <- BS.getLine
  let [n,q] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  abs <- forM [2..n] get2
  pxs <- forM [1..q] get2
  let ans = compute n q abs pxs
  putStrLn $ unwords $ map show ans

get2 _ = do
  li <- BS.getLine
  let [a,b] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  return (a,b)

compute :: Int -> Int -> [(Int,Int)] -> [(Int,Int)] -> [Int]
compute n _ abs pxs = ans
  where
    xa = accumArray (+) 0 (1,n) pxs
    ta = accumArray (flip (:)) [] (1,n) [ p | (a,b) <- abs, p <- [(a,b),(b,a)] ]
    ans = elems $ array (1,n) $ dft 0 0 1 []
    dft p v cur rest = (cur, v1) : foldr (dft cur v1) rest (delete p $ ta ! cur)
      where
        v1 = v + xa ! cur

Measured memory_bytes: 136800