akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
bitset<4000010> bs;
 
int num[2010],n;
 
inline int rd()
{
    int x=0;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar());
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x;
}
 
int main()
{
    n=rd();
    for (int i=1;i<=n;i++) num[i]=rd();
    bs.reset();bs[0]=1;
    for (int i=1;i<=n;i++) bs|=(bs<<num[i]);
    int sum=0;
    for (int i=1;i<=n;i++) sum+=num[i];
    int s=((sum+1)>>1);
    for (int i=s;i<=sum;i++)
    {
        if (bs[i]) { printf("%d\n",i);return 0; }
    }
    return 0;
}


Measured memory_bytes: 1664
n = int(input())
if n%2:
  print(0)
else:
  t = n//2
  c2, c5 = t, 0
  l = t
  while t>0:
    t //= 2
    c2 += t
  while l>0:
    l //= 5
    c5 += l
  print(min(c2, c5))

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll H, W; cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }
  cout << (H*W + 1) / 2 << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> dp(100000,0);
 
int main(){
    int n;cin>>n;
    int a,b,c;
    a=1;b=6;c=9;
    for(int i=1;i<n+1;i++){
        if(i>=b*6) b*=6;
        if(i>=c*9) c*=9;
        if(i<6) dp[i]=i;
        else if(i<9) dp[i]=min(dp[i-a]+1,dp[i-b]+1);
        else dp[i]=min({dp[i-a]+1,dp[i-b]+1,dp[i-c]+1});
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 640
v, e = gets.split.map(&:to_i)
ret = []
set = Array.new(v){ |i| i }
g = Array.new(v){ Array.new }
rg = Array.new(v){ Array.new }
e.times do
  s,t = gets.split.map(&:to_i)
  g[s] << t
  rg[t] << s
end
empset = rg.map.each_with_index{|a, i| i if a.empty? }.compact
until set.empty?
  n = empset.shift
  set.delete(n)
  ret << n
  g[n].each do |m|
    rg[m].delete(n)
    if rg[m].empty?
      set << m
      empset << m
    end
  end
end
ret.each{|v| p v}

Measured memory_bytes: 13256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,m;
    cin>>n>>m;
    if(n==2 || m==2)
        cout<<0<<endl;
    else
        cout<<max(max((n-2),(long long)1)*max((m-2),(long long)1),(long long)0)<<endl;
    return(0);
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int n,c[30][maxn];
char s[maxn];

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

void update(int idx,int change,int *a){
    for(int i=idx;i<=n;i+=lowbit(i)) a[i]+=change;
}

int quary ( int r,int *a){
    int sum=0;
    for(int i=r;i>0;i-=lowbit(i)) sum+=a[i];
    return sum;
}

int main()
{
    scanf("%d",&n);
    getchar();
    for(int i=1;i<=n;i++) scanf("%c",&s[i]);
    for(int i=1;i<=n;i++) update(i,1,c[s[i]-'a']);
    int q,iq,l,r,cmp;
    char cq;
    scanf("%d",&q);
    while(q--){
        int ans=0;
        scanf("%d",&cmp);
        if(cmp==1){
            scanf("%d %c",&iq,&cq);
            update(iq,-1,c[s[iq]-'a']);
            s[iq]=cq;
            update(iq,1,c[cq-'a']);
        }
        else{
            scanf("%d%d",&l,&r);
            for(int i=0;i<26;i++){
                int cnt=0;
                cnt+=quary(r,c[i])-quary(l-1,c[i]);
                if(cnt>0){
                    ans++;
                }
            }
            cout<<ans<<"\n";
        }
    }
}


Measured memory_bytes: 102272
#include "bits/stdc++.h"
using namespace std;
#define mx  100001
#define ll long long
#define llu long long unsigned
#define pb push_back
#define s(v) sort(v.begin(),v.end())


int main(){
    string s;
    int sum=0;
    cin>>s;
    for(int i=0; i<s.size(); i++){
        sum+=s[i]-48;
    }
    sum%9==0?cout<<"Yes"<<endl:cout<<"No"<<endl;
}
//1794102596


Measured memory_bytes: 3732
N = int(input())
A = list(map(int, input().split()))

k0 = 0
k2 = 0
k4 = 0

for a in A:
  if a%4==0:
    k4 += 1
  elif a%2==0:
    k2 += 1
  else:
    k0 += 1

# 2で割り切れるものをひとまとめにしk0としてみなす
if k2 > 0:
  k0 += 1

if k0 <= k4+1:
  print("Yes")  
else:
  print("No")


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int

struct edge{int to, cost;};

ll POW(ll a, ll b){
	if(b == 0) return 1LL;
	if(b == 1) return a;
	if(b %2 == 1) return (a*POW(a, b-1))%INF;
	return POW(a*a%INF, b/2);
}

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

int main(){
	int n;
	cin >> n;
	vector<edge> G[n];
	REP(i, n-1){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		G[a].pb({b,c});
		G[b].pb({a,c});
	}
	int ans[n];
	REP(i, n) ans[i] = -1;
	ans[0] = 1;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int f = que.front(); que.pop();
		for(edge e: G[f]){
			if(ans[e.to] == -1){
				if(e.cost%2 == 0) ans[e.to] = ans[f];
				else ans[e.to] = 1-ans[f];
				que.push(e.to);
			}
		}
	}
	REP(i, n) cout << ans[i] << endl;
	return 0;
} 


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int main()
{
   ll a,b,n;cin>>a>>b>>n;
   ll max=0,c,check;
   if(b>n)
   {
   	check=n;
   }
   else
   {
   	check=b-1;
   }
   c=(a*check)/b-(check/b)*a;
   cout<<c;
}

Measured memory_bytes: 3592
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
	using namespace std;

	int n;
	cin >> n;
	vec<int> h(n);

	for (auto& e : h)
		cin >> e;

	auto ans{0};
	auto count{ 0 };
	auto prev = h[0] - 1;

	for (auto e : h)
	{
		if (e <= prev)
		{
			++count;
		}
		else
		{
			count = 0;
		}
		ans = max(count, ans);
		prev = e;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    string c[2];
    for (int i = 0; i < 2; i++)
        cin >> c[i];
    if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 3580
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T, std::size_t N>
struct make_vector_type {
	using type =
		typename std::vector<typename make_vector_type<T, (N - 1)>::type>;
};

template <typename T>
struct make_vector_type<T, 0> {
	using type = typename std::vector<T>;
};

template <typename T, size_t N>
auto make_vector_impl(const std::vector<std::size_t>& ls, T init_value) {
	if constexpr(N == 0) {
		return std::vector<T>(ls[N], init_value);
	} else {
		return typename make_vector_type<T, N>::type(
			ls[N], make_vector_impl<T, (N - 1)>(ls, init_value));
	}
}

template <typename T, std::size_t N>
auto make_vector(const std::size_t (&ls)[N], T init_value) {
	std::vector<std::size_t> dimensions(N);
	for(int i = 0; i < N; i++) {
		dimensions[N - i - 1] = ls[i];
	}
	return make_vector_impl<T, N - 1>(dimensions, init_value);
}

template <typename T>
std::vector<T> make_vector(std::size_t size, T init_value) {
	return std::vector<T>(size, init_value);
}

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max<T>(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min<T>(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	VLL a(n);
	REP(i, n) { cin >> a[i]; }

	ll result = 0;
	ll a_max = a[0];
	REP(i, n) {
		result += max<ll>(a_max - a[i], 0);
		chmax<ll>(a_max, a[i]);
	}
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 4840
// AOJ DSL_2_A Range Minimum Query (RMQ)
// 2018.5.5 bal4u

#include <stdio.h>
#include <stdlib.h>

#define INF 0x7fffffff

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];
	char inf[11] = "2147483647";

	if (!n) pc('0');
	else if (n == INF) for (i = 0; i < 10; i++) pc(inf[i]);
	else {
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

// セグメント木の初期化：配列の確保と初期値による初期化
int seg[1<<18]; int sz;

void segtree(int n, int init_val)
{
	int i;

	sz = 1; while (sz < n) sz <<= 1;
	n = sz << 1;
//	seg = malloc(n << 2);
	for (i = 0; i < n; i++) seg[i] = init_val;
}

// k番目（0-index）の値を v に変更
void update(int k, int v)
{
	int p;

	k += sz - 1;
	seg[k] = v;
	while (k > 0) {
		k = (k-1) >> 1;
		p = (k << 1)+1;
		v = seg[p+1];
		if (v > seg[p]) v = seg[p];
		seg[k] = v;
	}
}

int query2(int a, int b, int k, int l, int r) 
{
	int m, lmin, rmin;

	if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return seg[k];
	k <<= 1, m = (l+r) >> 1;
    lmin = query2(a, b, k+1, l, m);
    rmin = query2(a, b, k+2, m, r);
	if (lmin > rmin) lmin = rmin;
    return lmin; 
}

// 空間 [a, b)　内の最小値
int range_min_query(int a, int b)
{
	return query2(a, b+1, 0, 0, sz);
}


int main()
{
	int n, q, op, x, y;

	n = in(), q = in();
	segtree(n, INF);

	while (q--) {
		op = in(), x = in(), y = in();
		if (op) out(range_min_query(x, y));
		else update(x, y);
	}
	return 0;
}



Measured memory_bytes: 2636
adjacent_vector = [
    (-1, 0), # left
    (0, -1), # down
    (1, 0),  # right
    (0, 1)   # up
]

while True:
    num_squares = int(input())

    if num_squares == 0:
        break

    x_coordinates = [0] # x??§?¨?????????????
    y_coordinates = [0] # y??§?¨?????????????

    for _ in range(num_squares-1):
        # adjacent_square: ??£??\????????£?????¢?????????
        adjacent_square, direction = map(int, input().split())

        x = x_coordinates[adjacent_square] # ??£??\????????£?????¢???x??§?¨?
        y = y_coordinates[adjacent_square] # ??£??\????????£?????¢???y??§?¨?

        (dx, dy) = adjacent_vector[direction]

        x_coordinates.append(x + dx)
        y_coordinates.append(y + dy)

    max_x = max(x_coordinates)
    min_x = min(x_coordinates)
    max_y = max(y_coordinates)
    min_y = min(y_coordinates)

    print(max_x - min_x + 1, max_y - min_y + 1)

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

int main() {
  int n,x;
  cin>>n>>x;
  int length[n];
  for(int i=0; i<n; i++) cin>>length[i];

  int ans = 1;
  int posi = 0;
  for(int i=0; i<n; i++) {
    posi += length[i];
    if(posi<=x) ans++;
    else break;
  }

  cout<<ans<<endl;

  return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

int main() {
  ll n, k;
  string s;
  cin >> n >> k >> s;

  s += "x";
  dqll as;
  ll sp = 0;
  rep(i, n) {
    if (s[i] != s[i + 1] || s[i + 1] == 'x') {
      ll sign = (s[i] == '0') ? -1 : 1;
      as.push_back(sign * (i - sp + 1));
      sp = i + 1;
    }
  }

  ll nas = as.size();

  ll ans = 0, sum = 0;
  ll cnt = 0;
  ll lp = 0, rp = 0;
  while (rp < nas) {
    if (as[rp] > 0) {
      sum += as[rp];
      rp++;
    } else {
      if (cnt < k) {
        sum -= as[rp];
        rp++;
        cnt++;
      } else {
        if (as[lp] > 0) {
          sum -= as[lp];
        } else {
          sum += as[lp];
          cnt--;
        }
        lp++;
      }
    }
    chmax(ans, sum);
  }  // while

  cout << ans << endl;

  return 0;
}


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

class Masu {
public:
  int e;
  int a;
};

int x, y, z;
int v[4];
Masu masu[52];

void solve() {
  double dp[52][5001];
  for(int i = 0; i < 52; i++) {
    for(int j = 0; j < 5001; j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;

  for(int i = 0; i < y; i++) {
    for(int j = 0; j <= 5000; j++) {
      if(dp[i][j] == 0) continue;
      for(int k = 0; k < x; k++) {
	int np = min(y, i + v[k]);
	int nm = j;
	switch(masu[np].e) {
	case 1:
	  np = min(y, np + masu[np].a);
	  break;
	case 2:
	  nm += masu[np].a;
	  break;
	case 3:
	  nm = max(0, nm - masu[np].a);
	  break;
	}

	dp[np][nm] += dp[i][j]*(1.0/x);
      }
    }
  }

  double ans = 0;
  for(int i = 0; i <= 5000; i++) ans += dp[y][i]*i;
  cout << (int)ans << endl;
}

int main() {
  while(1) {
    cin >> x >> y >> z;
    if(x == 0 && y == 0 && z == 0) break;
    for(int i = 0; i < x; i++) {
      cin >> v[i];
    }
    for(int i = 0; i <= y; i++) masu[i].e = 0;
    for(int i = 0; i < z; i++) {
      int n;
      cin >> n;
      cin >> masu[n].e >> masu[n].a;
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 2896
import itertools
N,M=map(int,input().split())
L=[]
c=[i for i in range(1,N+1)]
for _ in range(M):
    x,y = map(int,input().split())
    l1 = [x,y]
    l2 = [y,x]
    L.append(l1)
    L.append(l2)
c = [list(x) for x in itertools.permutations(c)]
count = 0
ans = 0
for x in c:
    if x[0] > 1:
        break
#    print(x)
    for i in range(N-1):
        if [x[i],x[i+1]] in L:
            count += 1
 #           print(x[i],x[i+1])
            if count == N - 1:
                ans += 1
                count = 0
        else:
            count = 0
            break

print(ans)


Measured memory_bytes: 47452
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
  int n,k,count = 0;
  cin >> n >> k;
  
  vector<int> d(k);
  int a[105][105];
  vector<bool> b(n);
  
  for(int i = 0; i<k; i++)
  {
    cin >> d[i];
    for(int j = 0; j < d[i]; j++)
    {
      cin >> a[i][j];
    }
  }
  
  for(int i = 0; i < k; i++)
  {
    for(int j = 0; j < d[i]; j++)
    {
      if(b[a[i][j]-1] == true)
      {
        continue;
      }
      else
      {
        b[a[i][j]-1] = false;
      }

      b[a[i][j]-1] = true;
      
    }
  }
  
  for(int i = 0; i < n; i++)
  {
    (b[i] != true) ? count++ : count += 0;
  }
  
  cout << count;
  
  return 0;
}

Measured memory_bytes: 3648
import math
n,d = map(int,input().split())
x = [0] * n
ans = 0
for i in range(n):
    x[i] = list(map(int,input().split()))
for i in range(n):
    for j in range(i+1,n):
        l = math.sqrt(sum((x[i][f] - x[j][f])**2 for f in range(d)))
        if l%1 == 0:
            ans += 1
print(ans)


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

int main()
{
	int N, D;
	cin >> N >> D;
	vector<vector<int>> X( N, vector<int>( D ) );
	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < D; j++ ) {
			cin >> X[i][j];
		}
	}

	int ans = 0;
	for( int i = 0; i < N; i++ ) {
		for( int j = i + 1; j < N; j++ ) {
			double sum = 0;
			for( int k = 0; k < D; k++ ) {
				int x = X[i][k] - X[j][k];
				sum += x * x;
			}
			double rt = sqrt( sum );
			if( floor( rt ) == rt ) ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3544
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    double sum = accumulate(A.begin(), A.end(), 0.0);
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    sum = sum / (4 * M);
    if(A[M - 1] < sum) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,q,i,x;
	cin>>n>>k>>q;
	int A[n]={0};
	for(i=0;i<q;i++){
		cin>>x;
		A[x-1]++;
	}
	for(i=0;i<n;i++){
		if(k-q+A[i]>0)cout<<"Yes";
		else cout<<"No";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define rep(index,num) for(int index=0;index<num;index++)
#define eps 1e-15
typedef long long ll;
int main(){
	char str[11];
	scanf("%s",str);
	rep(i,10){
		if(str[i]=='B'){
			for(int j=i-1;j>=0;j--){
				if(str[j]=='0'||str[j]=='1'){
					str[j]='X';
									break;
				}
			}
			str[i]='X';
		}
	}
	rep(i,10){
		if(str[i]=='0'||str[i]=='1'){
			printf("%c",str[i]);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;


// 149_c
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long a = sc.nextInt();
        long b = sc.nextInt();

        out(lcm(a, b));

    }

    /*
     * 以下メソッド集
     */

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

}


Measured memory_bytes: 21716
N,Y=map(int,input().split())
A=[]
for i in range(Y//10000+1):
    for j in range((Y-i*10000)//5000+1):
        c1=(Y-10000*i-5000*j)/1000
        c2=N-i-j
        if c1==c2:
            A=[i,j,c1]
            break
        if c1!=c2:
            continue
if len(A)==0:
    print("-1 -1 -1")
else:
    A[2]=int(A[2])
    print(str(A[0])+" "+str(A[1])+" "+str(A[2]))

Measured memory_bytes: 41040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(){
  string s;cin >> s;
  int n = s.size();
  int c  = s.at(0)-'0';
  bool frag = true;
  for(int i = 1;i<s.size();i++){
      if(s.at(i) != '9') frag = false;
  }
  if(frag == true){
      cout << c + 9*(n-1) << endl;
  }else{
      cout << c-1 + 9*(n-1) << endl;
  }
} 

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

double sum_upto(double n)
{
    double ans=0;
    if(int(n)%2==1)
    {
        ans = (n+1)/2;
        ans = ans*n;
    }
    else
    {
        ans = n/2;
        ans = ans*(n+1);
    }
    return ans;
}

int main()
{
    double n,k;
    cin>>n>>k;
    vector<double> v(n),prefix_sum(n+1); prefix_sum[0]=0;
    for(ll i=0;i<n;i++) cin>>v[i];
    prefix_sum[1] = v[0];
    for(ll i=2;i<n+1;i++) prefix_sum[i] = prefix_sum[i-1]+v[i-1];
    
    ll tmp_sum=0,l,r,sum=-1;
    
    for(ll i=k;i<n+1;i++)
    {
        tmp_sum = prefix_sum[i] - prefix_sum[i-k];
        if(tmp_sum>sum)
        {
            sum = tmp_sum;
            l = i-k;
            r = i-1;
        }
    }
    
    
    double ans=0;
    
    for(ll i=l;i<=r;i++)
    {
        ans += (sum_upto(v[i])/v[i]);
    }
    cout<<fixed<<setprecision(6)<<ans<<endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>

using namespace std;
using ll = long long;

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

	string s_a = s.substr(0, (n + 1) / 2);
	string s_b = s.substr((n + 1) / 2);

	if (s_a == s_b) cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int n=3;
int a[10];
int cmp(const void *a,const void *b)
{
	int x=*(int *)a;
	int y=*(int *)b;
	if (x>y)
	{
	    return 1; 
	} 
	else
	{
		return -1;
	} 
}

int main()
{
    int i;
    for (i=1;i<=n;i++)
    {
    	scanf ("%d",&a[i]);
	}
	qsort (a+1,n,sizeof(a[1]),cmp);
	cout<<a[3]-a[1]<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define nl '\n'
#define ff first
#define ss second
//////////////////////////////////////////////////



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); srand(time(0));
  
  int k; cin >> k;
  ll a[k];
  for(int i=0;i<k;i++) cin >> a[i];
  
  ll lo = 0, hi = (ll)4e18;
  while( lo < hi ) {
    ll mid = (lo+hi)/2;
    ll x = mid;
    for(int i=0;i<k and x>0;i++)
      x -= x % a[i];
    if( x >= 2 ) hi = mid;
    else lo = mid+1;
  }
  ll lx = lo;
  
  lo = 0, hi = (ll)4e18;
  while( lo < hi ) {
    ll mid = (lo+hi)/2;
    ll x = mid;
    for(int i=0;i<k and x>0;i++)
      x -= x % a[i];
    if( x > 2 ) hi = mid;
    else lo = mid+1;
  }
  ll rx = lo-1;
  
  // cerr << lx << ' ' << rx << endl;
  if( lx > rx ) cout << -1 << endl;
  else cout << lx << ' ' << rx << endl;
  
  return 0;
}


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

// 二分探索(O(log(2)N))

bool binarySearch(vector<int> S, int key){
    int left = 0;
    int right = S.size()-1;
    int mid;

    while(right - left > 1){
        mid = (left+right)/2;
        if(S[mid] >= key) right = mid;
        else left = mid;
    }

    return S[right] == key;
}

int main(){
    int N; cin >> N;
    vector<int> S(N+2);
    for(int i=1; i<=N; ++i){
        cin >> S[i];
    }
    S[0] = -1; S[N+1] = pow(10,9) + 1;

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

    int count = 0;

    for(int i=0; i<q; ++i){
        if(binarySearch(S, T[i])) count++;
    }
    
    cout << count << endl;
}


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

void shift(char *str, int len, int n){
	char t[] = "abcdefghijklmnopqrstuvwxyz";
	char c;
	for(int i=0; i<len; ++i){
		c = *(str + i);
		if(c >= 'a' && c <= 'z'){
			str[i] = t[(c-'a'+n)%26];
		}
	}
}

int main(void){
	char input[81];
	char copy[81];
	char *token;
	int len = 0;
	int n = 0;

	while(fgets(input, 80, stdin) != NULL){
		n = -1;
		strcpy(copy, input);

		token = strtok(copy, " .\n");
		while(token != NULL && n == -1){
			len = strlen(token);
			if(len == 4){
				for(int i=0;i<26; ++i){
					shift(token, 4, 1);
					if(strcmp(token, "this")==0 ||
						strcmp(token, "that")==0){
						n = i + 1;
						break;
					}
				}
			}else if(len ==3){
				for(int i=0;i<26; ++i){
					shift(token, 3, 1);
					if(strcmp(token, "the")==0){
						n = i + 1;
						break;
					}
				}
			}
			token = strtok(NULL, " .\n");
		}
		shift(input, strlen(input), n);
		printf(input);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  double D,T,S;
  cin>>D>>T>>S;
  double temp= D/S;
  if(temp<=T){
  cout<<"Yes"<<endl;
  
  }else{
  
  cout<<"No"<<endl;
  }


return 0;
}


Measured memory_bytes: 3704
#include <stdio.h>
int main(void)
{
  int n,k,i,j;
  while(1){
    scanf("%d %d",&n,&k);
    if(!(n+k)) break;
    int s[k];
    for(i=0;i<k;i++)
      scanf("%d",&s[i]);
    int b[n][k];
    int nec[k];
    for(i=0;i<k;i++)
      nec[i]=0;
    for(i=0;i<n;i++){
      for(j=0;j<k;j++){
	scanf("%d",&b[i][j]);
	nec[j]+=b[i][j];
      }
    }
    int f=1;
    for(i=0;i<k;i++){
      if(nec[i]>s[i]){
	f=0;
	break;
      }
    }
    if(f)
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}

Measured memory_bytes: 620
n = gets.to_i
a = gets.split.map(&:to_i)
sorted = a.sort
s = (0..n-1).count {|i| a[i] == sorted[i]}
if s == n
    p 0
else
    ans = -1
    gets.to_i.times do |k|
        i, j = gets.split.map(&:to_i)
        i -= 1
        j -= 1
        s -= 1 if a[i] == sorted[i]
        s -= 1 if a[j] == sorted[j]
        a[i], a[j] = a[j], a[i]
        s += 1 if a[i] == sorted[i]
        s += 1 if a[j] == sorted[j]
        if s == n
            ans = k + 1
            break
        end
    end
    p ans
end


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

typedef long long int llint;

int main(){
	llint A,B,C;
	cin >> A >> B >> C;
	if( A%2==0 || B%2==0 || C%2==0 ){
		cout << 0 << endl;
	}else{
		vector<llint> v={A*B,B*C,C*A};
		cout << *min_element(v.begin(),v.end()) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
K = int(input())
cnt = 0
while True:
    if A < B:
        break
    B *= 2
    cnt += 1
while True:
    if B < C:
        break
    C *= 2
    cnt += 1
if cnt <= K:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61628
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = 1e10;
/************************  DEFINE  ****************************/

/************************ FUNCTION ****************************/

/************************   MAIN   ****************************/
int main(void){
    
  	string s;cin>>s;
  if(s.size() <= 7)cout << "YES" << endl;
  else{ int a = 0;
    for(int i=0;i<s.size();i++){
      //int a = 0;
      if(s[i] == 'x') a++;
    }
    if(a <= 7)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
     return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

ll N;
 
int main() {
    ll N; cin>>N;
    VL p(N);
    rep(i,0,N)cin>>p[i];
    ll ans=0;
    rep(i,0,N-2){
        if(p[i]<p[i+1]&&p[i+1]<=p[i+2])ans++;
        if(p[i]>=p[i+1]&&p[i+1]>p[i+2])ans++;
    }
    cout << ans << endl;
    return 0;
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int H,W; cin >> H >> W;
    int A,B; cin >> A >> B;
    int ans[H][W];
    for(int i=0;i<2*B;i++){
        if(i%2==0){
            for(int j=0;j<A;j++){
                ans[i][j]=1;
            }
            for(int j=A;j<W;j++){
                ans[i][j]=0;
            }
        }else{
            for(int j=0;j<A;j++){
                ans[i][j]=0;
            }
            for(int j=A;j<W;j++){
                ans[i][j]=1;
            }
        }
    }
    for(int i=2*B;i<H;i++){
        for(int j=0;j<A;j++){
            ans[i][j]=0;
        }
        for(int j=A;j<W;j++){
            ans[i][j]=1;
        }
    }
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << ans[i][j];
        }
        cout << endl;
    }

    
}


Measured memory_bytes: 5120
K,N = list(map(int,input().split()))

A = list(map(int,input().split()))
ans = 10**20
for i in range(N):
    if A[i]>=A[i-1]:
        ans = min(K - (A[i]-A[i-1]),ans)
    else:
        ans = min(K- (A[i]+ K -A[i-1]), ans)

print(ans)


Measured memory_bytes: 77388
#include "bits/stdc++.h"
using namespace std;


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define sec second
#define fir first
#define pb push_back



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
//const int inf = pow(2, 62);
//const int mod = 1e9 + 7;
const int mod = 100000;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }




/* main */
int ceil(int a, int b){
    if(a % b == 0) return a /b;
    else return a /b + 1;
}


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    
    vec<string> arr; rep(i,0,3) arr.push_back(raw_input());

    if(arr[0].back() == arr[1].front() && arr[1].back() == arr[2].front()){
        print("YES");
    }else{
        print("NO");
    }




    
    



    
    

    







   




    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










Measured memory_bytes: 256
n,a,b=int(input()),list(map(int,input().split())),list(map(int,input().split()))
sa=sb=p1=p2=0
for i in range(n):
  sa+=a[i];sb+=b[i]
  if a[i]>b[i]:p1+=a[i]-b[i]
  elif a[i]<b[i]:p2+=(b[i]-a[i]-1)//2+1
m=sb-sa
if m<p1 or m<p2:print("No")
else:print("Yes")

Measured memory_bytes: 4596
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxN = 55;
int N;
int maxx, idx = 1;
int cabs(int num) {return ((num < 0) ? (-num) : num);}
int main() {
	//cout << cabs(-10) << endl; 
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i) {
		int val; scanf("%d", &val);
		if(cabs(val) > cabs(maxx)) maxx = val, idx = i;
	}
	printf("%d\n", (N - 1) * 2);
	for(int i = 1; i <= N; ++i) {
		if(i == idx) continue;
		printf("%d %d\n", idx, i);
	}
	if(maxx < 0) {
		for(int i = N; i > 1; --i) {
			printf("%d %d\n", i, i - 1);
		}
	} else {
		for(int i = 1; i < N; ++i) {
			printf("%d %d\n", i, i + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n, d, cnt = 0;
    cin >> n >> d;

    for(int i = 0; i < n; i++)
    {
        long long x, y;
        cin >> x >> y;
        if(x*x + y*y <= d*d)
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main()
{
   long a,b;
   long i,j,k;
   long cnt = 0;
   long left,right,mid;
   long ans = 0;
   static char str[102][1003];
   char p[1003];
   char tmp;
   long h,m,s;

   scanf("%ld %ld",&a,&b);
   printf("a ");
   if (a < b)
      putchar('<');
   else if (a > b)
      putchar('>');
   else
      printf("==");
   printf(" b\n");


   return 0;
}

Measured memory_bytes: 1024
import java.io.*;

public class Main{
	public static void main(String args[]){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		char[] ch = new char[1200];
		int len, cnt = 0;
		try{
			str = br.readLine();
			len = str.length();
			ch = str.toCharArray();
			
			for(int i = 0; i < len; i++){
				if('a' <= ch[i] && ch[i] <= 'z'){
					ch[i] = Character.toUpperCase(ch[i]);
				}
				else if('A' <= ch[i] && ch[i] <= 'Z'){
					ch[i] = Character.toLowerCase(ch[i]);
				}
		}
		} catch(IOException e){
			System.out.println(e);
		}
		
		
		
		
		System.out.println(ch);
	}
}

Measured memory_bytes: 24316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){cin >> a.at(i);}
  sort(a.begin(),a.end());
  int output = a.at(N-1)-a.at(0);
  cout << output << endl;
}

Measured memory_bytes: 256
import math

a, b, C = map(int,input().split())

S = a * b * math.sin(math.radians(C)) / 2
c2 = a * a + b * b - 2 * a * b * math.cos(math.radians(C))
c = math.sqrt(c2)
L = a + b + c
h = 2 * S / a

print('{:.6f}'.format(S))
print('{:.6f}'.format(L))
print('{:.6f}'.format(h))


Measured memory_bytes: 5716
//package beginerContest097.qA;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int[] abcd = new int[4];

		for (int i = 0; i < 4; i++) {
			abcd[i] = sc.nextInt();
		}

		int count = 0;

		for (int i = 0; i < 2; i++) {
			int m = abcd[i + 1] - abcd[i];
			if (Math.abs(m) <= abcd[3]) {
				count++;
			}
		}

		int m = Math.abs(abcd[0]- abcd[2]);
		if(m <= abcd[3]) count = 2;

		if (count == 2)
			System.out.println("Yes");
		else
			System.out.println("No");
		sc.close();

	}

}


Measured memory_bytes: 23124
#include <iostream>
using namespace std;
int max(int x, int y){return x > y ? x : y;}
int main(){
	int n; cin >> n;
	int res = 0;
	for(int num=1; num<=100000; num*=100){
		if (num*10-1 <= n) res += (num * 9);
		else res += max(n - num + 1, 0);
	}
	cout << res << endl;
}


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

using namespace std;

const long long inf = 1'000'000'000'000'000'000;

inline long long mul(long long a, long long b) {
  return a <= inf / b ? a * b : inf;
}

inline long long add(long long a, long long b) {
  a += b;
  return a <= inf ? a : inf;
}

const int N = 200'009;

int n;
int a[N];

long long calc(int s) {
  long long res = 0;
  for (int i = 0; i < s; ++i) {
    res = add(res, a[i]);
  }
  for (int from = 0; from < n; from += s) {
    for (int k = 0; k < s; ++k) {
      int i = from + k;
      if (i >= n) {
        continue;
      }
      int j = from + s + k;
      int v = from / s + 2;
      if (j < n) {
        res = add(res, mul(a[i] - a[j], mul(v, v)));
      } else {
        res = add(res, mul(a[i], mul(v, v)));
      }
    }
  }
  return res;
}

int main() {
  int m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  reverse(a, a + n);
  int l = 1, r = n;
  while (l < r) {
    int s = (l + r) / 2;
    long long v = calc(s);
    if (v == inf || v + (long long)m * s > calc(s + 1) + (long long)m * (s + 1)) {
      l = s + 1;
    } else {
      r = s;
    }
  }
  printf("%lld\n", calc(l) + (long long)m * (l + n));
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;  // NOLINT
using LL = int64_t;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& i : a) cin >> i;
    sort(a.begin(), a.end());
    cout << a.back() - a.front() << endl;
}


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

#include<algorithm>
using namespace std;
int main()
{
    vector <int> vec;
    int n,k,s=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    { int v;
    cin>>v;

      vec.push_back(v);
    }

    sort(vec.begin(),vec.end());
     for(int i=0;i<k;i++)
    {

   s=s+vec[i];

    }
    cout<<s<<endl;
    return 0;


}


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

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  if (s.size() <= k)
    cout << s << endl;
  else {
    for (int i = 0; i < k; i++) {
      cout << s.at(i);
      if (i == k - 1)
        cout << "..." << endl;
    }
  }
}


Measured memory_bytes: 3576
# -*- coding: utf-8 -*-
"""
Matching - Bipartite Matching
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_7_A&lang=jp

"""
import sys
from sys import stdin
from collections import namedtuple
input = stdin.readline
edge = namedtuple('edge', ['to', 'cap', 'rev'])


def add_edge(G, f, t, c):
    G[f].append(edge(t, c, len(G[t])))
    G[t].append(edge(f, 0, len(G[f]) - 1))


def dfs(G, used, v, t, f):
    if v == t:
        return f
    used[v] = True
    for i in range(len(G[v])):
        e = G[v][i]
        if (not used[e.to]) and (e.cap > 0):
            d = dfs(G, used, e.to, t, min(f, e.cap))
            if d > 0:
                G[v][i] = edge(e.to, e.cap - d, e.rev)
                G[e.to][e.rev] = edge(G[e.to][e.rev].to, G[e.to][e.rev].cap + d, G[e.to][e.rev].rev)
                return d
    return 0


def max_flow(G, V, s, t):
    flow = 0
    while True:
        used = [False] * V
        f = dfs(G, used, s, t, float('inf'))
        if f == 0:
            return flow
        flow += f


def main(args):
    """
    - 追加したソースノードID: 0
    - Xグループ: 1〜X
    - Yグループ: X+1〜X+Y
    - 追加したシンクノードID: X+Y+1
    として、ノード0 → X+Y+1 への最大流を求める
    """
    X, Y, E = map(int, input().split())
    G = [[] for _ in range(X+Y+2)]

    for li in range(E):
        x, y = map(int, input().split())
        add_edge(G, x+1, X+y+1, 1)

    for x in range(1, X+1):
        add_edge(G, 0, x, 1)       # ソースから集合X
    for y in range(X+1, X+Y+1):
        add_edge(G, y, X+Y+1, 1)   # 集合Yからシンク


    ans = max_flow(G, X+Y+2, 0, X+Y+1) #  ソースとシンク間の最大流
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])




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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N, k;
ll A[100010];
/*==================================================*/
class FermatCombination {
private:
	long long factrial[101010]; //階乗を保持
	long long inverse[101010];  //逆元を保持
	long long MOD;

public:
	FermatCombination(int size, long long mod);
	long long combine(int n, int k);
	long long fast_pow(long long x, int n);
};

FermatCombination::FermatCombination(int size, long long mod) {

	MOD = mod;

	factrial[0] = 1;
	inverse[0] = 1;

	for (int i = 1; i <= size; i++) {
		factrial[i] = (factrial[i - 1] * i) % MOD;  // 階乗を求める
		inverse[i] = fast_pow(factrial[i], (int)MOD - 2) % MOD; // フェルマーの小定理で逆元を求める
	}
}

long long FermatCombination::combine(int n, int k) {
	if(n < k) return 0;
	return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}

long long FermatCombination::fast_pow(long long x, int n) { // x^n 計算量O(logn)
	long long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x % MOD;
		}
		x = x * x % MOD; // 一周する度にx, x^2, x^4, x^8となる
		n >>= 1;         // 桁をずらす n = n >> 1
	}
	return ans;
}
ll ans;
int main(){
	cin >> N >> k;
	REP(i,0,N){
		cin >> A[i];
	}
	sort(A, A+N);
	FermatCombination fc(N, mod);
	REP(i,0,N){
		ans += A[i] * fc.combine(i, k-1);
		ans %= mod;
	}
//	p(ans);
	REP(i,0,N){
		ans -= A[i] * fc.combine(N-i-1, k-1);
		if(ans < 0) ans += A[i] * mod;
		ans %= mod;
//		p2(A[i],fc.combine(N-i-1, k-1));
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n, m; cin >> n >> m;
    vector<int> broken(n + 1);
    for(int i = 0; i < m; i++) {
        int a; cin >> a;
        broken[a] = 1;
    }

    vector<int> dp(n + 2);
    const int mod = 1000000007;
    dp[n] = 1;
    for(int i = n - 1; i >= 0; i--) {
        if(broken[i]) {
            dp[i] = 0; continue;
        }
        dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
    }

    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 1792
/*input
level
*/
#include<bits/stdc++.h>
#define int        long long
#define MOD        1000000007
#define MAX        100005
#define pb         push_back
#define mp         make_pair
#define pii        pair<int,int>
#define mii        map<int,int>
#define vi         vector<int>
#define ff         first
#define ss         second
#define T          int t;cin>>t;while(t--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define umi        unordered_map<int,int>
#define maxheap    priority_queue<int>
#define minheap    priority_queue<int,vector<int>,greater<int> >
#define inp(n)     for(int i=0;i<n;i++)
#define N          2000005
#define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())
using namespace std;
using namespace std::chrono;

bool pal(string s){
    int n = s.length();
    for(int i=0,j=n-1;i<j;i++,j--){
        if(s[i] != s[j]) return false;
    }
    return true;
}

signed main(){
    string s,a,b;
    cin >> s;
    int n = s.length();
    for(int i=0;i<(n-1)/2;i++) a+=s[i];
    for(int i=(n+3)/2-1;i<n;i++) b+=s[i];
    if(pal(s) && pal(a) && pal(b)) cout << "Yes\n";
    else cout << "No\n";
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	foods := make(map[int]int)
	ans := 0
	for i := 0; i < N; i++ {
		var k, a int
		fmt.Scan(&k)
		for j := 0; j < k; j++ {
			fmt.Scan(&a)
			foods[a]++
			if foods[a] == N {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
n, m = map(int, input().split())
N = 10 ** 9 + 7
d = [0 for _ in range(n + 2)]
d[1] = 1
for _ in range(m):
  i = int(input()) + 1
  d[i] = -1
  
for i in range(2, n + 2):
  if d[i] == -1:
    d[i] = 0
  else:
    d[i] = (d[i - 2] + d[i - 1]) % N

print(d[-1])

Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N, A, B, ans = 0;
    cin >> N >> A >> B;
    ll num = N / (A + B);
    ll res = N % (A + B);
    cout << num * A + min(res, A);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
V = [int(i) for i in input().split()]

Vodd = V[1::2]
Veven = V[::2]

from collections import Counter

Vodd = sorted(Counter(Vodd).items(), key=lambda x:x[1])
Veven = sorted(Counter(Veven).items(), key=lambda x:x[1])

if Vodd[-1][0] == Veven[-1][0]:
    if len(Vodd) == len(Veven) == 1:
        ans = N - Vodd[-1][1]
    elif len(Vodd) == 1:
        ans = N - Vodd[-1][1] - Veven[-2][1]
    elif len(Veven) == 1:
        ans = N - Vodd[-2][1] - Veven[-1][1]
    elif Vodd[-2][1] >= Veven[-2][1]:
        ans = N - Vodd[-2][1] - Veven[-1][1]
    else:
        ans = N - Vodd[-1][1] - Veven[-2][1]
else:
    ans = N - Vodd[-1][1] - Veven[-1][1]


print(ans)

Measured memory_bytes: 20636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<17,INF=1<<30;
int day[1005][15][25];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        
        int y=1,m=1,n=1,cnt=1;
        while(y<1000){
            day[y][m][n]=cnt;
            
            n++;
            cnt++;
            
            if(y%3==0){
                if(n==21){
                    m++;
                    n-=20;
                }
                if(m==11){
                    y++;
                    m-=10;
                }
            }else{
                if(m%2==1){
                    if(n==21){
                        m++;
                        n-=20;
                    }
                    if(m==11){
                        y++;
                        m-=10;
                    }
                }else{
                    if(n==20){
                        m++;
                        n-=19;
                    }
                    if(m==11){
                        y++;
                        m-=10;
                    }
                }
            }
        }
        
        while(N--){
            int Y,M,D;cin>>Y>>M>>D;
            cout<<196471-day[Y][M][D]<<endl;
        }
        
        break;
    }
}



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

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

	int ans = 0;
	for (int i = n; i > 0; i--) {
		int digit = to_string(i).length();
		if (digit % 2 == 1)ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256