akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
 
const int MAX_DIGIT = 50;
long long dp[100][2]; // dp[上から i 桁まで][ smaller ]
 
int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    memset(dp, -1, sizeof(dp)); // DP 配列を -1 で初期化
    dp[0][0] = 0; // 初期条件
    for (int d = 0; d < MAX_DIGIT; ++d) {
        long long mask = 1LL<<(MAX_DIGIT - d - 1);
        
        // A で元々 d 桁目にビットが立っているものの個数
        int num = 0;
        for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;
        
        // X の d 桁目を 0, 1 にしたときのコスト
        long long cost0 = mask * num;
        long long cost1 = mask * (N - num);
        
        // smaller -> smaller
        if (dp[d][1] != -1) {
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1)); // 0 でも 1 でも自在に大きい方
        }
        
        // exact -> smaller
        if (dp[d][0] != -1) {
            if (K & mask) { // K の d 桁目が 1 だったら、X の d 桁目は 0 にする
                chmax(dp[d+1][1], dp[d][0] + cost0);
            }
        }
        
        // exact -> exact (K にぴったり合わせる)
        if (dp[d][0] != -1) {
            if (K & mask) chmax(dp[d+1][0], dp[d][0] + cost1);
            else chmax(dp[d+1][0], dp[d][0] + cost0);
        }
    }
    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

class UnionFind {
  private:
    std::vector<int> par;
    std::vector<int> sizes;
    std::vector<int> rank;
    int group;

  public:
    UnionFind(int n) : par(n), sizes(n, 1), rank(n, 0), group(n) {
      for(int i = 0; i < n; ++i) par[i] = i;
    }

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

    void unite(int x, int y) {
      x = find(x);
      y = find(y);

      if(x == y) return;

      if(rank[x] < rank[y]) std::swap(x, y);
      par[y] = x;
      sizes[x] += sizes[y];
      if(rank[x] == rank[y]) rank[x]++;
      group--;
    }

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

    int size(int x) {
      return sizes[find(x)];
    }

    int groupSize() {
      return group;
    }
};

class Kruskal {
  struct Edge {
    int x, y, cost;

    Edge(int x, int y, int cost) : x(x), y(y), cost(cost) {}

    bool operator<(const Edge &e) const {
      return cost < e.cost;
    }
  };

  private:
    int n;
    std::vector<Edge> edge;

  public:
    Kruskal(int n) : n(n) {}

    void add(int x, int y, int cost) {
      edge.emplace_back(x, y, cost);
    }

    int kruskal() {
      std::sort(edge.begin(), edge.end());

      UnionFind uf(n);
      int res = 0;

      for(int i = 0; i < edge.size(); ++i) {
        if(!uf.same(edge[i].x, edge[i].y)) {
          res += edge[i].cost;
          uf.unite(edge[i].x, edge[i].y);
        }
      }
      return res;
    }
};

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

  int v, e;
  cin >> v >> e;
  Kruskal ks(v);
  rep(i, 0, e) {
    int s, t, w;
    cin >> s >> t >> w;
    ks.add(s, t, w);
  }
  cout << ks.kruskal() << endl;
}


Measured memory_bytes: 4540
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	int N,M,i;
	cin>>N>>M;
	int p,p0=0;
	string S;
	int succ=0;
	int err=0;
	vector<bool> OK(N+1,false);
	vector<int> Error(N+1,0);
	for (i=0;i<M;i++){
		cin>>p;
		cin>>S;
		if (!S.compare("WA")){
			if (OK[p]==false){
				Error[p]++;
			}
		}else{
			if (OK[p]==false){
				succ++;
				OK[p]=true;
			}
		}
	}
	for (p=1;p<=N;p++){
		if (OK[p]==true){
			err+=Error[p];
		}
	}
	cout<<succ<<" "<<err<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	
      	long total = 1L;
      	for(int i = 1; i <= N; i++){
        	total = (total * i) % 1000000007;
        }
      	System.out.println(total);
    }
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<double> p(n+1);
    rep(i,n) cin >> p[i+1];
    vector<vector<double>> dp(n+1, vector<double>(n+1));
    dp[0][0] = 1;
    rep(i, 1, n+1) rep(j, 0, i+1) {
        if(j == 0) dp[i][j] = dp[i-1][j] * (1-p[i]);
        else dp[i][j] = dp[i-1][j] * (1-p[i]) + dp[i-1][j-1] * p[i];
    }
    double ans = 0;
    rep(j, (n+1)/2, n+1) {
        ans += dp[n][j];
    }
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 73784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    public class Code20171210C
    {
        static void Main(string[] args)
        {
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();

            Console.WriteLine(funcMain(s1,s2));
        }

        static public string funcMain(string arg1, string arg2)
        {
            int ret=0;
            int tKind = int.Parse(arg1.Split().LastOrDefault());
            int cKind = arg2.Split().Distinct().Count();
            int ChgCnt = cKind - tKind;

            if(ChgCnt > 0) {
                var q = arg2.Split().GroupBy(g => g)
                        .Select(s => new { val = s, cnt = s.Count() })
                        .OrderBy(o => o.cnt);
                ret = q.Take(ChgCnt).Sum(s=>s.cnt);                     
            }
            
            return ret.ToString();
        }
    }
}

Measured memory_bytes: 64384
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
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; }
//-------------------
int n;
const int MX = 25;
int h[MX];

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


Measured memory_bytes: 256
#include<iostream> 
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int *arr=new int[m];
  int sum=0;
  for(int i=0; i<m; ++i)
  {
    cin>>arr[i];
    sum=sum+arr[i];
  }
  if(sum>n)
    cout<<"-1"<<endl;
  else
    cout<<n-sum<<endl;
  return 0;
}
  

Measured memory_bytes: 3648
#include <iostream>
#include <queue>

using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    vector<queue<int>>A(n);
    while(q--)
    {
        int act,t,x;
        cin>>act;
        if(act==0)
        {
            cin>>t>>x;
            A[t].push(x);
        }
        else if(act==1)
        {
            cin>>t;
            if(A[t].size()>0)
            {
                cout<<A[t].front()<<'\n';
            }
        }
        else{
            cin>>t;
            if(!A[t].empty())
            {
                A[t].pop();
            }
        }
    }
    return 0;
}



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

int main()
{
    int N, K;
    cin >> N >> K;
    int X[N];
    rep(i, N) cin >> X[i];
    int cost = 0;
    rep(i, N) {
        int costA = X[i];
        int costB = abs(X[i] - K);
        cost += min(costA, costB) * 2;
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
void chmin(ll &x, ll y) { x = min(x, y); }
void chmax(ll &x, ll y) { x = max(x, y); }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    ll a, b;
    cin >> a >> b;
    vector<ll> v(n), d(n-1);
    rep(i, n) cin >> v[i];
    for(int i=0; i<n-1; i++) d[i] = v[i+1] - v[i];

    ll ans = 0;
    rep(i, d.size()){
        if(d[i]*a < b) ans += d[i]*a;
        else ans += b;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
MAX=10**18
_n = gets.to_i
nums = gets.strip.split.map(&:to_i)

r = if nums.any?{|n| n == 0}
      0
    elsif nums.any?{|n| n > MAX}
      -1
    else
      1
    end

if r != 0 && r != -1
  nums.each do |n|
    r *= n
    if r >MAX
      r = -1
      break
    end
  end
end
p r


Measured memory_bytes: 23612
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int64_t n;
int64_t ans = 1e18;


int64_t ex_gcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
    x = 1, y = 0;
    int64_t x1 = 0, y1 = 1, a1 = a, b1 = b;
    while (b1) {
        int64_t q = a1 / b1;
        tie(x, x1) = make_tuple(x1, x - q * x1);
        tie(y, y1) = make_tuple(y1, y - q * y1);
        tie(a1, b1) = make_tuple(b1, a1 - q * b1);
    }
    return a1;
}


void brute(int64_t x, int64_t y) {
    int64_t foo, bar;
    if (ex_gcd(x, y, foo, bar) != 1) return ;
    int64_t real_foo = foo * x;
    int64_t real_bar = -y * bar;
    if (real_bar > 0) ans = min(ans, real_bar);
    else {
        int64_t need = 1 - real_bar;
        int64_t add = (need + n - 1) / n;
        real_bar += add * n;
        ans = min(ans, real_bar);
    }
}

int main() {

    cin >> n;
    n <<= 1;

    for (int64_t i = 1 ; i * i <= n ; ++ i)
        if (n % i == 0) brute(i, n / i), brute(n / i, i);

    cout << ans << '\n';
}
/*
    Why not Ventuswill?
*/


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int a[8][8]={{1,2,1,2,1,4,1,4},{1,2,1,4,1,4,1,2},{1,4,1,2,1,2,1,4},{1,4,1,4,1,2,1,2},{2,1,2,1,4,1,4,1},{2,1,4,1,4,1,2,1},{4,1,2,1,2,1,4,1},{4,1,4,1,2,1,2,1}};
int p[8],t[8];
int cal(int n)
{
	int sum=0;
	for(int i=0;i<8;i++)
	{
		if(a[n][i]>=p[i])continue;
		sum+=p[i]-a[n][i];
	}
	return sum;
}
int main()
{
	while(scanf("%d %d %d %d %d %d %d %d",&p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6],&p[7])!=EOF)
	{
		int i,mi=INF;
		for(i=0;i<8;i++)
		{
			t[i]=cal(i);
			mi=min(mi,t[i]);
		}
		for(i=0;i<8;i++)
		{
			if(mi==t[i])break;
		}
		for(int j=0;j<8;j++)
		{
			if(j!=7)
			{
				cout << a[i][j] << ' ';
			}
			else
			{
				cout << a[i][j] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1208
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int K = int.Parse(str[0]);
            int X = int.Parse(str[1]);

            int sum = 500 * K;
            string ans;
            if (sum < X) ans = "No";
            else ans = "Yes";

            Console.WriteLine(ans);
        }
       
    }
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = long.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();

string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
 */
/*
      static long func(long n)
      {
          long d = 0;
          for (long i = 0; i < 10; i++)
          {
              if (n / longPow(10, i) == 0)
              {
                  d = i;
                  break;
              }
          }
          long ret = A * n + B * d;
          return ret;
      }
      static long longPow(long a, long n)
      {
          long b = 1;
          for (long i = 0; i < n; i++) b = b * a;
          return b;
      }
      */


Measured memory_bytes: 13012
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
#include<string_view>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
void a(){
   ll H,W,A,B; cin >> H >> W >> A >> B;
   v<string> s(H,string(W,'0'));
   rep(i,H) {
       rep(j,W){
            if((i<B&&j<A)||(B<=i&&i<H&&A<=j&&j<W)){
                cout << '1';
            }else{
                cout << '0';
            }
        }
        cout<<endl;
   }


}
int main(void){
    a();
    return 0;
 }

Measured memory_bytes: 4564
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <set>

using namespace std;

#define ERROR_ID		0

#define PROCESS_ERROR(Condition)    \
{                                   \
		if (!(Condition))           \
		{                           \
			goto Exit0;             \
		}                           \
}

typedef unsigned char			BYTE;
typedef int						BOOL;
typedef unsigned long			DWORD;
typedef long long				LLONG;

inline int read() {
	int ret = 0, f = 1;
	char ch = getchar();
	while (ch<'0' || ch>'9') {
		if (ch == '-') f = -f;
		ch = getchar();
	}
	while (ch >= '0'&&ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
	return ret * f;
}//快读优化

int			g_nNumberArrays[100010];

int main(int argc, char* argv[])
{
	int			nNumberCount;
	int			nCount;

	cin >> nNumberCount;

	for (int i = 1; i <= nNumberCount; i++)
	{
		cin >> g_nNumberArrays[i];
	}
	sort(g_nNumberArrays + 1, g_nNumberArrays + 1 + nNumberCount);

	for (int i = 2; i <= nNumberCount; i++)
	{
		if (g_nNumberArrays[i] == g_nNumberArrays[i - 1])
		{
			nCount++;
		}
	}

	if (nCount & 1)
	{
		nCount++;
	}
	cout << nNumberCount - nCount << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  ll ans = 1;
  for (int i = 0; i < N; i++) {
    ll A;
    cin >> A;
    if (A == 0) {
      ans = 0;
    } else if (ans <= (ll)1e18 / A && ans > 0) {
      ans *= A;
    } else if (ans > 0) {
      ans = -1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
N = int(input())
A = list(map(int, input().split()))
abs_A = [abs(i) for i in A]

minus = 0
for i in range(N):
    minus += A[i] < 0

if minus % 2 == 0:
    print(sum(abs_A))
else:
    mini = float('inf')
    for i in range(N):
        mini = min(mini, abs_A[i])
    print(sum(abs_A) - 2*mini)

Measured memory_bytes: 20132
#define MST(a, b) memset(a,b,sizeof(a))

#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;

#include <ext/pb_ds/priority_queue.hpp>

using namespace __gnu_pbds;
typedef __gnu_pbds::priority_queue<pii, greater<>, pairing_heap_tag> heap;
typedef heap::point_iterator iter;
typedef long long LL;
typedef long long LL;
typedef unsigned long long ULL;

void init_all(int t = 0) {
    if (t & 1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
#ifdef LOCAL
    if ((t >> 1) & 1) freopen("input", "r", stdin);
    if ((t >> 2) & 1) freopen("output", "w", stdout);
#endif
}

namespace solver {
    const int N = 50 + 19;
    LL f[N];
    int n, m, fa[N], dep[N], val[N], x[N], y[N], z[N];
    vector<int> e[N];

    void dfs(int u, int p) {
        for (auto v : e[u])
            if (v != p) {
                dep[v] = dep[u] + 1;
                fa[v] = u;
                dfs(v, u);
            }
    }

    int lca(int u, int v) {
        if (dep[u] < dep[v]) swap(u, v);
        while (dep[u] > dep[v]) u = fa[u];
        while (u != v) {
            u = fa[u];
            v = fa[v];
        }
        return u;
    }

    void get_color(int u, int p) {
        for (auto v : e[u])
            if (v != p) {
                get_color(v, u);
                val[u] += val[v];
            }
    }

    void work(int mask) {
        int num = 0;
        for (int i = 1; i <= n; ++i) val[i] = 0;
        for (int i = 0; i < m; ++i) {
            if ((mask >> i) & 1) {
                ++num;
                ++val[x[i]];
                ++val[y[i]];
                val[z[i]] -= 2;
            }
        }
        get_color(1, 0);
        int tot = 0;
        for (int i = 2; i <= n; ++i)
            if (!val[i])
                ++tot;
        f[num] += (1ll << tot);
    }

    void solve() {
        init_all(3);

        cin >> n;
        for (int i = 1; i < n; ++i) {
            int u, v;
            cin >> u >> v;
            e[u].push_back(v);
            e[v].push_back(u);
        }

        dep[1] = 0;
        dfs(1, 0);

        cin >> m;

        for (int i = 0; i < m; ++i) {
            cin >> x[i] >> y[i];
            z[i] = lca(x[i], y[i]);
        }

        for (int i = 0; i < (1 << m); ++i)
            work(i);
        LL ans = 0;
        for (int i = 0; i <= m; ++i)
            ans += ((i & 1) ? -1 : 1) * f[i];
        cout << ans << endl;
    }
}



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

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int C = sc.nextInt();
        int[][] D = new int[C][C];
        //int[][] c = new int[N][N];
        int[] remain0 = new int[C];
        int[] remain1 = new int[C];
        int[] remain2 = new int[C];
        for(int row=0;row<C;row++){
            for(int col=0;col<C;col++){
                D[row][col] = sc.nextInt();
            }
        }
        // /*记得从小c去找D时要把小c的值-1*/
        for(int row=0;row<N;row++){
            for(int col=0;col<N;col++){
                int nxt = sc.nextInt()-1;
                //c[row][col] = nxt-1; // 0<=c<=C-1
                if((row+col)%3==0) remain0[nxt]++;
                else if((row+col)%3==1) remain1[nxt]++;
                else remain2[nxt]++;
            }
        }
        long ans = Long.MAX_VALUE;
        for(int i=0;i<C;i++) { // target color for remain0
            for (int j = 0; j < C; j++) { // target color for remain1
                if (j == i) continue;
                for (int k = 0; k < C; k++) { // target color for remain2
                    if (k == i || k == j) continue;
                    //compute remain0
                    long sum0 = 0;
                    for (int r0 = 0; r0 < C; r0++) {
                        sum0 += remain0[r0] * (D[r0][i]);
                    }
                    if (sum0 > ans) continue;
                    //compute remain1
                    long sum1 = 0;
                    for (int r1 = 0; r1 < C; r1++) {
                        sum1 += remain1[r1] * (D[r1][j]);
                    }
                    if (sum1 + sum0 > ans) continue;
                    //compute remain2
                    long sum2 = 0;
                    for (int r2 = 0; r2 < C; r2++) {
                        sum2 += remain2[r2] * (D[r2][k]);
                    }
                    ans = Math.min(ans, sum0 + sum1 + sum2);
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 79508
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        List<Integer> from1 = new ArrayList<>();
        Set<Integer> ton = new HashSet<>();
        for (int i = 0; i < m; i++) {
            if (a[i] == 1) {
                from1.add(b[i]);
            }
            if (b[i] == n) {
                ton.add(a[i]);
            }
        }
        for (Integer island : from1) {
            if (ton.contains(island)) {
                System.out.println("POSSIBLE");
                return;
            }
        }
        System.out.println("IMPOSSIBLE");
    }

}


Measured memory_bytes: 96196
def bubble(A):
    #标记是否需要继续冒泡
    flag =True;
    n=len(A)
    i=0
    while flag:
        flag=False
        for j in range(n-1,i,-1):
           if A[j][1]<A[j-1][1]:
               A[j],A[j-1]=A[j-1],A[j]
               flag=True
        i+=1
 
 
#选择排序法
def selection(A):
    n=len(A)
    for i in range(n):
        minj=i
        for j in range(i,n):
            if A[j][1]<A[minj][1]:
                minj=j
        if i!=minj:
            A[i],A[minj]=A[minj],A[i]
             
   
           
n=int(input())
ss=[x for x in input().split()]     
ss2=ss.copy()
 
 
bubble(ss)
for i in range(len(ss)-1):
    print(ss[i],end=' ')
print(ss[-1])
print('Stable')
    
 
selection(ss2)
for i in range(len(ss2)-1):
    print(ss2[i],end=' ')
print(ss2[-1])
if ss==ss2:
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 5616
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N = int(input().rstrip())
    A,B = map(int, input().split())
    X =list(map(int, input().split())) 
    vec = [0]*3
    for x in X:
        if(x <= A):
            vec[0] += 1
        elif(x <= B):
            vec[1] += 1
        else:
            vec[2] += 1
    

    print(min(vec))
if __name__ == '__main__':
    solve()


Measured memory_bytes: 3940
/**
*    author:  yuya1234
*    created: 10.07.2020 13:31:12
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)

#define SORT(s) sort((s).begin(), (s).end())
#define SORTD(s) sort((s).rbegin(), (s).rend())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  string s;
  cin >> s;

  int ans = INT_MAX - 1, cnt = 0;
  string ss;
  REP(i, 26)
  {
    cnt = 0;
    ss = s;
    for (;;)
    {
      bool flg = true;
      REP(j, SZ(ss) - 1)
      {
        if (ss[j] != ss[j + 1])
          flg = false;
      }
      if (flg)
      {
        ans = min(ans, cnt);
        break;
      }
      else
      {
        string ss1;
        int cnt1;
        cnt1 = 0;
        ss1 = "";
        FOR(j, 0, SZ(ss) - 2)
        {
          if ((ss[j] - 'a') == i || (ss[j + 1] - 'a') == i)
          {
            ss1 += char(i+'a');
            cnt1++;
          }
          else
            ss1 += ss[j];
        }
        if (cnt1 == 0)break;
        ss = ss1;
        cnt++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++) 
#define fr(i,a,b) for(int i=a;i<b;i++) 
#define F first 
#define S second 
#define mp make_pair 
#define pb push_back 
#define ll long long 
using namespace std;

void test(){
	ll n;
	cin>>n;
	ll a[n];
	f(i,n)cin>>a[i];
	ll sum = 0LL;
	f(i,n)sum=sum+ a[i];
	ll avg = sum/n ;
	ll ans = 0LL;
	f(i,n)ans = ans + (avg-a[i])*(avg-a[i]);
	if(sum%n!=0){
		avg++;
		ll ans2 = 0LL;
		f(i,n)ans2 = ans2 + (avg-a[i])*(avg-a[i]);
		ans = min(ans,ans2);
	}
	cout<<ans<<"\n";
}

int main(){
	int t=1;
//	cin>>t;
	while(t--){
		test();
	}
}

Measured memory_bytes: 256
package main

import "fmt"
import "math"

func main() {
	var n int
	fmt.Scan(&n)

	arr := make([]int, n)

	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		arr[i] = a
	}

	var min_cost float64
	min_cost = math.Inf(0)

	for i := 0; i < 100; i++ {
		var cost float64
		for _, x := range arr {
			z := float64(i - x)
			cost = cost + math.Pow(z, 2)
		} 
		if cost < min_cost {
			min_cost = cost
		}
	}

	fmt.Println(min_cost)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10;
vector<int> datas[MAXN];//通道关系
int ans[MAXN];//保存最近的房间号
 
void bfs() {
    queue<int> q;
    q.push(1);
    ans[1] = 1;
 
    while (!q.empty()) {
        int u = q.front();
        q.pop();
 
        for (int i=0;i<datas[u].size();i++) {
        	int v=datas[u][i];
            if (0==ans[v]) {
                q.push(v);
                ans[v] = u;
            }
        }
    }
}
 
int main() {
    int n,m;
    scanf("%d%d", &n, &m);
    for (int i=0; i<m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        datas[u].push_back(v);
        datas[v].push_back(u);
    }
 
    bfs();
 
    //查询
    for (int i=2; i<=n; i++) {
        if (0==ans[i]) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    for (int i=2; i<=n; i++) {
        printf("%d\n", ans[i]);
    }
 
    return 0;
}

Measured memory_bytes: 13044
package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	ans := 0
	x := 0
	for _, v := range s {
		if v == 'I' {
			x++
		} else {
			x--
		}
		if ans < x {
			ans = x
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <cmath>


using namespace std;

//  ||
// \

int main() {
	int n = 0, l = 0;
	cin >> n >> l;
	string tab[n];
	for(int i = 0; i < n; i++) {
		cin >> tab[i];
	}
	for(int j = 0; j < n; j++) {
		for(int i = j+1; i < n; i++) {
			if(tab[j] > tab[i]) {
				swap(tab[j], tab[i]);
			}
		}
	}
	for(int i = 0; i < n; i++) {
		cout << tab[i];
	}

 
    return 0;
}

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
#define fir first
#define sec second

const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n, k;
string S;

int func(char str, int k) {
	char c = str;
	string s(S);

	for (int i = 0; i < s.size(); i++) {
		if (c != s[i]) {
			int t = i;
			int cnt = 0;
			while (t < s.size() && s[t] == s[i]) {
				cnt++;
				t++;
			}

			for (int j = i; j < t; j++)	s[j] = c;
			k--;
			if (k == 0) break;
		}
	}

	int res = 0;
	for (int i = 0; i + 1 < s.size(); i++) {
		if (s[i] == s[i + 1]) res++;
	}

	return res;
}

int main(void){
	cin>>n>>k>>S;

	cout<< max(func('L', k), func('R', k)) <<endl;
	
	return 0;
}

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

using ll = long long;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

ll H, W, V;
ll dy[4] = { 0,  0, -1, +1};
ll dx[4] = {-1, +1,  0,  0};

bool is_ok(std::vector< std::string >& grid)
{
  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      if (grid[y][x] == '.') continue;
      bool was_found = false;
      for (ll d = 0; d < 4; d++) {
	ll ny = y + dy[d];
	ll nx = x + dx[d];
	if (ny >= 0 && nx >= 0 && ny < H && nx < W) {
	  if (grid[ny][nx] == '#') was_found = true;
	}
      }
      if (!was_found) return false;
    }
  }

  return true;
}

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  std::cin >> H >> W;
  std::vector< std::string > grid(H, std::string(W, 'x'));

  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      std::cin >> grid[y][x];
    }
  }

  std::string judge = is_ok(grid) ? "Yes" : "No";
  print(judge);

  return 0;
}


Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0503

from collections import deque

def main():
    N, M = map(int, input().split()) # N: コップの数　M: 最大回数
    if N==0:
        exit()
    data = [0]*N
    map(int, input().split())
    for b in list(map(int, input().split()))[1:]:
        data[N-b]=1
    for c in list(map(int, input().split()))[1:]:
        data[N-c]=2

    next_set = deque([(data[:],0)])
    visit=set([tuple(data)])

    while next_set:
        q = next_set.popleft()
        data, t = q
        l = data[0]

        # M 回より大きい回数かかる場合は-1
        if t > M:
            return -1

        # 全てのコップがA(あるいはC)にいるとき、時刻を返す
        for cnt, k in enumerate(data):
            if k != l:
                break
            if cnt == N-1 and k != 1:
                return t
            l = k

        pos = [N,N,N]
        k = 0
        for i, ABC in enumerate(data):
            if pos[ABC] == N:
                pos[ABC] = i
                k += 1
            if k == 3:
                break

        if pos[0] < pos[1]:
            data[pos[0]] = 1
            t_data = tuple(data)
            if t_data not in visit:
                next_set.append((data[:],t+1))
                visit.add(t_data)
            data[pos[0]] = 0
        else:
            data[pos[1]] = 0
            t_data = tuple(data)
            if t_data not in visit:
                next_set.append((data[:],t+1))
                visit.add(t_data)
            data[pos[1]] = 1

        if pos[1] < pos[2]:
            data[pos[1]] = 2
            t_data = tuple(data)
            if t_data not in visit:
                next_set.append((data[:],t+1))
                visit.add(t_data)
            data[pos[1]] = 1
        else:
            data[pos[2]] = 1
            t_data = tuple(data)
            if t_data not in visit:
                next_set.append((data[:],t+1))
                visit.add(t_data)
            data[pos[2]] = 2


while True:
    print(main())






'''

3 10
0
1 1
2 2 3

'''


Measured memory_bytes: 489220
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

//3281

const int mn = 3334;
//num
ll dp1[101][mn];
//sum
ll dp2[101][mn];
void solve() {
	int n, m; cin >> n >> m;
	dp1[0][0] = 1;
	rep(i, n) {
		int c = n - i;
		rep(j, mn) {
			if (dp1[i][j] == 0)continue;
			rep(k, m + 1) {
				if (k > c) {
					dp1[i + 1][j] += dp1[i][j];
					if (dp1[i + 1][j] >= mod)dp1[i + 1][j] -= mod;
					dp2[i + 1][j] = (dp2[i + 1][j] + dp2[i][j]+dp1[i][j] * k) % mod;
				}
				else {
					int z = j + k;
					int d = z / c;
					dp1[i + 1][d+j] += dp1[i][j];
					if (dp1[i + 1][d + j] >= mod)dp1[i + 1][d + j] -= mod;
					dp2[i + 1][d + j] = (dp2[i + 1][d + j] + dp2[i][j] + dp1[i][j] * k) % mod;
				}
			}
		}
	}
	ll ans = 0;
	rep(i, mn) {
		ll csum = dp2[n][i] - dp1[n][i] * i;
		csum = (csum%mod + mod) % mod;
		ans = (ans + csum) % mod;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 2944
#include <iostream> 
#include <iomanip> 
#include <string> 
#include <math.h> 
 
using namespace std; 
 
int main(){ 
 int a[3]; 
 cin >> a[0] >> a[1] >> a[2]; 
 if (a[0] > a[1]) 
  swap(a[0], a[1]); 
 if (a[1] > a[2]) 
  swap(a[1], a[2]); 
 if (a[0] > a[1]) 
  swap(a[0], a[1]); 
 cout << a[0] << " " << a[1] << " " << a[2] << "\n"; 
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n;
  cin>>n;
  vi a(n),b(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];

  int x=0,y=0;
  int sum=0;
  rep(i,n){
    int t=b[i]-a[i];
    sum+=b[i]-a[i];
    if(t>=0)
      x+=(t+1)/2;
  }
  if(x+y<=sum)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
    int N, X;
    int tempL;
    int D = 0;
    int ans = 1;


    scanf("%d %d", &N, &X);

    for (int i = 0; i < N; i++)
    {
        scanf("%d", &tempL);

        D += tempL;

        if (D <= X)
        {
            ans++;
        } else
        {
            break;
        }
        
    }

    printf("%d", ans);        

    return 0;
}

Measured memory_bytes: 128
/* Stable Sort */

#include <stdio.h>

typedef struct {
    char suit;
    int number;
} Card;

void swap_Card(Card *x, Card *y)
{
    Card temp = *x;
    *x = *y;
    *y = temp;
}

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

    int i;
    Card BC[N];
    Card SC[N];

    for (i = 0; i < N; i++) {
        Card c;
        scanf("%c", &c.suit);
        scanf("%d ", &c.number);
        BC[i] = c;
        SC[i] = c;
    }

    int j;

    /* Bubble Sort */
    for (i = 0; i < N - 1; i++) {
        for (j = N - 1; j > i; j--) {
            if (BC[j].number < BC[j - 1].number)
                swap_Card(&BC[j], &BC[j - 1]);
        }
    }

    /* Selection Sort */
    for (i = 0; i < N - 1; i++) {
        int min_i = i;
        for (j = i + 1; j < N; j++) {
            if (SC[j].number < SC[min_i].number)
                min_i = j;
        }
        swap_Card(&SC[i], &SC[min_i]);
    }

    /* Output */
    for (i = 0; i < N - 1; i++)
        printf("%c%d ", BC[i].suit, BC[i].number);
    printf("%c%d\n", BC[N - 1].suit, BC[N - 1].number);

    puts("Stable");

    for (i = 0; i < N - 1; i++)
        printf("%c%d ", SC[i].suit, SC[i].number);
    printf("%c%d\n", SC[N - 1].suit, SC[N - 1].number);

    for (i = 0; i < N; i++) {
        if (BC[i].suit != SC[i].suit) {
            puts("Not stable");
            return 0;
        }
    }
    puts("Stable");

    return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;  //このネームスペースを使う

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

  if(A%2 ==0){
  	cout << A << endl;
  }
  else{
  	cout << A*2 << endl;
  }
  
  return 0;
}



Measured memory_bytes: 384
#include <stdio.h>


int main(){
  int n,i, ans,res,min,tag;
  scanf("%d",&n);
  scanf("%d",&min);
  scanf("%d", &tag);
    ans = tag - min;
    if (tag < min ) { min = tag;}
  for ( i = 0; i < n-2; i++){
    scanf("%d", &tag);
    res = tag - min;
        if (tag < min ) { min = tag;}
    if ( res > ans){ans = res;}
  }
  printf("%d\n",ans );



  return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s;
	cin >> s;
	
	int wb = 0;
	int bw = 0;
	for(int i = 0; i < s.size(); ++i) {
		if( i % 2 == 0 && s[i] - '0' == 0 ) bw++;
		if( i % 2 == 1 && s[i] - '0' == 1 ) bw++;
		if( i % 2 == 0 && s[i] - '0' == 1 ) wb++;
		if( i % 2 == 1 && s[i] - '0' == 0 ) wb++;
	}
	
	cout << min(bw, wb) << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forna(i,a,n) for(int i =a; i < n; i++)
#define fornd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push
#define fi first
#define se second
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long int unsigned lliu;
typedef long long int lli;
typedef pair<lli,lli> pi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;

int main(){
    int a, b, n;
    cin>>a>>b;
    forn(i, 800005){
        if((i*8)/100 == a && i/10 == b){
            cout<<i<<"\n";
            exit(0);
        }
    }
    cout<<"-1\n";
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc087/tasks/abc087_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x - a) % b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define task "atcoder"
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define BIT(x, i) (((x) >> (i)) & 1)
#define lb lower_bound
#define ub upper_bound
#define lla(v) (v).begin(),(v).end()
#define zs(v) int((v).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ar array
#define endl '\n'
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1000000007; /// 998244353
const int base=311;
const int N=3e5+5;

int cnth[N],cntc[N];
map<pii,int> M;
void solved()
{
    int r,c,m;
    cin>>r>>c>>m;
    int mxc=0,mxh=0;
    for(int i=1;i<=m;++i)
    {
        int x,y;
        cin>>x>>y;
        cnth[x]++;
        cntc[y]++;
        mxc=max(mxc,cntc[y]);
        mxh=max(mxh,cnth[x]);
        M[mp(x,y)]=1;
    }
    vector<int> s;
    for(int i=1;i<=c;++i)
    {
        if(cntc[i]==mxc) s.pb(i);
    }
    sort(lla(s));
    s.resize(unique(lla(s))-s.begin());
    vector<int> q;
    for(int i=1;i<=r;++i)
    {
        if(cnth[i]==mxh) q.pb(i);
    }
    sort(lla(q));
    q.resize(unique(lla(q))-q.begin());
    int ans=0;
    for(int i:q)
        for(int j:s)
            {
                if(M[{i,j}]==0)
                {
                    cout<<cnth[i]+cntc[j];
                    return;
                }
                ans=max(ans,cnth[i]+cntc[j]-M[{i,j}]);
            }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solved();
}










Measured memory_bytes: 28504
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

#define endl "\n"

using namespace std;

double n, x;
int main(){

    cin >> n;
    x = ceil(n/2);

    cout << x/n;



}

//g++ -std=c++14 comp.cpp -o b; ./b.exe


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::setprecision(20) << std::fixed;

  long long N;
  cin >> N;

  long long ans = 0;
  for (long long a = 1; a <= N; a++) {
    ans += (N - 1) / a;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3648
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];
		for(int i=0;i<h;i++){
			s[i] = sc.next();
		}
		int[][] map = new int[h][w];
		int[] dx = {1,1,1,0,-1,-1,-1,0};
		int[] dy = {1,0,-1,-1,-1,0,1,1};
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(s[i].charAt(j)=='#'){
					map[i][j] = -1;
				}
			}
		}

		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]==-1){
					for(int k=0;k<8;k++){
						if(i+dy[k]<0 || i+dy[k]>=h || j+dx[k]<0 || j+dx[k]>=w){
							continue;
						}
						if(map[i+dy[k]][j+dx[k]]!=-1){
							map[i+dy[k]][j+dx[k]]+=1;
						}
					}
				}
			}
		}

		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]==-1){
					System.out.print("#");
				}
				else{
					System.out.print(map[i][j]);
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int n, a[1005], p[1005], c[1005], m;
long long ans = 1;
void siftp(int maxn) {
    a[0] = a[1] = 1;
    for (int i = 2; i < maxn; i++) {
        if (!a[i]) p[m++] = i;
        for (int j = 0; j < m; j++) {
            if (i * p[j] >= maxn) break;
            a[i*p[j]] = 1;
            if (i % p[j] == 0) break;
        }
    }
}
void handle(int x) {
    for (int i = 0; i < m && x > 1; i++) {
        while (x % p[i] == 0) {
            c[i] += 1;
            x /= p[i];
        }
    }
}
int main() {
    siftp(1005);
    scanf("%d", &n);
    for (int i = 2; i <= n; i++)
        handle(i);
    for (int i = 0; i < m; i++)
        ans = ans * (c[i] + 1) % mod;
    cout << ans << endl;
    return 0;
}

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

int main(){
  long long int N;
  cin >> N;
  vector<long long int> P(5);
  for(int i=0; i<5; i++){
    cin >> P.at(i);
  }
  sort(P.begin(),P.end());
  if(N%P.at(0)==0){
    cout << N/P.at(0)+4 << endl;
  }
  else{
    cout << N/P.at(0)+5 << endl;
  }
}

Measured memory_bytes: 256