akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<ll>& vec) {
    for (ll value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    int N; cin >> N;
    vector<ll> A(N + 1), B(N);
    rep(i, N+1) cin >> A[i];
    rep(i, N) cin >> B[i];

    ll P = 0, Q = 0;

    rep(i, N + 1) P += A[i];

    rep(i, N) {
        ll x = A[i];
        ll y = B[i];
        A[i] = max(A[i]-y, (ll)0);
        B[i] = max(B[i] - x, (ll)0);
        A[i + 1] = max(A[i+1]-B[i], (ll)0);
    }

    rep(i, N + 1) Q += A[i];

    cout << P - Q << endl;

}

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

int n, cnt=0;
long long d;
string s;

int main()
{
    cin >> n >> d;
    for(int i = 0; i < n; i++)
    {
        long long a, b;
        cin >> a >> b;
        if(sqrt(a*a+b*b)<=d)cnt++;
    }
    cout << cnt;
}



Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] harr = new long[N];

        for (int i=0; i<N; i++) {
            harr[i] = scanner.nextLong();
        }

        int result = 0;
        for (int i=0; i< N-1; i++) {
            if (result >= (N-1 - i)) break;
            int tmp = 0;
            for (int k=i; k< N-1; k++) {
                if (harr[k] >= harr[k+1]) {
                    tmp++;
                } else {
                    break;
                }
            }
            if (tmp > result) {
                result = tmp;
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 50692
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  if (a < b) {
    return b - a;
  } else {
    return a - b;
  }
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a) {
    a = b;
  }
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b) {
    a = b;
  }
}
template <class F> class fix_point : private F {
public:
  explicit constexpr fix_point(F &&f) : F(std::forward<F>(f)) {}

  template <class... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};
template <class F> constexpr decltype(auto) make_fix(F &&f) {
  return fix_point<F>(std::forward<F>(f));
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  u64 h = scan<u64>();
  u64 c = 1;
  u64 ans = 0;
  while (h != 0) {
    ans += c;
    c *= 2;
    h /= 2;
  }
  std::cout << ans << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    ll c[10][10], A;
    ll H, W;
    cin >> H >> W;
    ll i, j, k;
    ll ans=0;
    for(i=0; i<=9; i++) {
        for(j=0; j<=9; j++) {
            cin >> c[i][j];
        }
    }
    
    for(k=0; k<10; k++) {
        for(i=0; i<10; i++) {
            for(j=0; j<10; j++) {
                if(c[i][j]>c[i][k]+c[k][j])
                    c[i][j]=c[i][k]+c[k][j];
            }
        }
    }
    
    for(i=1; i<=H; i++) {
        for(j=1; j<=W; j++) {
            cin >> A;
            if(A>=0)
                ans+=c[A][1];
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int l,r;
	cin>>l>>r;
	if((r/2019)-(l/2019)>0) {
		cout<<0;
	} else {
		ll mi = 2019;
		for(ll i=l;i<=min(r,l+2030);i++) {
			for(ll j=i+1;j<=min(r,l+2030);j++) {
				mi = min(mi,(i*j)%((ll)2019));
			}
		}
		cout<<mi;
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

int main()
{
    string S; cin >> S;

    string ans = "YES";
    while (S.length() > 0)
    {
        if (S.substr(S.length() - 5) == "dream")
        {
            S = S.substr(0, S.length() - 5);
        }
        else if (S.substr(S.length() - 5) == "erase")
        {
            S = S.substr(0, S.length() - 5);
        }
        else if (S.substr(S.length() - 6) == "eraser")
        {
            S = S.substr(0, S.length() - 6);
        }
        else if (S.substr(S.length() - 7) == "dreamer")
        {
            S = S.substr(0, S.length() - 7);
        }
        else
        {
            ans = "NO";
            break;
        }
    }

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

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

#define W 100
#define H 100
#define MAX(A,B) \
  ( (B) > (A) ? (B) : (A) )

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i, j, k;

  for ( ; ; )
  {
    int d[ W + 1 ][ H + 1 ] = { };
    int w, h, s, t;
    int res = 0;
    int n;

    scanf ( "%d", &n );
    if ( n == 0 ) break ;
    scanf ( "%d%d", &w, &h );
    while ( n-- )
    {
      int x, y;

      scanf ( "%d%d", &x, &y );
      d[ x ][ y ] = 1;
    }
    for ( i = 1; i <= w; ++i )
    for ( j = 1; j <= h; ++j )
      d[ i ][ j ] += d[ i ][ j - 1 ];
    scanf ( "%d%d", &s, &t );

    for ( i = 1; i + s - 1 <= w; ++i )
    for ( j = 0; j + t <= h; ++j )
    {
      int tmp = 0;

      for ( k = i; k <= i + s - 1; ++k )
        tmp += d[ k ][ j + t ] - d[ k ][ j ];

      res = MAX( res, tmp );
    }

    printf ( "%d\n", res );
  }

  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 648
using System;

	public class Class1
	{
		public static void Main(String[] args)
		{
			string data=Console.ReadLine();
			string[] xxyy=data.Split();
			double x1=double.Parse(xxyy[0]);
			double y1=double.Parse(xxyy[1]);
			double x2=double.Parse(xxyy[2]);
			double y2=double.Parse(xxyy[3]);
			double a=x2-x1;
			double b=y2-y1;
			double c=a*a+b*b;
			Console.WriteLine(Math.Sqrt(c));
			
		}
	}

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

int cnt;

void print_vector(vector<int> A, int N)
{
    for (int i = 0; i < N; i++)
    {
        cout << A.at(i) << endl;
    }
}

void insertion_sort(vector<int> &A, int N, int g)
{
    int i, j, v;
    for (i = g; i < N; i++)
    {
        v = A.at(i);
        j = i - g;
        while (j >= 0 && A.at(j) > v)
        {
            A.at(j + g) = A.at(j);
            j -= g;
            cnt++;
        }
        A.at(j + g) = v;
    }
}

void shell_sort(vector<int> &A, int N)
{
    cnt = 0;
    vector<int> G;
    for (int g = 1; g <= N;)
    {
        G.push_back(g);
        g = 3 * g + 1;
    }

    int m = G.size();
    cout << m << endl;
    for (int i = m - 1; i >= 0; i--)
    {
        if (i != m - 1)
            cout << " ";
        cout << G.at(i);
        if (i == 0)
            cout << endl;
        insertion_sort(A, N, G.at(i));
    }
    cout << cnt << endl;
}

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

    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A.at(i);

    shell_sort(A, N);

    print_vector(A, N);
}


Measured memory_bytes: 10716
#include <stdio.h>
int main(void)
{
  int a,b;
  scanf("%d %d",&a,&b);
  if (a == b){
    printf("a == b\n");
  } else if (a < b){
    printf("a < b\n");
  }else{
    printf("a > b\n");
  }
  return 0;
}


Measured memory_bytes: 2544
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;


int main(){

	int A,B,D,ans_minus,ans_plus,w_num,sum,ans_x,ans_y,ans_reverse;
	bool FLG;

	while(true){
		scanf("%d %d %d",&A,&B,&D);
		if(A == 0 && B == 0 && D == 0)break;

		ans_minus = -1,ans_plus = -1,ans_reverse = -1,w_num = -1;
		for(int x = 0;ans_minus == -1 || ans_plus == -1;x++){

			FLG = false;
			if(ans_reverse == -1){
				FLG = true;
				if((D-A*x < 0) || (w_num != -1 && x > w_num)){
					ans_reverse = 999;
				}else if((D-A*x)%B == 0){
					if(w_num != -1){
						if((x + (D-A*x)/B < w_num) || (x + (D-A*x)/B == w_num && A*x + B*((D-A*x)/B) < sum)){
							w_num = x + (D-A*x)/B;
							ans_x = x;
							ans_y = (D-A*x)/B;
							sum = A*x + B*((D-A*x)/B);
						}
					}else{
						w_num = x + (D-A*x)/B;
						ans_x = x;
						ans_y = (D-A*x)/B;
						sum = A*x + B*((D-A*x)/B);
					}
				}
			}

			if(ans_minus == -1){
				FLG = true;
				if(A*x >= D && (A*x-D)%B == 0){
					ans_minus = (A*x-D)/B;
					if(w_num != -1){
						if((x+ans_minus < w_num) || (x+ans_minus == w_num && (A*x+B*ans_minus) < sum)){
							ans_x = x;
							ans_y = ans_minus;
							w_num = x + ans_minus;
							sum = A*x+B*ans_minus;
						}
					}else{
						ans_x = x;
						ans_y = ans_minus;
						w_num = x + ans_minus;
						sum = A*x+B*ans_minus;
					}
				}
			}else{
				if(x + (A*x+D)/B > w_num || (x + (A*x+D)/B == w_num && A*x+B*((A*x+D)/B)) > sum){
					ans_plus = 999;
				}
			}

			if(ans_plus == -1){
				FLG = true;
				if((A*x+D)%B == 0){
					ans_plus = (A*x+D)/B;
					if(w_num != -1){
						if((x+ans_plus < w_num) || (x+ans_plus == w_num && (A*x+B*ans_plus) < sum)){
							ans_x = x;
							ans_y = ans_plus;
							w_num = x + ans_plus;
							sum = A*x+B*ans_plus;
						}
					}else{
						ans_x = x;
						ans_y = ans_plus;
						w_num = x + ans_plus;
						sum = A*x+B*ans_plus;
					}
				}
			}else{
				if(x + (A*x-D)/B > w_num || (x + (A*x-D)/B > w_num && A*x+B*((A*x-D)/B)) > sum){
					ans_minus = 999;
				}
			}
			if(!FLG)break;
		}

		printf("%d %d\n",ans_x,ans_y);

	}

    return 0;
}

Measured memory_bytes: 2660
#include <stdio.h>
int main(void){
    int a, b;
    
    scanf("%d %d", &a, &b);
    
    if(a % 2 == 0 || b % 2 == 0){
        printf("No\n");
    }else if(a % 2 != 0 && b % 2 != 0){
        printf("Yes\n");
    }
    
}


Measured memory_bytes: 1600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    if (n == 1) {
        cout << "1\n1\n";
        return 0;
    } else if (n == 2) {
        cout << "2\n0\n11\n";
        return 0;
    }
    cout << n - 1 << "\n";
    rep (i, n) cout << 0; cout << "\n";
    rep (i, n - 2) {
        if (n - 2 * i - 2>= 0) {
            rep (j, n - 2 * i - 2) cout << 0;
            cout << 1;
            rep (j, i) cout << 0;
            cout << "\n";
        } else {
            cout << 1;
            rep (j, n - i - 3) cout << 0;
            cout << "1\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;

int main(){
    ll h;
    cin >> h;
    ll monster = 1;
    ll number = 0;
    while(true){
        if(h ==1){
            number+=monster;
            break;
        }
        else{
            if(h%2 == 0){
                h /= 2;
                number += monster;
                monster *= 2;
            }else{
                h = (h-1)/2;
                number += monster;
                monster *= 2;
            }
        }
    }

    cout << number << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int sum;
  while(cin >> str && str!="0"){
    sum = 0;
    for(int i=0,l=str.size();i<l;i++) sum += str[i]-'0';
    cout << sum << endl;
  }
}

Measured memory_bytes: 1188
module Main where

import Data.Functor
import Data.Char

main :: IO ()
main =  do
  { [n]   <- getInts
  ; (t,h) <- turn n (0,0)
  ; putStrLn $ unwords $ map show [t,h]
  }

turn :: Int -> (Int, Int) -> IO (Int, Int)
turn 0 th = return th
turn n (t,h) = do
  { [ts,hs] <- words <$> getLine
  ; case compare ts hs of
      LT -> turn (n-1) (t,h+3)
      EQ -> turn (n-1) (t+1,h+1)
      GT -> turn (n-1) (t+3,h)
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

Measured memory_bytes: 4068
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<climits>
#include<numeric>
#include<deque>
#include<queue>
#include <utility>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

typedef queue<int> IntQueue;

int N,M;
const int MAX=16;
int A[MAX][MAX];
int visited[MAX];

void solve(){
  cin>>N>>M;
  int a,b;
  for(int i=0;i<M;i++){
    cin>>a>>b;
    A[a][b]=1;
    A[b][a]=1;
  }
  vector<int> idx(N-1);
  iota(idx.begin(),idx.end(),0);
  for(int i=2;i<N+1;i++){
    idx[i-2]=i;
  }
  int pre;
  int cnt=0;
  bool flag;
  do{
    pre=1;flag=true;
    for(int i=0;i<N-1;i++){
      if (!A[pre][idx[i]]){
        flag=false;
        break;
      }
      pre=idx[i];
    }
    if (flag)cnt++;
  }while(next_permutation(idx.begin(),idx.end()));
  cout<<cnt<<endl;
  return;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll ans;
    for(ll i=0;i*i<=n;i++){
      ans=i*i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int maze[25][25];
int mark[25][25];
int wayx[] = {0, 0, 1, -1};
int wayy[] = {1, -1, 0, 0};
struct node{
    int i, j;
    node(int a, int b) {
        i = a;
        j = b;
    }
};
int bfs(int x, int y, int ex, int ey, int h, int w) {
    memset(mark, 0, sizeof(mark));
    queue<node> qe;
    qe.push(node(x, y));
    mark[x][y] = 1;
    int i = 0, j = 0;
    while(!qe.empty()) {
        i = qe.front().i, j = qe.front().j;
        qe.pop();
        for(int n = 0; n < 4; ++ n) {
            if(i + wayx[n] >= 0 && i + wayx[n] < h && j + wayy[n] >= 0 && j + wayy[n] < w) {
                if(!mark[i + wayx[n]][j + wayy[n]] && maze[i + wayx[n]][j + wayy[n]]) {
                    mark[i + wayx[n]][j + wayy[n]] = mark[i][j] + 1;
                    qe.push(node(i + wayx[n], j + wayy[n]));
                }
            }
        }
    }
    // for(int _i = 0; _i < h; ++ _i) {
    //     for(int _j = 0; _j < w; ++ _j) {
    //         cout << mark[_i][_j] << " ";
    //     }
    //     cout << endl;
    // }
    return mark[ex][ey] - 1;
}
int main() {
    int h, w;
    cin >> h >> w;
    memset(maze, 0, sizeof(maze));
    for(int i = 0; i < h; ++ i) {
        string input;
        cin >> input;
        for(int j = 0; j < w; ++ j) {
            if(input[j] == '.') maze[i][j] = 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < h; ++ i) {
        for(int j = 0; j < w; ++ j) {
            for(int k = 0; k < h; ++ k) {
                for(int l = 0; l < w; ++ l) {
                    if(maze[i][j] && maze[k][l]) {
                        ans = max(bfs(i, j, k, l, h, w), ans);
                        // cout << ans << endl;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    // system("pause");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#define eps 1e-8
#define double long double

using namespace std;
typedef pair<double, pair<int, int> > Event;

struct vec3d{
	double x, y, z;
	vec3d(){}
	vec3d(double x, double y, double z){
		this->x = x, this->y = y, this->z = z;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec3d operator+(vec3d ope){
		return vec3d(add(x, ope.x), add(y, ope.y), add(z, ope.z));
	}
	vec3d operator-(vec3d ope){
		return vec3d(add(x, -ope.x), add(y, -ope.y), add(z, -ope.z));
	}
	vec3d operator*(double t){
		return vec3d(x*t, y*t, z*t);
	}
	vec3d operator/(double t){
		return vec3d(x/t, y/t, z/t);
	}
	double dot(vec3d ope){
		return add(add(x*ope.x, y*ope.y), z*ope.z);
	}
	/*double cross(vec3d ope){  // NOT IMPLEMENTED
		return add(x*ope.y, -y*ope.x);
	}*/
	double norm(){
		double d2 = dot(*this);
		if(d2 > 0) return sqrt(d2);
		return 0.0;
	}
};

double distPP(vec3d p, vec3d q){
	return (p-q).norm();
}

	
vector<Event> vec;

int n;
vec3d p[205], v[205];
double r[205], vr[205];
double dis[205], ans[205];
bool used[205];

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		for(int i = 1; i <= n; i++){
			cin >> p[i].x >> p[i].y >> p[i].z;
			cin >> v[i].x >> v[i].y >> v[i].z;
			cin >> r[i] >> vr[i];
		}
		for(int i = 1; i <= n; i++) dis[i] = r[i] / vr[i];
		
		vec.clear();
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(i >= j) continue;
				vec3d P = p[i]-p[j], V = v[i]-v[j];
				double R = r[i]+r[j], VR = vr[i]+vr[j];
				double t = min(dis[i], dis[j]);
				double A = V.dot(V) - VR*VR;
				double B = 2*P.dot(V) + 2*R*VR;
				double C = P.dot(P) - R*R;
				double D = B*B-4*A*C;
				if(fabs(A) < eps){
					if(fabs(B) < eps){
						if(fabs(C) < eps) vec.push_back(make_pair(0, make_pair(i, j)));
						continue;
					}
					double x = -C/B;
					if(x >= -eps && x <= t + eps) vec.push_back(make_pair(x, make_pair(i, j)));
					continue;
				}
				if(D < 0) continue;
				double x1 = (-B - sqrt(D)) / (2*A);
				double x2 = (-B + sqrt(D)) / (2*A);
				if(x1 > x2) swap(x1, x2);
				if(x1 >= -eps && x1 <= t + eps){
					vec.push_back(make_pair(x1, make_pair(i, j)));
					continue;
				}
				if(x2 >= -eps && x2 <= t + eps){
					vec.push_back(make_pair(x2, make_pair(i, j)));
				}
			}
		}
		for(int i = 1; i <= n; i++) vec.push_back(make_pair(dis[i], make_pair(i, i)));
		sort(vec.begin(), vec.end());
		
		for(int i = 1; i <= n; i++) used[i] = false;
		for(int i = 0; i < vec.size(); i++){
			int u = vec[i].second.first, v = vec[i].second.second;
			if(used[u] || used[v]) continue;
			ans[u] = ans[v] = vec[i].first;
			used[u] = used[v] = true;
		}
		
		for(int i = 1; i <= n; i++) printf("%.11Lf\n", ans[i]);
	}
	
	return 0;
}


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

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

	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
	  cin >> vec.at(i);
	}

	int diff = 0, sumdiff = 0;
  
	sort(vec.begin(), vec.end());
  
	for( int i = 0; i < n-1; i +=2) {
      diff = max( vec.at(n-1-i) - vec.at(n-1-(i+1)), vec.at(n-1-(i+1))- vec.at(n-1-i) );
      sumdiff += diff;
//    cout << sumdiff << endl;
    }

	if(n%2 == 1){
      diff = vec.at(0);
      sumdiff += diff;
    }
  
    cout << sumdiff << endl;
}


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

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

    const int N = 3;
    int A[N][N];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> A[i][j];
        }
    }

    int n;
    cin >> n;
    vector<int> B(n);

    bool F[N][N] = {};
    for(int i = 0; i < n; i++){
        cin >> B[i];
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                if(A[j][k] == B[i]){
                    F[j][k] = true;
                    break;
                }
            }
        }
    }

    bool f = false;
    for(int i = 0; i < N; i++){
        bool c = true;
        for(int j = 0; j < N; j++){
            if(F[i][j]);
            else{
                c = false;
                break;
            }
        }
        if(c){
            f = true;
            break;
        }
    }

    for(int i = 0; i < N; i++){
        bool c = true;
        for(int j = 0; j < N; j++){
            if(F[j][i]);
            else{
                c = false;
                break;
            }
        }
        if(c){
            f = true;
            break;
        }
    }

    bool f1 = F[0][0] && F[1][1] && F[2][2];
    bool f2 = F[2][0] && F[1][1] && F[0][2];

    if(f1 || f2) f = true;

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    ll sum = 0;

    vll red(a);
    vll green(b);
    vll ncolor(c);
    rep(i,0,a) cin >> red[i];
    rep(i,0,b) cin >> green[i];
    rep(i,0,c) cin >> ncolor[i];

    sort(all(red));
    sort(all(green));
    sort(all(ncolor));
    reverse(all(red));
    reverse(all(green));
    reverse(all(ncolor));


    priority_queue<ll, vll, greater<ll>> reds;
    ll sumred = 0;
    priority_queue<ll, vll, greater<ll>> greens;
    ll sumgreen = 0;

    for(int i = 0; i < x; i++) {
        sumred += red[i];
        reds.push(red[i]);
    }
    for(int i = 0; i < y; i++) {
        sumgreen += green[i];
        greens.push(green[i]);
    }

    for(int i = 0; i < c; i++) {
        ll lowestred = reds.top();
        ll lowestgreen = greens.top();
        ll val = ncolor[i];
        ll diff1 = val - lowestred;
        ll diff2 = val - lowestgreen;
        if(diff1 <= 0 && diff2 <= 0) break;
        else if(diff1 <= 0 && diff2 > 0) {
            greens.pop();
            greens.push(val);
            sumgreen += diff2;
        } else if(diff1 > 0 && diff2 <= 0) {
            reds.pop();
            reds.push(val);
            sumred += diff1;
        } else {
            if(diff1 > diff2) {
                reds.pop();
                reds.push(val);
                sumred += diff1;
            } else {
                greens.pop();
                greens.push(val);
                sumgreen += diff2;
            }
        }
    }
    cout << sumgreen + sumred << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n); ++i)
#define INF 100000 // 2^31-1
#define MAX_V 1000


using namespace std;

using ll =long long;
using P = pair<int,int>;


 
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

//5
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main() {

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

string s,t;

cin>>s;
cin>>t;

int leng=(int)s.size();
int leng2=(int)t.size();


int flag=0;

for(int i=0;i<leng;i++){
if(s[i]!=t[i])flag=1;
}

if(flag==0 && leng+1==leng2){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}


}

//cout << fixed << setprecision(5) <<(n*2)*M_PI << endl;

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, a[1010], k;
i64 d[1010][1010];
void solve(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < n; i++){
		i64 cnt = 0;
		for(int j = i; j < n; j++){
			cnt += a[j];
			d[i][j] = cnt;
		}
	}
	
	int b = 0;
	i64 ans = 0;
	for(b = 0; (1LL<<b) < 1000000000000; b++){}
	bool used[1010][1010] = {};
	for(; b >= 0; b--){
		int cc = 0;
		vector<P> v;
		for(int i = 0; i < n; i++){
			for(int j = i; j < n; j++){
				if(!used[i][j] && d[i][j] >> b & 1){
					cc++;
					v.push_back({i,j});
				}
			}
		}
		if(cc >= k){
			ans += (1LL << b);
			for(int i = 0; i < n; i++){
				for(int j = i; j < n; j++){
					used[i][j] = 1;
				}
			}
			for(int i = 0; i < v.size(); i++){
				used[v[i].first][v[i].second] = 0;
			}
		}
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 10612
import sys
import numpy as np
# from numba import njit

# 公式解説を見てからやった
# 複数サイクルでき、1-K回移動可能
# N < 5000?多分、O(N * 2N)くらいで行けそうに見えるが。。。

# @njit(cache=False)
def main(N,K,P,C): #,ans):


	# XeXは、Float?numbaの場合、intに変換しないとまずいのかもしれない
	# ans = -1e9
	ans = -10 ** 9

	# 一度計算したサイクル情報を一応キャッシュしておく。。。
	# あんまり意味なさそう
	cycleIDs = np.full( N, -1, dtype=np.int64 )
	cycleInfs = []


	# print(P)

	cycleID = 0

	for n in range(N):

		v = n
		currentCycleItemCnt = 0
		currentCycleTotal = 0

		if cycleIDs[v] != -1:
			currentCycleItemCnt, currentCycleTotal = cycleInfs[ cycleIDs[v] ]
			# print(currentCycleItemCnt, currentCycleTotal)
		else:
			while True:
				# 全頂点について、属するサイクルを計算する
				currentCycleItemCnt += 1
				currentCycleTotal += C[v]

				v = P[v]
				if v == n:
					# サイクル発見
					cycleInfs.append( (currentCycleItemCnt, currentCycleTotal) )
					cycleID += 1
					break

				# 一応、一度サイクルを計算した頂点については、
				# その頂点の属するサイクルの情報をメモっておく。。。
				cycleIDs[v] = cycleID

		procCnt = 0
		currentCycleSumTmp = 0

		while True:

			# 頂点vにコマが置かれた時の最高スコアを計算し、
			# これまでの最高スコアを上回ったら、これまでの最高スコアを更新する
			procCnt += 1
			currentCycleSumTmp += C[v]
			if K < procCnt:
				break

			cycleLoopCnt = 0
			if procCnt < K and 0 < currentCycleTotal:
				cycleLoopCnt = int(( K - procCnt ) // currentCycleItemCnt)

			# print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, procCnt)
			tmp = currentCycleSumTmp + cycleLoopCnt * currentCycleTotal
			ans = max( int(ans), int(tmp) )

			v = P[v]
			if v == n:
				# サイクル終了
				break

	print(int(ans))

if sys.argv[-1]=='ONLINE_JUDGE':
	# from numba import njit
	from numba.pycc import CC
	cc=CC('my_module')
	cc.export('main','void(i8,i8,i8[:],i8[:])')(main)
	# main=njit(main, cache=True)
	cc.compile()
	exit(0)
from my_module import main



if __name__ == "__main__":
	N,K = map(int,input().split())
	P = np.array( input().split(), np.int64 )
	P -= 1
	C = np.array( input().split(), np.int64 )

	# ans = -1e9	# NOTES: 2020/08/17 numba関数内でこれをやっていたら、データによってはWAになってしまっていた。詳細は、いまだに不明。
	main(N,K,P,C) #,ans)
	#print(ans)




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

int Func(const int A, const int B)
{
  return A > B ? A : B;
}

int Keta(long x)
{
  int num = 0;
  while(x != 0)
  {
    x /= 10;
    ++num;
  }
  return num;
}

int main(int argc, char const *argv[])
{
  long N;
  cin >> N;

  int min = 20;
  for(long i = 1; i <= sqrt(N); ++i)
  {
    if(N % i != 0)
      continue;

    int A_keta = Keta(i);
    int B_keta = Keta(N / i);
    int num = Func(A_keta, B_keta);

    if(num < min)
      min = num;
  }
  cout << min << flush;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  vector<ll>vec(3);
  cin>>vec.at(0)>>vec.at(1)>>vec.at(2);
  sort(vec.begin(),vec.end());
  ll a=2*vec.at(2)-vec.at(0)-vec.at(1);
  if(a%2==0){
    cout<<a/2<<endl;
  }
  else{
    cout<<(a+3)/2<<endl;
  }
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int X[62][2];
const int mod=1000000007;
int main()
{
	long long ans=0;
	int N;
	cin>>N;
	while(N--)
	{
		long long A;
		cin>>A;
		long long B=A;
		for(int i=0;i<60;i++)
			ans=(ans+X[i][(int)(1ll-(B%2ll))])%mod,
			B/=2ll;
		for(int i=0;i<60;i++)
			X[i][(int)(A%2ll)]=(X[i][(int)(A%2ll)]+(1ll<<i))%mod,
			A/=2ll;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  ll k;
  cin>>s>>k;
  ll n=len(s);
  ll ans=0;
  set<char> cnt;
  rep(i,n) cnt.insert(s[i]);
  if(len(cnt)==1){
    if(n%2==1){
      ll cnt1=n/2;
      ll cnt2=n-cnt1;
      ll ans=(cnt1+cnt2)*(k/2);
      //cout<<ans<<endl;
      if(k%2==1) ans+=cnt1;
      cout<<ans<<endl;
      return 0;
    }
  }
  if(s[0]!=s[n-1]){
    char now='A';
    rep(i,n){
      if(s[i]==now){
        ans++;
        now='A';
      }else{
        now=s[i];
      }
    }
    ans*=k;
    cout<<ans<<endl;
  }else{
    string t=s+s;
    ll cnt1=0,cnt2=0;
    char now='A';
    rep(i,n){
      if(t[i]==now){
        cnt1++;
        now='A';
      }else{
        now=t[i];
      }
    }
    FOR(i,n,2*n){
      if(t[i]==now){
        cnt2++;
        now='A';
      }else{
        now=t[i];
      }
    }
    ans=cnt1+cnt2*(k-1);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
 
int A[2000],l[2000],n,j,m[2000];
void slove(int,int);
void slove (int a  ,int b){
  if(b==0){
    l[j]=1;
  }
  else if( b>0 && a<n){
    slove(a+1,b-A[a]);
    slove(a+1,b);
  }
   
   
}
main()
{
  int q,i; 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }
  for(j=0;j<q;j++){
    slove(0,m[j]);
  }
  for(j=0;j<q;j++){
    if(l[j]==1)printf("yes\n");
    else  printf("no\n");
  }
  return 0;
}

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

int main() {
//	freopen("input.txt", "r", stdin);
	int n, m;

	cin >> n >> m;
	string a[n], b[m];
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	for (int i = 0; i < m; ++i) {
		cin >> b[i];
	}


	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (a[i][j] == b[0][0]) {
				for (int k = 0; k < m; ++k) {

					for (int h = 0; h < m; ++h) {

						if (a[i + k][h + j] == b[k][h])
							cnt++;
						else
							goto y;
					}
				}
			}
//			cout<<cnt<<endl;
			if (cnt == m * m) {
				puts("Yes");
				return 0;
			}
			y: cnt = 0;
		}
		
	}

	puts("No");
}


Measured memory_bytes: 256
#include <stdio.h>

int meijiJ(int year, int month, int day);
int showaJ(int year, int month, int day);
int taishoJ(int year, int month, int day);
int heiseiJ(int year, int month, int day);

int main(void)
{
    int ye, mo, da;  //year, month, day
    while (scanf("%d %d %d", &ye, &mo, &da) != EOF) {
        if (meijiJ(ye, mo, da) != 4) {
            printf("pre-meiji\n");
        } else if (meijiJ(ye, mo, da) == 4 && taishoJ(ye, mo, da) != 8) {
            printf("meiji %d %d %d\n", ye - 1867, mo, da);
        } else if (taishoJ(ye, mo, da) == 8 && showaJ(ye, mo, da) != 12) {
            printf("taisho %d %d %d\n", ye - 1911, mo, da);
        } else if (showaJ(ye, mo, da) == 12 && heiseiJ(ye, mo, da) != 16) {
            printf("showa %d %d %d\n", ye - 1925, mo, da);
        } else {
            printf("heisei %d %d %d\n", ye - 1988, mo, da);
        }
    }
    return 0;
}

int meijiJ(int year, int month, int day)
{
    int result;
    if (year < 1868) {
        result = 1;  //1868??´??\???
    } else if (year == 1868) {
        if (month < 9) {
            result = 2;  //1868??´1?????????1868??´9?????\???
        } else if (month == 9 && day < 8) {
            result = 3;  //1868??´9???8??\??\???
        } else {
            result = 4; //????????\???
        }
    } else {
        result = 4;
    }
    return result;
}

int taishoJ(int year, int month, int day)
{
    int result;
    if (year < 1912) {
        result = 5;  //1912??´??\???
    } else if (year == 1912) {
        if (month < 7) {
            result = 6;  //1912??´1?????????1912??´7?????\???
        } else if (month == 7 && day < 30) {
            result = 7;  //1912??´7???1??\??????1912??´7???30??\??\???
        } else {
            result = 8; //??§??£??\???
        }
    } else {
        result = 8;
    }
    return result;
}

int showaJ(int year, int month, int day)
{
    int result;
    if (year < 1926) {
        result = 9;  //1926??´??\???
    } else if (year == 1926) {
        if (month < 12) {
            result = 10;  //1926??´1?????????1926??´12?????\???
        } else if (month == 12 && day < 25) {
            result = 11;  //1926??´12???1??\??????1926??´12???25??\??\???
        } else {
            result = 12; //????????\???
        }
    } else {
        result = 12;
    }
    return result;
}

int heiseiJ(int year, int month, int day)
{
    int result;
    if (year < 1989) {
        result = 13;  //1989??´??\???
    } else if (year == 1989) {
        if (month < 1) {
            result = 14;  //?§???????????????¢??°??¨??????????????¨????????????????????????
        } else if (month == 1 && day < 8) {
            result = 15;  //1989??´1???1??\??????1989??´1???8??\??\???
        } else {
            result = 16; //????????\???
        }
    } else {
        result = 16;
    }
    return result;
}

Measured memory_bytes: 1036
//b−a=c−b
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(b - a == c - b) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============modpow============================
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  string X;
  cin >> X;
  reverse(X.begin(), X.end());
  ll pc = 0;
  for (ll i = 0; i < N; ++i) {
    if (X.at(i) == '1') {
      pc += 1;
    }
  }
  ll s = 0, l = 0;
  for (ll i = 0; i < N; ++i) {
    if (X.at(i) == '1') {
      if (pc != 1) {
        s += modpow(2, i, pc - 1);s %= (pc - 1);
      }
      l += modpow(2, i, pc + 1);l %= (pc + 1);
    }
  }
  for (ll i = N - 1; i >= 0; --i) {
    ll now;
    ll ans = 1;
    if (X.at(i) == '1') {
      if (pc == 1) {
        cout << '0' << "\n";
        continue;
      }
      now = s;
      now -= modpow(2, i, pc - 1);
      if (now < 0) {
        now += pc - 1;
      }
      now %= (pc - 1);
    }
    else {
      now = l;
      now += modpow(2, i, pc + 1);
      now %= (pc + 1);
    }
    // cout << now << "\n";
    while (now != 0) {
      now %= __builtin_popcountll(now);
      ans += 1;
    }
    cout << ans << "\n";
  }
  // cout << s << m << l << "\n";
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define count(v,x) count(v.begin(),v.end(),x)
#define find(v,x) find(v.begin(),v.end(),x)


priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int a,b,c,x,y;

void solve(){
    cin >> a >> b >> c >> x >> y;
    llint ans=inf;
    int z=max(x,y);
    for(int i=0;i<=z;i++){
        llint tmp=i*2*c+max((x-i),0)*a+max(y-i,0)*b;
        ans=min(ans,tmp);
    }
    cout << ans << endl;

}

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





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

using namespace std;
#define ll long long
#define st first
#define nd second
#define pb push_back

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cntW = 0, cntR = 0;
	for(int i = 0; i < n; i++)
		if(s[i] == 'W')
			cntW++;
		else
			cntR++;	
	if(min(cntR,cntW) == 0)
		cout << 0;
	else{
		int ans = 0;
		for(int i = 1; i <= cntR; i++)
			if(s[i - 1] == 'W')
				ans++;
		cout << ans;
	}
	return 0;
}



Measured memory_bytes: 3776
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
int ceil(int a,int b){// a以上でbの倍数の最小値を出力//
    return (a+b-1)/b*b;
}

//シフト演算　(1<<k) 2のk乗

int stoii(string s){//stoi関数の代用 文字列を数値として読み取りint型に変換//
    return atoi(s.c_str());
}
int main (void){
    int a,b;
    cin>>a>>b;
    if(a<=b) cout<<a<<endl;
    else cout<<a-1<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(){
	int h,w,x,y;
	char dp[150][150];
	while(true){
	cin>>h>>w;
	if(h==0&&w==0)
		break;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>dp[i][j];
		}
	}
	x=0,y=0;
	int i=0;
	bool loop=false;
	while(true){
		if(dp[x][y]=='>')
			y+=1;
		if(dp[x][y]=='<')
			y-=1;
		if(dp[x][y]=='^')
			x-=1;
		if(dp[x][y]=='v')
			x+=1;
		if(dp[x][y]=='.')
			break;
		i++;
		if(i==h*w){
			cout<<"LOOP"<<endl;
			loop=true;
			break;
		}
	}
	if(loop==false)
	cout<<y<<" "<<x<<endl;
	}
	return 0;
}

Measured memory_bytes: 1184
def main(N,P):
    ad=(1,N,-1,-N)
    X=[0]*N*N
    for i in range(N*N):
        X[i]=min(i//N,N-1-i//N,i%N,N-1-i%N)
    E=[1]*N*N
    a=0
    q=[0]*N*N*N
    l,r=0,0
    for p in P:
        p-=1
        a+=X[p]
        E[p]=0
        q[r]=p
        r+=1
        while l<r:
            i=q[l]
            l+=1
            for j in ad:
                if 0<=i+j<N*N and X[i]+E[i]<X[i+j]:
                    X[i+j]=X[i]+E[i]
                    q[r]=i+j
                    r+=1
    return a
import sys
import numpy as np
readline=sys.stdin.buffer.readline
read=sys.stdin.buffer.read
if sys.argv[-1]=='ONLINE_JUDGE':
    from numba import*
    from numba.pycc import CC
    cc=CC('my_module')
    def cc_export(f,signature):
        cc.export(f.__name__,signature)(f)
        return njit(f)
    main=cc_export(main,(i8,i8[:],))
    cc.compile()
    exit()
N=int(readline())
P=np.array(readline().split(),dtype=np.int64)
from my_module import main
print(main(N,P))


Measured memory_bytes: 1012640
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
vector<int>v[N+100];

int main()
{
	int n,ans = 0,pre = 0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int a;
		scanf("%d",&a);
		v[a].push_back(i);
	}
	for(int i=1;i<=n;i++){
		auto it = lower_bound(v[i].begin(),v[i].end(),pre);
		if(it==v[i].end())break;
		ans++;
		pre = *it;
	}
	if(ans==0){
		printf("-1\n");
	}
	else printf("%d\n",n-ans);
}


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

using namespace std;

#define ll long long

std::vector<ll> v;

int main(){

    ll a, b;

    cin >> a >> b;

    for(ll i = 2LL; i * i <= a || i * i <= b; i+=2){

        if(a % i == 0 && b % i == 0){
            while(a % i == 0) a /= i;

            while(b % i == 0) b /= i;

            v.push_back(i);
        }
        while(a % i == 0) a /= i;
        while(b % i == 0) b /= i;

        if(i == 2) i--;
    }
    if(a == b && a > 1)v.push_back(a);

    v.push_back(1);

    cout << (int) v.size() << endl;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e17+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
bool solve(void){
	int n;cin>>n;
	if(n==0){return false;}
	vector<pair<char,llint>>sta;
	sta.pub(mp('+',0LL));
	while(n--){
		string s;cin>>s;
		int t=s.size()-1;
		while(sta.size()>t+1){
			llint su=sta.back().sec;
			sta.pob();
			if(sta.back().fir=='+'){sta.back().sec+=su;}
			else{sta.back().sec*=su;}
		}
		if('0'<=s[t]&&s[t]<='9'){
			llint su=s[t]-'0';
			if(sta.back().fir=='+'){sta.back().sec+=su;}
			else{sta.back().sec*=su;}
		}else{
			if(s[t]=='+'){sta.pub(mp('+',0LL));}
			else{sta.pub(mp('*',1LL));}
		}
	}
	while(sta.size()>1){
		llint su=sta.back().sec;
		sta.pob();
		if(sta.back().fir=='+'){sta.back().sec+=su;}
		else{sta.back().sec*=su;}
	}
	cout<<sta.back().sec<<endl;
	return true;
}
int main(void){
	while(solve()){}
}


Measured memory_bytes: 3148