akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n,a,b,c,d;
string s;

bool solve(ll sa,ll sb,ll sc,ll sd){
    bool f = false;
    ll pos = sa;
    for(ll i = sb;i <= sd;i++){
        // cout << i << " " << pos << endl;
        while(pos < sc){
            ll prev = pos;
            if(s[pos+1] != '#' && pos+1 != i)pos++;
            else if(pos+2 < n){
                if(s[pos+2] != '#' && pos+2 != i)pos += 2;
            }
            if(pos == prev)break;
        }
        if(i == sd&&pos == sc)f = true;
        if(i+1 < n){
            if(s[i+1] == '#' || i+1 == pos){
                if(i+2 < n){
                    if(s[i+2] == '#' || i+2 == pos)break;
                }
                i++;
            }
        }
        // cout << i << " " << pos << endl;
        // cout << endl;
        // if(i == sd&&pos == sc)f = true;
    }
    return f;
}

int main(){
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--;
    bool f = solve(a,b,c,d);
    // cout << "!!" << f << endl;
    f |= solve(b,a,d,c);
    if(f)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 500000;

int cnt;
int A[MAXN], L[MAXN/2+5], R[MAXN/2+5];

void merge(int left, int mid, int right){
	int n1 = mid - left, n2 = right - mid;
	for(int i = 0; i < n1; i++) L[i] = A[left+i];
	for(int i = 0; i < n2; i++) R[i] = A[mid+i];
	L[n1] = R[n2] = INF;
	int i = 0, j = 0;
	for(int k = left; k < right; k++){
		cnt++;
		if(L[i] < R[j])
			A[k] = L[i++];
		else
			A[k] = R[j++];
	}
}

void mergeSort(int left, int right){
	if(left + 1 < right){
		int mid = (left + right) / 2;
		mergeSort(left, mid);
		mergeSort(mid, right);
		merge(left, mid, right);
	}
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		scanf("%d", A + i);
	mergeSort(0, n);
	for(int i = 0; i < n; i++){
		if(i)
			printf(" ");
		printf("%d", A[i]);
	}
	printf("\n%d\n", cnt);
	return 0;
}

Measured memory_bytes: 7052
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x=0;
    cin>>a>>b;
    int c[a];
    for(int i=0;i<a;i++){
        cin>>c[i];
        x+=min(c[i],b-c[i])*2;
    }
    cout<<x<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define pb push_back
#define md 1000000007
int main()
{
	fast;
	int n,k;
	cin>>n>>k;
	int vis[n+1]={0};
	int a[k+1];
	for(int i=1;i<=k;i++)
	{
		cin>>a[i];
		int b[a[i]+1];
		for(int j=1;j<=a[i];j++)
		{
			cin>>b[j];
			vis[b[j]]=1;
		}
			
	}
	int count=0;
	for(int i=1;i<=n;i++)
		if(vis[i]==0)
			count++;
		
	
	cout<<count;

	return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main() {
    long long n, k;
    cin >> n >> k;

    if (k == 0) {
        cout << n * n << endl;
    } else {
        long long res = 0;
        for (int i = k + 1; i <= n; i++) {
            res += (n / i) * (i - k) + (n % i - k + 1 > 0 ? n % i - k + 1 : 0);
        }

        cout << res << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll r, g, b, n;
    cin >> r >> g >> b >> n;

    ll ans = 0;
    rep(i, 0, n+1) {
        rep(j, 0, n+1) {
            if ((n - i*r - j*g) % b == 0 && n - i*r - j*g >= 0) ans++;
            else continue;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().rstrip()

n, m = map(int, input().split())
g =  [list() for i in range(n)]

for _ in range(m):
    x, y, z = map(int, input().split())
    x -= 1; y -= 1
    g[x].append(y)
    g[y].append(x)

visited = [False] * n

def dfs(v, p):
    visited[v] = True
    for nv in g[v]:
        if nv == p or visited[nv]: continue
        dfs(nv, v)

cnt = 0

for v in range(n):
    if not visited[v]:
        dfs(v, -1)
        cnt += 1

print(cnt)


Measured memory_bytes: 110212
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	ll n;
	cin >> n;

	cout << n * (n-1) / 2 << endl;

}


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

int main() {
    int N, M, s[5], c[5];
    int a[5];
    int i, j, k, x, digit, num, ans = -1;
    scanf("%d %d", &N, &M);
    for (i=0; i<M; i++) 
        scanf("%d %d", &s[i], &c[i]);

    int start = (int)(pow(10, N-1));
    int limit = (int)(pow(10, N));
    // printf("%d to %d", start, limit);
    if (start == 1) start = 0;

    for (i=start; i<limit; i++) {
        x = i;
        for (k=N; k>0; k--) {
            a[k] = (x % 10);
            x /= 10;
        }

        for (j=0; j<M; j++) {
            if (a[s[j]] != c[j]) break;
        }
        if (j==M) {
            ans = i;
            break;
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{

   int n,k,sum=0;
   cin>>n>>k;
   int arr[n];
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   sort(arr,arr+n);
   for(int i=0;i<k;i++)
   {
       sum+=arr[i];
   }
   cout<<sum<<endl;

}


Measured memory_bytes: 3640
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {
			String[] data = sc.nextLine().split(" ");

			int a = Integer.parseInt(data[0]);
			String op = data[1];
			int b = Integer.parseInt(data[2]);

			if ( op.equals("?") ) break;

			switch (op) {
			case "+":
				sb.append( (a+b) + "\n" );
				break;
			case "-":
				sb.append( (a-b) + "\n" );
				break;
			case "*":
				sb.append( (a*b) + "\n" );
				break;
			case "/":
				sb.append( (a/b) + "\n" );
				break;
			}
		}

		System.out.print(sb);
	}

}

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

#define ll long long
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl '\n'
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define INF 1e+9

using namespace std;

int main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;  cout.tie( 0 ) ;
    
    int n , k ;
    cin >> n >> k ;
    int a[n] , dp[n] ;
    fill_n(dp, n , INF) ;  
    dp[0] = 0 ; 
    for(int i = 0 ; i < n ; i++){
        cin >> a[i] ; 
        for(int j = i - 1 ; j >= i - k and j >= 0 ; j--){
            dp[i] = min(dp[i] , dp[j] + abs(a[i] - a[j]))  ;
        }
    }

    cout << dp[n - 1] << endl ; 
    return 0 ; 
}



Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable:4996)

int main()
{
	int n, arr[9][9] = { 0 }, flag = 0;
	scanf("%d", &n);

	for (int i = 0; i < 9; i++) {
		for (int j = 0; j < 9; j++) {
			arr[j][i] = (j + 1)*(i + 1);
			if (n == arr[j][i]) {
				flag = 1;
				break;
			}
		}
	}
	if (flag == 1) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>

#define MOD 1000000007
#define ll long long

using namespace std;

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

ll N;

int main(){
  ll inp;
  ll result=1;
  ll a;
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;

  for(ll i =0 ;i< N;i++){
    cin >> inp;
    a = gcd(inp, result);
    result = (result / a) * inp;

  }

  cout << result<< endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int i = (a); i <= (n); i++)
using namespace std;

int main(void) {
  for(int n; cin >> n, n != 0;) {
    bool p[123456 * 2 + 1];
    REP(i, 1, n * 2) p[i] = true;
    p[1] = false;
    p[2] = true;

    REP(i, 2, n * 2) {
      if(p[i]) {
        for(int j = i * 2; j <= n * 2; j += i) {
          p[j] = false;
        }
      }
    }

    int ans = 0;
    REP(i, n + 1, n * 2) {
      if(p[i]) ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

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

char s[3][101]; int n[3], c[3];
int r(int i){
  if(c[i] == n[i]) return i;
  return r(s[i][c[i]++] - 'a');
}

int
main()
{
  for(int i = 0; i < 3; i++){
    scanf("%s", s[i]);
    n[i] = strlen(s[i]);
  }

  printf("%c\n", r(0) + 'A');

  return 0;
}
  


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <set>
using namespace std;
typedef long long i64;
typedef pair<int, int> pii;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, f[2][N]; set<pii> s[2];
i64 move(int &p, int i)
{
    i64 ret = 0; s[0].erase(pii(f[0][i], i)), s[1].erase(pii(f[1][i], i));
    if(f[0][i] <= p&&p <= f[1][i]) return 0;
    else if(p < f[0][i]) ret = f[0][i]-p, p = f[0][i];
    else ret = p-f[1][i], p = f[1][i];
    return ret;
}
i64 solve(int d)
{
    for(int i = 1; i <= n; ++i) s[0].insert(pii(f[0][i], i)), s[1].insert(pii(f[1][i], i));
    i64 ret = 0; int p = 0; set<pii>::iterator it;
    for(int i = 1; i <= n; d ^= 1, ++i) it = d?s[1].begin():--s[0].end(), ret += move(p, it->second);
    return (p>0?p:-p)+ret;
}
int main()
{
    n = read(); for(int i = 1; i <= n; ++i) f[0][i] = read(), f[1][i] = read();
    printf("%lld\n", max(solve(0), solve(1)));
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = LINF;
    for (ll i = 0; i <= max(x, y); i++) {
        chmin(ans, i * 2 * c + max(0ll, x - i) * a + max(0ll, y - i) * b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N := nextInt()
	h := 0
	total := 0
	for i := 0; i < N; i++ {
		a := nextInt()
		if a < h {
			total += h - a
		} else {
			h = a
		}
	}
	fmt.Fprintf(out, "%d\n", total)
}


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

int main()
{
    int N;
    cin >> N;
    int A;
    string ans = "APPROVED";
    for (int i = 0; i < N; i++) {
        cin >> A;
        if (A % 2 == 0) {
            if (A % 3 != 0 && A % 5 != 0) {
                ans = "DENIED";
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
N = int(input())
S = input()
ans = 0
for i in range(10):
    fp = S.find(str(i))
    if fp == -1:
        continue

    for j in range(10):
        sp = S.find(str(j), fp + 1)
        if sp == -1:
            continue

        for k in range(10):
            if str(k) in S[sp + 1:]:
                ans += 1

print(ans)







Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,i,m,sum=0,j,ans=0;
  cin>>n>>m;
  pair<ll,ll> p[n];
  for(i=0;i<n;i++)
  {
  cin>>p[i].first>>p[i].second;
  }
  sort(p,p+n);
  j=0;
  
  /*for(i=0;i<n;i++)
  {
  cout<<p[i].first<<" "<<p[i].second<<endl;
  }
  */
 
  while(sum<m)
  {
    sum+=p[j].second;
    j++;
  }
  //cout<<sum<<" "<<j;
  
  for(i=0;i<=j-1;i++)
  {
    ans+=((p[i].first)*(p[i].second));
  }

  ans-=((sum-m)*(p[j-1].first));
  cout<<ans;
  return 0;
}

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



class union_find {
private:
    vector<ll> par;
    vector<ll> ran;
    vector<ll> m_size;
public:
    union_find(ll n);
    ll find(ll x);
    void unite(ll x, ll y);
    bool same(ll x, ll y);
    ll size(ll x);
};

union_find::union_find(ll n){
    par.resize(n);
    ran.resize(n, 0);
    m_size.resize(n, 1);
    REP(i,n) par[i] = i;
};

ll union_find::find(ll x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll t = size(x)+size(y);
    m_size[x] = m_size[y] = t;
    if (ran[x] < ran[y]) {
        par[x] = y;
        //size[y] += size[x];
    } else {
        par[y] = x;
        //ize[x] += size[y];
        if (ran[x]==ran[y]) ran[x]++;
    }
};

ll union_find::size(ll x) {
    if (par[x] == x) return m_size[x];
    return size(par[x] = find(par[x]));
}

bool union_find::same(ll x, ll y) {
    return (find(x) == find(y));
};


vector<P> a;
set<P> st;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    REP(i,n) {
        ll x,y;
        cin >> x >> y;
        a.emplace_back(x,y);
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i == j) continue;
            st.insert({a[i].first-a[j].first, a[i].second-a[j].second});
        }
    }


    int ans = 0;
    while (!st.empty()) {
        int tmp = 0;
        auto itr = st.begin();
        P p = *itr;
        st.erase(itr);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (i == j) continue;
                if (a[i].first-a[j].first == p.first && a[i].second-a[j].second == p.second) tmp++;
            }
        }
        ans = max(ans, tmp);
    }
    
    cout << n-ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define debug(a,b) cerr << #a<<" = "<<a<<"   |   "<<#b<<" = "<<b<<'\n'
#define endl '\n'
#define SZ(x) (int)x.size()
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const ll MX = 1e5+10, inf = 1e9 + 7;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	string s,t;
	cin>>s>>t;
	s+=t.back();
	if(s==t)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}




Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

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

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

vector<vector<int> > G;
vector<vector<int> > T;
vector<int> V;

void build(int a, int p) {
    for (int i = 0;i < G[a].size();i++) {
        if (G[a][i] == p) continue;
        T[a].push_back(G[a][i]);
        build(G[a][i], a);
    }
    return;
}

int cal(int n) {
    if (V[n] != 0) return V[n];
    if (T[n].size() == 0) {
        V[n] = 1;
        return 1;
    }
    int v = 0;
    int t[31];
    memset(t, 0, sizeof(t));
    for (int i = 0;i < T[n].size();i++) {
        int z = cal(T[n][i]);
        int x = 1;
        for (int j = 0;j < 31;j++) {
            if (z & x) t[j]++;
            x *= 2;
        }
    }
    int m_v = -1;
    for (int i = 0;i < 31;i++) {
        if (t[i] > 1) m_v = i;
    }
    m_v++;
    for (int i = m_v;i < 31;i++) {
        if (t[i] == 0) {
            for (int j = 0;j < i;j++) t[j] = 0;
            t[i] = 1;
            break;
        }
    }
    int sol = 0;
    for (int i = 0;i < 31;i++) {
        if (t[i]) sol += (1 << i);
    }
    V[n] = sol;
    return sol;
}

int main() {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    G.resize(N);
    for (int i = 1;i < N;i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    T.resize(N);
    build(0, -1);
    V.resize(N, 0);
    int v = cal(0);
    int x = 1;
    int sol = 0;
    for (int i = 0;i < 31;i++) {
        if (v & x) sol = i;
        x *= 2;
    }
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 24192
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    int n;
    cin>>n;
    vint a(n);
    cin>>a;
    int ans = 0;
    REP(i, n) {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1){
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
int main() {
	string S, T;
	cin >> S >> T;
	sort(S.begin(), S.end());
	sort(T.begin(), T.end(), greater<char>());
	if (S < T) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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


int main() {
	vector<int> data(3);
	cin >> data.at(0)>>data.at(1)>>data.at(2);
	sort(data.begin(), data.end());
	if ((data.at(0) == data.at(1) && data.at(0) != data.at(2)) || (data.at(2) == data.at(1) && data.at(0) != data.at(1))) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3576
s= input()
z=len(s)//2
flag=0
sd=s[0:z]
if len(s)==3:
    if s[0]==s[2]:
        flag=1
else:
    if sd==s[z+1:len(s)]:
        if sd==sd[::-1]:
            flag=1
if flag==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
int parent(int);
int left(int);
int right(int);
void buildMaxHeap(int*,int);
void maxHeapify(int*,int,int);
void swap(int*,int,int);
void printHeap(int*,int);
int main(void)
{
  int i;//counter
  int n;//the size of heap
  int *arr;//array (1-origin)
  scanf("%d",&n);
  arr=(int*)malloc(sizeof(int)*(n+1));
  for(i=1;i<=n;i++) scanf("%d",&arr[i]);
  buildMaxHeap(arr,n);
  printHeap(arr,n);
  return 0;
}
int parent(int i)
{
  return i/2;
}
int left(int i)
{
  return 2*i;
}
int right(int i)
{
  return 2*i+1;
}
void buildMaxHeap(int *arr,int n)
{
  int i;//counter
  for(i=n/2;i>=1;i--) maxHeapify(arr,i,n);
}
void maxHeapify(int *arr,int i,int n)
{
  int l=left(i);
  int r=right(i);
  int largest;
  if(l<=n&&arr[l]>arr[i]) largest=l;
  else largest=i;
  if(r<=n&&arr[r]>arr[largest]) largest=r;
  if(largest!=i)
    {
      swap(arr,i,largest);
      maxHeapify(arr,largest,n);
    }
}
void swap(int *arr,int x,int y)
{
  int temp;
  temp=arr[x];
  arr[x]=arr[y];
  arr[y]=temp;
}
void printHeap(int *arr,int n)
{
  int i;
  for(i=1;i<=n;i++) printf(" %d",arr[i]);
  printf("\n");
}



Measured memory_bytes: 3688
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

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

class AServalVsMonster {
 public:
  void solveOne(std::istream &in, std::ostream &out) {
    int n, k;
    in >> n >> k;

    out << (n + k - 1) / k << endl;
  }
  void solve(std::istream &in, std::ostream &out) {
    int nt = 1;
    for (int i = 0; i < nt; ++i)
      solveOne(in, out);
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  AServalVsMonster solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

void maxHeapify(int i){int l, r, largest;
  l = 2*i;
  r = 2 * i +1;

  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int extract(){
  int max;
  if(H < 1) return -INFTY;
  max = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return max;
}

void increaseKey(int i, int key){
  if(key < A[i]) return;
  A[i] = key;
  while(i > 1 && A[i/2] < A[i]){
    swap(A[i], A[i/2]);
    i = i/2;
  }
}

void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s", com);
    if(com[0] == 'e' && com[1] == 'n') break;
    if(com[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    }
    else{
      printf("%d\n", extract());
    }
  }

  return 0;
}



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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<long long> x(0);
  x.push_back(a * c);
  x.push_back(a * d);
  x.push_back(b * c);
  x.push_back(b * d);
  long long ans = x.at(0);
  rep(i, x.size()) if (x.at(i) > ans) ans = x.at(i);
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;
const string YES = "Yes";
const string NO = "No";

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  int two = 0, four = 0;
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &a[i]);
    if (a[i] % 4 == 0)
      four++;
    else if (a[i] % 2 == 0)
      two++;
  }
  N -= 2 * four + 1;
  if (two / 2 * 2 >= N)
    cout << YES << endl;
  else
    cout << NO << endl;

  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,k;
Vi x,y;
vector<PLL> v;


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>k;
    x.resize(n); y.resize(n);
    v.resize(n);
    rep(i,n){
        cin>>x[i]>>y[i];
        v[i] = mp(x[i],y[i]);
    }
    ll ans = INT64_MAX;
    ll tmp = 0;
    ll mx;ll my;ll ix;ll iy;
    rep(i,n){
        repi(j,i+1,n){
            rep(ii,n){
                repi(jj,ii+1,n){
                    ll mx = max(x[i],x[j]);
                    ll ix = min(x[i],x[j]);
                    ll my = max(y[ii],y[jj]);
                    ll iy = min(y[ii],y[jj]);
                    tmp  = 0;
                    rep(kk,n){
                        ll _x = v[kk].first;
                        ll _y = v[kk].second;
                        if(_x >= ix && _x <= mx){
                            if(_y >= iy && _y <= my){
                                tmp++;
                            }
                        }
                    }
                    if(tmp>=k){
                        chmin(ans,(mx-ix)*(my-iy));
                    }
                }
            }
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
import math
N, M = map(int, input().strip().split())
st= min(M//N,int(math.sqrt(M)))
cand=0
if M//N <= int(math.sqrt(M)):
    for i in range(M//N,0,-1):
        if M%i==0:
            print(i)
            break
else:
    for i in range(1,int(math.sqrt(M)),1):
        if M%i==0:
            if M//N >= i:
                cand=max(cand,i)
            if M//N >= M//i:
                cand=max(cand,M//i)
    print(cand)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }

const ll INF=1e18;

struct edge{ll to,cost;};


struct PP{
    ll min_d,vert;
};

bool operator> (const PP &p1, const PP &p2){
    return p1.min_d > p2.min_d;
};


class Dijkstra{
public:
    ll n;//頂点数,辺数
    V<V<edge>> G;
    V<ll> d;
    V<ll> pr;

    explicit Dijkstra(ll sz_n){
        n=sz_n;
        G.resize(sz_n);
        d.resize(sz_n);
        pr.resize(sz_n);
    }

    void add_edge(ll from,ll to,ll cost){
        G[from].push_back((edge){to,cost});
        G[to].push_back((edge){from,cost});//有向辺の場合は削除
    }

    void exe(ll s){//頂点sからの最短距離
        priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> que;
        rep(i,n) d[i]=INF;
        d[s]=0;
        que.push(make_pair(0,s));//pair...first->最短距離、second->頂点

        while(!que.empty()){
            pair<ll,ll> p=que.top();que.pop();
            ll v=p.second;
            if(d[v]<p.first) continue;
            for(int i=0;i<(int)G[v].size();i++){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(make_pair(d[e.to],e.to));
                    pr[e.to]=v;
                }
            }
        }
    }

    ll dist_to(ll t){
        return d[t];
    }

    //頂点tへの最短路
    vector<ll> get_path(ll t){
        vector<ll> path;
        for(;t!=-1;t=pr[t]) path.push_back(t);//tがsになるまでprev[t]をたどっていく
        reverse(all(path));
        return path;
    }

};


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    Dijkstra ds(n);
    rep(i,n-1){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        ds.add_edge(a,b,c);
    }
    int Q;ll k;
    cin>>Q>>k;
    k--;
    ds.exe(k);
    while(Q--){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        out(ds.dist_to(x)+ds.dist_to(y));
    }
}


Measured memory_bytes: 14808
n = int(input())
a = list(map(int,input().split()))
Flag = True
for i in a:
    if i%2 == 0 and (i%3 == 0 or i%5 == 0):
        continue
    elif i%2 == 0 and (i%3 != 0 or i%5 != 0):
        Flag = False

if Flag == True:
    print("APPROVED")
else:
    print("DENIED")

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const ll inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n, m; cin >> n >> m;
    ll Q; cin >> Q;
    vector<ll> a(Q); cin >> a; REP(i, Q) a[i]--;
    vector<ll> seq = [&]() {
        set<ll> used;
        vector<ll> res;
        RREP(i, Q) {
            if (used.count(a[i]) == 0) {
                res.pb(a[i]);
                used.insert(a[i]);
            }
        }
        REP(i, m) if ( used.count(i) == 0 ) res.pb(i);
        return res;
    }();

    vector<ll> rseq(m); REP(i, m) rseq[seq[i]] = i;
    vector<ll> cnt(m+1, 0); cnt[0] = n;
    // int skipped = 0;
    RREP(i, Q) {
        ll pos = rseq[a[i]];
        if (cnt[pos] > 0) --cnt[pos], ++cnt[pos+1];
        // else ++skipped;
    }
    bool ans = true;
    // if (skipped > 0 && cnt[m] == 0 && cnt[m-1] == 0) {
    //     ans = false;
    // }
    // cout << seq << endl;
    // cout << cnt << endl;
    // cout << def << endl;
    REP(i, m) {
        if (cnt[i] > 0) {
            FOR(j, i, m-1) {
                if (seq[j+1] < seq[j]) ans = false;
            }
            break;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 6516
import bisect

def main():
    A = []
    length = 0
    
    for i in range(int(input())):
        a = int(input())
    
        idx = bisect.bisect_left(A, a)
        
        if idx == length:
            A.append(a)
            length += 1
            
        else: A[idx] = a
        
    print(length)
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 9672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string s;
int main(){
	cin>>s;
	int a=0,b=0;
	rep(i,s.size()){
		if(i%2 == 0){
			if(s[i] == '1') a++;
			else b++;
		}
		else{
			if(s[i] == '0') a++;
			else b++;
		}
	}
	cout<<min(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, m;
    cin >> n >> m;
    fore(i,1,n+1) fore(j,1,m+1) {
        cin >> grid[i][j];
    }
    fore(i,1,n+1) fore(j,1,m+1) {
        if (grid[i][j] == '.') {
            char cnt = '0';
            fore(k,0,8) {
                if (grid[i+dy[k]][j+dx[k]] == '#') {
                    cnt++;
                }
            }
            grid[i][j] = cnt;
        }
    }
    fore(i,1,n+1) {
        fore(j,1,m+1) cout << grid[i][j];
        cout << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define MAX 10000000000
#define rep(i,n) for(int i = 0; i < n;i++)
ll v, n, c, e, u, k, ans = 0,sum;
int main(void) {
	int n,m,k, b;cin >> n >> m;
	vector<int > a(m);
	rep(i, n) {
		cin >> k;
		rep(j, k) {
			cin >> b;b--;
			a[b]++;
		}
	}
	rep(i, m) {
		if (a[i] == n) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll t;
  cin >> t;

  for(ll i=0;i<t;i++){
    ll n,m,a,b;
    cin >> n >> m >> a >> b;
    cout << floor_sum(n,m,a,b) << endl;
  }

}

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

int main(){
   int i,j,H,W;

   while(1){

	cin >> H >> W;

	if((H == 0)&&(W == 0)) break;

   	for(i=0;i<H;i++){

		for(j=0;j<W;j++){
			cout << "#";
		}

		cout << endl;

  	 }

	cout << endl;
   }

   return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll mx=INT_MAX;
ll mn=INT_MIN;

int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll i;
    for(i=0;i<n;i++)
        cin>>a[i];
    ll dp[n];
    for(i=0;i<n;i++)
        dp[i]=mx;
    dp[0]=0;
    for(i=1;i<n;i++)
    {
        for(ll j=max(0ll,i-k);j<i;j++)
            dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

class D
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var s = Console.ReadLine();
		int n = h[0], k = h[1];

		if (n == 1) { Console.WriteLine(0); return; }
		var x = Enumerable.Range(1, n - 2).Count(i => s[i] == 'L' ? s[i - 1] == 'L' : s[i + 1] == 'R');
		if (s.StartsWith("RR")) x++;
		if (s.EndsWith("LL")) x++;

		var f = Enumerable.Range(0, n - 1).Count(i => s[i] == 'R' && s[i + 1] == 'L');
		if (s[0] == s[n - 1])
		{
			x += 2 * Math.Min(k, f);
		}
		else if (s[0] == 'L')
		{
			x += 2 * Math.Min(k, f);
			if (k > f) x++;
		}
		else
		{
			x += 2 * Math.Min(k, f - 1);
			if (k >= f) x++;
		}
		Console.WriteLine(x);
	}
}


Measured memory_bytes: 13920
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
/*----------------------------------------------------------------------------------*/


int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

    vector<vector<bool>> ok(h, vector<bool>(w,false));
    
    // h->h, w->w, grid[][]->s[][]
    auto bfs = [&](int sy, int sx) -> ll {
        ll a = 1, b = 0;
        queue<pair<int, int>> que;
        que.push(make_pair(sy, sx));
        ok[sy][sx] = true;
        while(!que.empty()) {
            pair<int, int> cur = que.front(); que.pop();
            int y = cur.first, x = cur.second;
            for(int i = 0; i < 4; ++i) {
                int ny = y + dy[i], nx = x + dx[i];
                if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
    
                if(ok[ny][nx]) continue;
    
                if((s[ny][nx] == '.' && s[y][x] == '#') || (s[ny][nx] == '#' && s[y][x] == '.')) {
                    // cout << ny << ' ' << nx << endl;
                    que.push(make_pair(ny, nx));
                    ok[ny][nx] = true;
                    if (s[ny][nx] == s[sy][sx]) a++;
                    else b++;
                }
            }
        }
        return a*b;
    };

    ll ans = 0;
    rep(i,h) rep(j,w) {
        if (!ok[i][j]) ans += bfs(i,j);
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		double[] a = new double[n];
		double sum = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextDouble();
			sum += a[i];
		}
		int ans = 0;
		for(int i = 0; i < n; i++) {
			if(sum / (4 * m) <= a[i])
				ans++;
		}
		System.out.println(ans >= m ? "Yes" : "No");

	}

}


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

int main() {
  string s; cin >> s;
  rep(i,3) cout << s[i];
  cout << endl;
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int n = Integer.parseInt(chr[0]);
			int a = Integer.parseInt(chr[1]);
			int b = Integer.parseInt(chr[2]);
			System.out.println(Math.min(n*a, b));

		}
	}
}

Measured memory_bytes: 25388
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 

double dist(double a, double b) {
	return a*a + b*b;
}

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

   int n;  cin>>n;
  vector<double>x(1005), y(1005) ;
   double X,Y,d,e;  
  
   cout<<setprecision(15)<<fixed;
  for (int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		X += x[i]; Y += y[i];
	}
	X/=n; Y/=n;
	double P=0.1;
	for(int i=0;i<30000;i++) {
		int f=0;
		d =dist(X-x[0],Y-y[0]);
		for(int j=1;j<n;j++){
			e = dist(X-x[j],Y-y[j]);
			if(d<e)
            {d=e; f=j;}
		}
		X+=(x[f]-X)*P;
		Y+=(y[f]-Y)*P;
		P*=0.999;
	}
	cout<<sqrt(d);

}




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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int tot = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        tot += a[i];
    }
    sort(a.begin(), a.end());
    bool ok = true;
    for (int i = 0; i < m; i++) {
        if (4 * m * a[n-1-i] < tot) {
            ok = false;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}



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

int x;
bool dp[1000200];

int main() {
    cin >> x;
    for (bool &i : dp) i = false;
    for (int i = 100; i <= 105; i++) dp[i] = true;
    for (int i = 0; i <= 1000000; i++) {
        if (dp[i]) {
            for (int j = 100; j <= 105; j++) dp[i+j] = true;
        }
    }
    cout << (dp[x] ? 1 : 0) << endl;
    return 0;
}

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

using namespace std;

int a,b;
string s;

bool valid() {
	for(int i = 0; i < s.size(); i++) {
		if(i == a) {
			if(s[i] != '-')
				return false;
		}
		else {
			if(!isdigit(s[i]))
				return false;
		}

	}
	return true;
}

int main() {
	cin >> a >> b >> s;
	cout << (valid() ? "Yes" : "No") << endl;
}

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

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{
  long n;

  cin >> n;//-9のとき

  // -2^n= 1, ,-2, 4 , -8
  long p = abs(n);


  string s = "";
  p -= 1;
  // long p2 = p - 1;
  long div = 2;
  long c = 0;
  long count = 1;
  if (n < 0) {
    while (true) {//p2=8
      if ((p - c) % div < div / 2)s += "1";
      if ((p - c) % div >= div / 2)s += "0";
      div *= 2;
      // cout <<s <<endl;
      if ( (p - c) % div < div / 2)s += "1";
      if ( (p - c) % div >= div / 2)s += "0";
      div *= 2;
      c += pow(2, count);
      count += 2;
      // cout <<s <<endl;
      if (c > p)break;
    }
  } else if (n > 0) {


    count = 0;
    c = 0;
    while (true) {//p2=8
      if ((p - c) % div < div / 2)s += "1";
      if ((p - c) % div >= div / 2)s += "0";
      div *= 2;
      c += pow(2, count);
      count += 2;
      if (c > p)break;
      // cout <<s <<endl;
      if ( (p - c) % div < div / 2)s += "1";
      if ( (p - c) % div >= div / 2)s += "0";
      div *= 2;

    }



  } else {
    s = "0";
  }




  reverse(s.begin(), s.end());


  cout << s;
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    
    int N;
    cin >> N;
   
    vector<int> cnt(N, 0);
    for (int i = 0; i < N-1; ++i) {
       int x;
       cin >> x;
       ++cnt[x-1];
    }
    for (int v: cnt)
        cout << v << endl;

    
    return 0;
}


Measured memory_bytes: 3988
fun main(args: Array<String>) {
    abc048b()
}

fun abc048b() {
    val (a, b, x) = readLine()!!.split(" ").map { it.toLong() }

    val answer = (b / x) + 1 - (if (a == 0L) 0 else (a - 1) / x + 1)

    println(answer)
}


Measured memory_bytes: 38008
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
#define ll long long
int main()
{
    int N,M;
    char s[105][15],t[105][15],a[105][15];
    int book[105];
    memset(book,0,sizeof(book));
    scanf("%d",&N);
    scanf("%s",s[0]);
    int p=0;
    book[0]=1;
    strcpy(a[0],s[0]);
    for(int i=1;i<N;i++)
    {
        scanf("%s",s[i]);
        int flag=0;
        for(int j=0;j<=p;j++)
        {
            if(strcmp(a[j],s[i])==0)
            {
                book[j]++;
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            p++;
            strcpy(a[p],s[i]);
            book[p]++;
        }
    }
    scanf("%d",&M);
    for(int j=0;j<M;j++)
    {
        scanf("%s",t[j]);
        for(int i=0;i<=p;i++)
        {
            if(strcmp(a[i],t[j])==0)
            {
                book[i]--;
                break;
            }
        }
    }
    int max=-1;
    for(int i=0;i<=p;i++)
    {
        if(book[i]>max)
            max=book[i];
    }
    if(max<0)
        max=0;
    printf("%d\n",max);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
int n, m, cnt[44];
char s[1000010];
string c[N];
int mp1[5761455], mp2[5761537], mp3[5761543], mp4[5705543], mp5[5703199];
int main(){
	scanf("%d",&n);
	ll ans=0, mod1=5761455, mod2=5761537, mod3=5761543, mod4=5705543, mod5=5703199;
	for(int i=0; i<n; ++i){
		scanf("%s",s);
		int sz=strlen(s);
		c[i]=s;
		int hsh2=0, hsh1=0, hsh3=0, hsh4=0, hsh5=0;
		for(int j=sz-1; j>=0; --j){
			hsh1*=29;
			hsh1+=s[j]-'a'+1;
			hsh1%=mod1;
			hsh2*=31;
			hsh2+=s[j]-'a'+1;
			hsh2%=mod2;
			hsh3*=37;
			hsh3+=s[j]-'a'+1;
			hsh3%=mod3;
			hsh4*=41;
			hsh4+=s[j]-'a'+1;
			hsh4%=mod4;
			hsh5*=43;
			hsh5+=s[j]-'a'+1;
			hsh5%=mod5;
		}
		++mp1[hsh1];
		++mp2[hsh2];
		++mp3[hsh3];
		++mp4[hsh4];
		++mp5[hsh5];
	}
	for(int i=0; i<n; ++i){
		int sz=c[i].size();
		for(int j=0; j<26; ++j)
			cnt[j]=0;
		for(int j=0; j<sz; ++j){
			++cnt[c[i][j]-'a'];
		}
		ll hsh3=0, hsh4=0, hsh1=0, hsh2=0, tmp1, tmp2, tmp3, tmp4, hsh5=0, tmp5;
		for(int j=sz-1; j>=0; --j){
			for(int k=0; k<26; ++k){
				if(cnt[k]){
					tmp1=hsh1*29;
					tmp1+=k+1;
					tmp1%=mod1;
					tmp2=hsh2*31;
					tmp2+=k+1;
					tmp2%=mod2;
					tmp3=hsh3*37;
					tmp3+=k+1;
					tmp3%=mod3;
					tmp4=hsh4*41;
					tmp4+=k+1;
					tmp4%=mod4;
					tmp5=hsh5*43;
					tmp5+=k+1;
					tmp5%=mod5;
					ans+=min(min(min(mp3[tmp3], mp4[tmp4]),min(mp1[tmp1], mp2[tmp2])), mp5[tmp5]);
				}
			}
			hsh1*=29;
			hsh1+=c[i][j]-'a'+1;
			hsh1%=mod1;
			hsh2*=31;
			hsh2+=c[i][j]-'a'+1;
			hsh2%=mod2;
			hsh3*=37;
			hsh3+=c[i][j]-'a'+1;
			hsh3%=mod3;
			hsh4*=41;
			hsh4+=c[i][j]-'a'+1;
			hsh4%=mod4;
			hsh5*=43;
			hsh5+=c[i][j]-'a'+1;
			hsh5%=mod5;
			--cnt[c[i][j]-'a'];
		}
	}
	ans-=n;
	cout<<ans<<endl;
}


Measured memory_bytes: 123584