akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            int x = p[i];
            int y = p[i + 1];
            int z = p[i + 2];
            if (x < y && y < z || z < y && y < x) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21972
#include <iostream>
 
using namespace std;
 
int main () {
    int D,T,S;
    while(cin>>D>>T>>S) {
        int ans = S * T;
        if (ans >= D) {
            cout << "Yes"<<endl;
        } else {
            cout << "No"<<endl;
        }
    }
}

Measured memory_bytes: 3636
N = int(input())

mod = 10**9+7

dp = [ [ [ [0 for i in range(4)] for j in range(4)] for k in range(4)] for l in range(N+1) ]


dp[0][3][3][3] = 1
#A=0,G=1,C=2,T=3とする

for len in range(N):
    #最後から1文字目
    for c1 in range(4):
        #最後から2文字目
        for c2 in range(4):
            #最後から3文字目
            for c3 in range(4):
                if dp[len][c1][c2][c3] == 0:
                    continue
                for c0 in range(4):
                    if c0 ==2 and c1 == 1 and c2 == 0:
                        continue
                    if c0 ==1 and c1 == 2 and c2 == 0:
                        continue
                    if c0 ==2 and c1 == 0 and c2 == 1:
                        continue
                    if c0 ==2 and c1 == 1 and c3 == 0:
                        continue
                    if c0 ==2 and c2 == 1 and c3 == 0:
                        continue
                    dp[len+1][c0][c1][c2] += dp[len][c1][c2][c3]
                    dp[len+1][c0][c1][c2] %= mod


ans = 0

for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[N][i][j][k]
            ans = ans % mod 
            
print(ans)

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

class Program
{
    static void Main()
    {
        var tmp = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        var A = tmp[0];
        var B = tmp[1];

        int ans = 0;

        int d = A - 2 * B;

        if (d <= 0)
        {
            ans = 0;
        }
        else
        {
            ans = d;
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  int s, w;
  cin >> s >> w;
  if (w >= s)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
  return 0;
}


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

using namespace std;

int dp[1001][1001];
int v[1001], w[1001];

int main()
{
    int W, N;
    char t;
    int cnt = 1;

    while(true)
    {
        cin >> W >> N;

        if(W == 0) return 0;

        for (int i = 0; i < N; i++)
        {
            cin >> v[i] >> t >>  w[i];
        }

        for(int i = 0; i <= W; i++) dp[0][i] = 0;

        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j <= W; j++)
            {
                if (j < w[i])
                    dp[i + 1][j] = dp[i][j];
                else
                    dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }

        int ans1 = 0, ans2 = 0;

        for(int i = 0; i <= W; i++)
        {
            if(dp[N][i] > ans1)
            {
                ans1 = dp[N][i];
                ans2 = i;
            }
        }

        cout << "Case " << cnt << ":" << endl;
        cout << ans1 << endl << ans2 << endl;
        cnt++;
    }

    return 0;
}


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

int main(void){
    string a, b;
    int ans = 2;
    cin >> a >> b;
    if (a.size() != b.size()) ans = a.size() > b.size() ? 0 : 1;
    else {
        for (int i = 0; i < a.size(); i++) {
            if (a[i] > b[i]) {
                ans = 0;
                break;
            }
            if (a[i] < b[i]) {
                ans = 1;
                break;
            }
        }
    }
    if (ans == 0) cout << "GREATER" << endl;
    if (ans == 1) cout << "LESS" << endl;
    if (ans == 2) cout << "EQUAL" << endl;
}


Measured memory_bytes: 256
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e15+100)
#define N 1000500


 
// Driver code to test above functions
int32_t main()
{
    
 
    
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n, m;
    cin >> n >> m;
    n = __gcd(n, m);

    int ans = 1;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ans++;
            while(n%i==0)
                n/=i;
        }
    }

    if(n!=1)
        ans++;

    cout << ans;

    return 0;
} 

Measured memory_bytes: 256
S = input()
judge = False
 
while (len(S)>=0):
    if len(S) == 0:
        judge = True
        break
    elif S[-5::] == "dream" or S[-5::] == "erase":
        S = S[:-5:]
    elif S[-6::] == "eraser":
        S = S[:-6:]
    elif S[-7::] == "dreamer":
        S = S[:-7:]
    else:
        break
 
    
if judge == True:
    print("YES")
else:
    print("NO")

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


int main()
{
	int A, B, C, X;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> X;

	int count = 0;
	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			for (int k = 0; k <= C; k++) {
				if (500 * i + 100 * j + 50 * k == X)
					count++;
			}
		}
	}

	cout << count << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a[3],c=0,i;
	for (i=0;i<3;++i){
		scanf("%d",a+i);
	}
	for (i=a[0];i<=a[1];++i){
		if (a[2]%i == 0){
			c++;
		}
	}
	printf("%d\n",c );

	return 0;
}

Measured memory_bytes: 596
#define _CRT_SECURE_NO_WARNINGS

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

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (4e18) + 9;
const int MOD = (1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { r, d, l, u };
int dx[] = { 0, 1, 0,-1 };
int dy[] = { 1, 0,-1, 0 };

//enum diR { d, r, u, l , dr, ur, dl, ul };
int dX[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dY[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiou"; //and sometimes "aeiouy"

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
//convert index from 2D matrix to 1D array. (Zero-indexed)
int ord(int r, int c, int nCol) { return (nCol*r) + c + 1; }
//convert index from 1D array to 2D matrix . (One-indexed)
ii rord(int n, int nCol) {
	int r = n%nCol, c = n / nCol;
	if (n%nCol == 0) c--, r = nCol;
	return ii(r, c);
}

ll poww(ll num, ll p, ll md = MOD) {
	num %= md;
	ll ret = 1;
	while (p > 0) {
		if (p & 1) ret = (ret * num) % md;
		num = (num * num) % md;
		p >>= 1;
	}
	return ret;
}

ll nCr(ll n, ll r) {
	if (n < r)
		return 0;
	if (r == 0)
		return 1;
	return n * nCr(n - 1, r - 1) / r;
}

const int N = 1100;
ll dp[N][N]; int  H, W;
string grid[N];
ll solve(int i, int j) {
	if (i >= H || j >= W || grid[i][j] == '#') return 0;
	if (i == H - 1 && j == W - 1) return 1;
	ll& ret = dp[i][j];
	if (~ret) return ret;
	return ret = (solve(i + 1, j)%MOD + solve(i, j + 1)%MOD)%MOD;
}


int main()
{
#ifndef ONLINE_JUDGE

#else
	//freopen("pyramid.in", "r", stdin);
#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> H >> W;
	lop(i, H) cin >> grid[i];
	mem(dp, -1);
	cout << solve(0, 0) % MOD << endl;



	return 0;
}


Measured memory_bytes: 10880
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 1e5 + 10;
int a[maxn];
int n, m;

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  return 1;
}

pair<int, int> ps[maxn];

int b[maxn][2];

void solve() {
  sort(a, a + n);
  for (int i = 0; i < m; ++i) {
    b[i][0] = b[i][1] = 0;
  }
  for (int i = 0; i < n;) {
    int i0 = i;
    while (i < n && a[i] == a[i0]) {
      ++i;
    }
    int r = a[i0] % m;
    b[r][0] += (i - i0) / 2;
    b[r][1] += (i - i0) % 2;
    //eprintf("%d  %d\n", r, i - i0);
  }

  int res = 0;

  for (int i = 0; i <= m - i; ++i) {
    if (!i || i == m - i) {
      res += b[i][0] + b[i][1] / 2;
    } else {
      //eprintf("%d %d\n", i, m - i);
      while (1) {
        if ((!b[i][0] && !b[i][1]) || (!b[m - i][0] && !b[m - i][1])) {
          res += b[i][0] + b[m - i][0];
          break;
        }
        //eprintf("%d %d   %d %d\n", b[i][0], b[i][1], b[m - i][0], b[m - i][1]);
        for (int it = 0; it < 2; ++it) {
          int x = !it ? i : (m - i);
          if (b[x][1]) {
            --b[x][1];
            continue;
          }
          if (b[x][0]) {
            ++b[x][1];
            --b[x][0];
            continue;
          }
          assert(0);
        }
        ++res;
      }
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

struct UnionFind{
// 同値関係をサポートするデータ構造
// 併合,所属する同値類の代表元: O(a(n)), 集合の分割はNG
// (a(n): アッカーマン関数A(m,n)について,f(n)=A(n,n)としたときの逆関数)
  vector<int> m_root;
  vector<int> m_size;

  UnionFind(int N)
  : m_root(N)
  , m_size(N,1)
  { iota(m_root.begin(), m_root.end(), 0); }

  int find(int a){
    if(m_root.at(a)==a){
      return a;
    }
    else{
      return m_root.at(a)= find(m_root.at(a));
    }
  }

  void unify(int a, int b){
    int r_a= find(a);
    int r_b= find(b);

    if(r_a != r_b){
      if(m_size.at(r_a) < m_size.at(r_b)){
        m_root.at(r_a)= r_b;
        m_size.at(r_b)+= m_size.at(r_a);
        return;
      }
      else{
        m_root.at(r_b)= r_a;
        m_size.at(r_a)+= m_size.at(r_b);
        return;
      }
    }
  }
  
  bool are_comrade(int a, int b){
    return find(a)==find(b);
  }

  int get_size(int a){
    return m_size.at(find(a));
  }
};

int main(){// 最大の派閥サイズを求めれば良い
  int N,M;
  cin >> N >> M;

  UnionFind uf(N);
  int buf1,buf2;
  for(int j=0; j<M; j++){
    cin >> buf1 >> buf2;
    buf1--; buf2--; // 1-indexed -> 0-indexed
    uf.unify(buf1, buf2);
  }

  int ans= 0;
  for(int i=0; i<N; i++){
    ans= max(ans, uf.get_size(i));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4728
'use strict'

const main = arg => {
 const input = arg.trim().split("\n")[0].split(" ").map(num => parseInt(num));
 const tate = input[0];
 const yoko = input[1];

 console.log("%d %d", tate*yoko, (tate+yoko)*2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 15112
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 1000000007

typedef struct pair{ll x,y;}P;
ll gcd(ll p,ll q){while(q){ll t=p%q;p=q;q=t;}return p;}

int cmp(const void*p,const void*q){
	if((*(P*)p).x<(*(P*)q).x)return -1;
	if((*(P*)p).x>(*(P*)q).x)return 1;
	if((*(P*)p).y<(*(P*)q).y)return -1;
	if((*(P*)p).y>(*(P*)q).y)return 1;
	return 0;
}

P pp[200010],*p=pp,mm[200010],*m=mm,*t;
int pcnt,mcnt;
int zero;

int bs(P p){
	int l=-1,r=mcnt;
	while(r-l>1){
		int mid=(l+r)/2;
		if(cmp(m+mid,&p)<0)l=mid;
		else r=mid;
	}
	return cmp(m+r,&p)?-1:r;
}

int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		if(x==0&&y==0){
			zero++;
		}else{
			ll d=gcd(x,y);
			x/=d;
			y/=d;
			if(y<0){
				x*=-1;
				y*=-1;
			}
			if(x>0){
				p[pcnt].x=x;
				p[pcnt].y=y;
				pcnt++;
			}else{
				m[mcnt].x=x;
				m[mcnt].y=y;
				mcnt++;
			}
		}
	}
	qsort(p,pcnt,sizeof(P),cmp);
	qsort(m,mcnt,sizeof(P),cmp);
	
	ll ans=1;
	rep(k,0,2){
		int pnum=0;
		rep(i,0,pcnt){
			pnum++;
			if(cmp(p+i,p+i+1)==0)continue;
			P ppp={-p[i].y,p[i].x};
			if(k){
				ppp.x*=-1;
				ppp.y*=-1;
			}
			int idx=bs(ppp);
			if(idx==-1){
				ans=ans*pom(2,pnum,MOD)%MOD;
			}else{
				if(k){
					int mnum=1;
					while(cmp(m+idx,m+idx+mnum)==0)mnum++;
					ans=ans*(pom(2,pnum,MOD)+pom(2,mnum,MOD)-1)%MOD;
				}
			}
			pnum=0;
		}
		t=p;p=m;m=t;
		int temp=pcnt;pcnt=mcnt;mcnt=temp;
	}
	printf("%lld\n",(ans+zero+MOD-1)%MOD);
}

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

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

	vector<int> a;
	while( b.size() ) {
		int flag = 0;
		for( int i = b.size() - 1; i >= 0; i-- ) {
			if( b[i] == i + 1 ) {
				a.push_back( i + 1 );
				b.erase( b.begin() + i );
				flag = 1;
				break;
			}
		}
		if( flag == 0 ) {
			cout << -1 << endl;
			return 0;
		}
	}
	reverse( a.begin(), a.end() );

	for( int i = 0; i < N; i++ ) {
		cout << a[i] << endl;
	}
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int n;
	scanf("%d", &n);
	vi p(n+1);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		p[x] = i;
	}

	set<int> s;
	long long ans = 0;
	for (int i = n; i > 0; --i) {
		auto it = s.insert(p[i]);
		auto ptr = it.first;
		int a, b, x, y;

		if (++ptr == s.end()) {
			x = y = n;
		}
		else {
			x = *ptr;
			if (++ptr == s.end())
				y = n;
			else
				y = *ptr;
		}

		ptr = it.first;
		if (ptr == s.begin()) {
			a = b = -1;
		}
		else {
			b = *(--ptr);
			if (ptr == s.begin())
				a = -1;
			else
				a = *(--ptr);
		}

		long long t = (long long)(b - a) * (x - p[i]) + (long long)(p[i] - b) * (y - x);
		ans += t * i;
	}
	printf("%lld\n", ans);
}


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

const long long INF = 1LL<<60;
int N = 131072;
long long dat[262144];

void update(int i, long long x) {
	i += N-1;
	dat[i] = x;
	while (i > 0) {
		i = (i-1)/2;
		dat[i] = min(dat[i*2+1], dat[i*2+2]);
	}
}

long long query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l) return INF;
	if (a <= l && r <= b) return dat[k];
	return min(query(a,b,k*2+1,l,(l+r)/2), query(a,b,k*2+2,(l+r)/2,r));
}

long long get(int a, int b) {
	long long r = query(a, b, 0, 0, N);
	//cerr << a << " " << b << " " << r << endl;
	return r;
}

long long solve() {
	for (int i = 0; i < 262144; ++ i) dat[i] = INF;

	int n, M;
	cin >> n >> M;
	vector<pair<pair<int,int>,int>> a;
	for (int i = 0; i < M; ++ i) {
		int x, y, z;
		cin >> x >> y >> z;
		a.push_back({{x,y},z});
	}
	sort(a.begin(), a.end());
	update(1, 0);
	for (auto p : a) {
		int li = p.first.first;
		int ri = p.first.second;
		int ci = p.second;
		auto c1 = get(li, ri+1);
		auto c2 = get(ri, ri+1);
		if (c1+ci < c2) {
			update(ri, c1+ci);
		}
	}
	auto r = get(n, n+1);
	if (r == INF) return -1;
	return r;
}

int main() {
	cout << solve() << endl;
}


Measured memory_bytes: 3960
import heapq
X, Y, A, B, C = map(int, input().split())
red = sorted(list(map(int, input().split())), reverse=True)
green = sorted(list(map(int, input().split())), reverse=True)
mu = list(map(int, input().split()))
eat_red = [0]*X
eat_green = [0]*Y
for i in range(X):
    eat_red[i] = red[i]
for i in range(Y):
    eat_green[i] = green[i]
heapq.heapify(eat_red)
heapq.heapify(eat_green)
for i in range(C):
    tmp = mu[i]
    r = heapq.heappop(eat_red)
    g = heapq.heappop(eat_green)
    if r <= g:
        heapq.heappush(eat_green,g)
        heapq.heappush(eat_red,max(tmp,r))
    else:
        heapq.heappush(eat_red,r)
        heapq.heappush(eat_green,max(tmp,g))
print(sum(eat_red)+sum(eat_green))

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

int main() {
    int ans = 0;
    char s[4], t[4];
    cin >> s >> t;
    for(int i = 0; i < 3;++i)
        ans += (s[i] == t[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int A[n];

    for(size_t i = 0; i < n; i++) scanf("%d",&A[i]);
    //A[0]～A[n-1]までn個の配列を格納
    for(size_t i = n-1; i > 0; i--) printf("%d ",A[i]);
    //for(size_t i = n-1; i >-1; i--) printf("%d ",A[i]); はエラー
    //forのデクリメントはi=0を判定しない？
    printf("%d\n",A[0]);
    
}


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

int main()
{
	int N;
	cin >> N;
	if ((N / 10) % 111 == 0 || (N % 1000) % 111 == 0) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}


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

public class Main{
    static PrintWriter out = new PrintWriter(System.out);
    long mod = 1000000000+7;
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static public void main(String[] args) throws Exception{
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ")
        Main main = new Main();
        int t= 1;
        while(t-->0){
            main.solve();
        }
//        main.solve();
        out.flush();
    }
    void solve() throws Exception{
        //
        String[] buf = reader.readLine().split(" ");
        int n = parIn(buf[0]), q = parIn(buf[1]);
        int[] color = new int[n+1];
        buf = reader.readLine().split(" ");
        for(int i=1; i<=n; i++) color[i] = parIn(buf[i-1]);
        int[] bit = new int[n+1];
        int[][] qlr = new int[q][];

        for(int i=0; i<q; i++){
            buf = reader.readLine().split(" ");
            qlr[i] = new int[]{i, parIn(buf[0]), parIn(buf[1])};
        }
        Arrays.sort(qlr, Comparator.comparingInt(o1->o1[2])); // ascending order or r[i]
        int now = 1;
        int[] last = new int[n+1];
        int[] ans = new int[q];
        boolean[] seen = new boolean[n+1];
        int total = 0;
        for(int i=0; i<q; i++){
            int[] cur = qlr[i];
            while(now<=cur[2]){
                int c = color[now];
                if(!seen[c]) {
                    total += 1;
                    seen[c] = true;
                }
                if(last[c]>0){
                    addTo(last[c], -1, n, bit);
                }
                last[c] = now;
                addTo(now, 1, n, bit);
                now++;
            }
            int l = cur[1], r = cur[2];
            int temp = total-sum(l-1, n, bit);
            ans[cur[0]] = temp;
        }
        for(int i=0; i<q; i++) out.println(ans[i]);
    }
    void addTo(int idx, int val, int n, int[] bit){
        while(idx<=n){
            bit[idx] += val;
            idx += idx&(-idx);
        }
    }
    int sum(int idx, int n, int[] bit){
        int ans= 0;
        while(idx>0){
            ans += bit[idx];
            idx -= idx&(-idx);
        }
        return ans;
    }
    int parIn(String s){return Integer.parseInt(s);}
}



Measured memory_bytes: 103704
using System;

namespace Circle
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string input = Console.ReadLine();
			double r = double.Parse(input);

			double pi = Math.PI;
			double area = r * r * pi;
			double circumference = 2 * r * pi;
			Console.WriteLine(area +" "+ circumference);
		}
	}
}

Measured memory_bytes: 5740
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		String S = in.nextStr();
		for(int i = 1; i < S.length(); i++){
			if(S.charAt(i-1) == S.charAt(i)){
				out.println("Bad");
				return;
			}
		}
		out.println("Good");
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
}
/* end Main */

class FastScanner {
	Reader input;

	FastScanner() {this(System.in);}
	FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
	
	int nextInt() {return (int) nextLong();}

	long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	}

	char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	}

	String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    cin>>n;
    long long a[n+1],b[n],ans=0,i;
    for (i=0;i<=n;i++)
    {
        cin>>a[i];
    }
    for (i=0;i<n;i++)
    {
        cin>>b[i];
        if (a[i]>=b[i])
            ans+=b[i];
        else
        {
            ans+=a[i];
            b[i]-=a[i];
            ans+=min(b[i],a[i+1]);
            a[i+1]-=min(a[i+1],b[i]);
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
package main

import "fmt"

func dfs(s string) bool {
	if s == "" {
		return true
	}
	for _, t := range []string{"dream", "dreamer", "erase", "eraser"} {
		if len(s) >= len(t) && s[0:len(t)] == t && dfs(s[len(t):]) {
			return true
		}
	}
	return false
}

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

	if dfs(s) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 10368
rows, cols = (int(x) for x in input().split())

mat = []
for r in range(rows):
    line = input().split()
    row = [int(x) for x in line]
    mat.append(row)
#     print(mat)

v = []
for r in range(cols):
    v.append(int(input()))

out = [int(0)] * rows
for r in range(rows):
    for c in range(cols):
#         print(mat[r])
        out[r] += mat[r][c] * v[c]
    print(int(out[r]))


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

int main () {
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
  int ans = 0;
    for (int j = 1; j < 200; j++){
      bool check = true;
      for (int k = 1; k < 200; k++){
        bool check = true;
        for (int l = 1; l < 200; l++){
         if (i < j*j+k*k+l*l+j*k+k*l+l*j) check = false;
          if (i == j*j+k*k+l*l+j*k+k*l+l*j)  ans++;
         if (!check) break;
        }
      }
    }
  cout << ans << endl;
  }
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int col[360000], tmp[360000];
void rec(const vector<vi> &g, int c, int p, int col){
	tmp[c] = col;
	for(int i : g[c]) if(i != p && !tmp[i]) rec(g, i, c, -col);
}
void graph(int n, int d, int c){
	vector<vi> g(4 * n * n);
	vector<pi> p;
	for(int i = 0; i * i <= d; i++){
		int r = d - i * i, j = sqrt(r) + EPS;
		if(j * j == r) p.emplace_back(i, j);
	}
	rep(i, 2 * n) rep(j, 2 * n){
		set<int> s;
		for(auto k : p){
			int a = i - k.first, b = j - k.second;
			if(a >= 0 && b >= 0) s.insert(a * 2 * n + b);
			b = j + k.second;
			if(a >= 0 && b < 2 * n) s.insert(a * 2 * n + b);
		}
		for(int k : s){
			g[i * 2 * n + j].pb(k);
			g[k].pb(i * 2 * n + j);
		}
	}
	memset(tmp, 0, sizeof(tmp));
	rep(i, 4 * n * n) if(!tmp[i]) rec(g, i, i, 1);
	rep(i, 4 * n * n) if(tmp[i] > 0) col[i] |= c;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, d1, d2; cin >> n >> d1 >> d2;
	graph(n, d1, 1);
	graph(n, d2, 2);
	
	int cnt[4] = {};
	rep(i, 4 * n * n) cnt[col[i]]++;
	int mi = max_element(cnt, cnt + 4) - cnt, x = 0;
	rep(i, 4 * n * n) if(col[i] == mi){
		cout << i / (2 * n) << " " << i % (2 * n) << endl;
		if(++x == n * n) break;
	}
	
	return 0;
}

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

int main(){
    double x1,x2,y1,y2,r;
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    
    r=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
    printf("%f",r);
    
    return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int> x(N), y(N);
  for (int i=0; i<N; i++){
    scanf("%d", &x[i]);
    scanf("%d", &y[i]);
  }
  //std::pair table[54][54];
  std::map<std::pair<int, int>, int> mp;
  for (int i=0; i<N; i++){
    for (int j=0; j<N; j++){
      if (i==j) continue;
      //table[i][j] = std::make_pair(x[i]-x[j], y[i]-y[j]);
      mp[std::make_pair(x[i]-x[j], y[i]-y[j])]++;
    }
  }
  int max = 0;
  for (auto &entry : mp){
    max = std::max(max, entry.second);
  }
  std::cout << N-max << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
 
const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;
 
int n, a[N], b[N], dp[1 << 18][18];

int f(int mask, int i){
	int x = __builtin_popcount(mask) ^ i;
	if(x & 1)
		return a[i];
	else
		return b[i];
}
int main()
{
	cin >> n;       
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];
	
	for(int i = 0; i < (1 << n); i++)
		for(int j = 0; j < n; j++)
			dp[i][j] = inf;
	for(int i = 0; i < n; i++)
		dp[1 << i][i] = 0;	                  
	for(int mask = 1; mask < (1 << n); mask++)
		for(int next = 0; next < n; next++)
			if(((mask >> next) & 1) == 0){
				int val = 0;
				for(int i = next; i < n; i++)
					if((mask >> i) & 1)
						val++;
				for(int last = 0; last < n; last++)
					if(((mask >> last) & 1) != 0 && f(mask, last) <= f(mask | (1 << next), next))
						dp[mask | (1 << next)][next] = min(dp[mask | (1 << next)][next] , dp[mask][last] + val);
			}
	int ans = inf;
	for(int i = 0; i < n; i++)
		ans = min(ans, dp[(1 << n) - 1][i]);
	if(ans == inf)
		ans = -1;
	cout << ans;
}


Measured memory_bytes: 18688
#include <boost/functional/hash.hpp>
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define DOFAST 
#define rep(i,a,n) for(int i=a,_n=(n);i<_n;i++)
#define repr(i,n,a) for(int i=n-1;i>=a;i--)
#define foreach(it,ar) for(auto it:ar)
#define All(x) x.begin(),x.end()
#define Sort(v) sort(v.begin(),v.end())
#define Endl '\n'
#define space <<" "<<
#define Print(x) cout<<x
#define Pair make_pair
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef long long ll;
typedef unordered_map<int,int> UMP;
struct TreeNode {
    int data;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int NodeData,int l, int r) {
        left = NULL;
        right = NULL;
        data = NodeData;
    }
};
ll gcd(ll a, ll b) {
    if(!a || !b) {
        return a|b;
    }
    unsigned int  zeros = __builtin_ctzll(a|b);
    a>>=__builtin_ctzll(a);
    do{
        b>=__builtin_ctzll(b);
        if(a>b) {
            swap(a,b);
        }
        b-=a;
    }while(b);
    return a<<zeros;
}
void Main(){
   int n,d;
   cin>>n>>d;
   ll dis = (ll)d * (ll)d;
   ll x,y;
   ll p;
   int count = 0;
   for(int i=0;i<n;i++){
       cin>>x>>y;
       p = x*x + y*y;
       if(p<=dis) count++;
   }
   cout<<count;
}

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int t; cin>>t;
    // while(t--)
    Main();
    return 0; 

} 



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

int main(){
  int A, B, K, N;
  cin >> A >> B >> K;
  
  if (A>B){
    N = B;
  }
  else{
    N = A;
  }
  
  int count = 0;
  for(int i = N; i > 0; i--){
    if(A%i == 0 && B%i == 0){
      count+=1;
    }
    if(count == K){
      cout << i << endl;
      break;
    }
  }
}

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

int main(){


    int H, W, h, w; cin >> H >> W >> h >> w;
    vector<vector<int> > a(H, vector<int> (W, 2000));
    
    for(int i = h - 1; i < H; i += h){
        for(int j = w - 1; j < W; j += w){
            a[i][j] = -2000 * (h * w - 1) - 1;
        }
    }

    int sum = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            sum += a[i][j];
        }
    }

    if(sum > 0){
        cout << "Yes" << endl;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cout << a[i][j] << " ";
            }
            cout << endl;
        }
    }else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int dp[1009][1009],mod=1e9+7;
string s[1009];
int bt(int x,int y)
{
//    cout<<x<<" "<<y<<"\n";
    if(s[x][y]=='#')return 0;
    if(dp[x][y]!=-1)return dp[x][y];
    dp[x][y]=(bt(x-1,y)+bt(x,y-1))%mod;
    return dp[x][y];
}
int n,m;
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>s[i];
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        if(s[i][0]=='#')
        {
            for(i;i<n;i++)dp[i][0]=0;
            continue;
        }
        dp[i][0]=1;
    }
    for(int i=0;i<m;i++)
    {
        if(s[0][i]=='#')
        {
            for(i;i<m;i++)dp[0][i]=0;
            continue;
        }
        dp[0][i]=1;
    }
    cout<<bt(n-1,m-1);
}


Measured memory_bytes: 5376
// マージソート
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 500000
const int INFTY = 2147483647;

int cmp_count = 0;

void mergeSort(int A[], int n, int left, int right);
void merge(int A[], int n, int left, int mid, int right);

int main(void)
{
    int A[MAX_N];
    int n;

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }

    // マージソートを実施
    mergeSort(A, n, 0, n);

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        if( i )
        {
            printf(" ");
        }

        printf("%d", A[i]);
    }

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

    return 0;
}

// マージソートを実施する関数
void mergeSort(int A[], int n, int left, int right)
{
    // 最小単位まで分割する
    if ( left + 1 < right )
    {
        int mid = ( left + right ) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
  }

  return;
}

// 分割された要素を並び替える関数
void merge(int A[], int n, int left, int mid, int right)
{

    vector<int> L, R;

    int n1 = mid - left;
    int n2 = right - mid;

    // L[0...n1], R[0...n2] を生成
    for(int i = 0; i < n1; i++)
    {
        // 前半部分の配列を作成する
        L.push_back(A[left + i]);
    }

    for(int i = 0; i < n2; i++)
    {
        // 後半部分の配列を作成する
        R.push_back(A[mid + i]);
    }

    // 前半と後半の配列の最後の要素に最大値を入れておく
    // ( 比較時の番兵として使用 )
    L.push_back(INFTY);
    R.push_back(INFTY);

    int i = 0;
    int j = 0;

    for(int k = left; k < right; k++)
    {
        // 前半部分の配列と後半部分の配列を比較する
        if ( L[i] <= R[j] )
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }

        cmp_count++;
    }
}



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

int main()
{
    int n,x,y,sum = 0;
    //int a[105];
    vector<int>a;
    vector<int>b;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(x%10==0)
            a.push_back(x);
        else
            b.push_back(x);
        sum +=x;
    }
    sort(b.begin(),b.end());
    if(b.size() == 0){
        cout<<0<<endl;
        return 0;
    }
    if(sum%10 == 0 && b.size())
        sum-= b[0];

    cout<<sum<<endl;
}



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

# 状態
INCREASING = 1
DECREASED_BY_1 = 2
FAIL = -1

state = INCREASING

for i in range(1, N): # i = 1, 2, ..., N - 1
    if state == INCREASING:
        if H[i] == H[i - 1] - 1: # 1減少
            state = DECREASED_BY_1
        elif H[i] <= H[i - 1] - 2: # 2以上減少
            state = FAIL
    elif state == DECREASED_BY_1:
        if H[i] > H[i - 1]: # 増加
            state = INCREASING
        elif H[i] < H[i - 1]: # 減少
            state = FAIL
    else:
        break

ans = "Yes" if state is not FAIL else "No"
print(ans)

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

int n, x, y, z, s, e[2], c[2];
vector<int> b[2];
string a;
bool v[2][8005][8005];
bool f(int p, int q, int z) {
	if (q > e[z]) return false;
	if (q == e[z]) return true;
	if (v[z][p][q]) return false;
	if (p == b[z].size()) return false;
	v[z][p][q] = true;
	return (f(p + 1, q, z) | f(p + 1, q + b[z][p], z));
}
int main()
{
	int i;
	cin >> a;
	cin >> x >> y;
	z = 0;
	for (i =0; i < a.size(); i++) {
		if (a[i] == 'F') s++;
		else {
			b[z].push_back(s);
			c[z] += s;
			z = 1 - z;
			s = 0;
		}
	}
	b[z].push_back(s);
	c[z] += s;
	if ((c[0] + x) % 2 || (c[1] + y) % 2) {
		cout << "No";
		return 0;
	}
	e[0] = (c[0] + x) / 2;
	e[1] = (c[1] + y) / 2;
	if (f(1, b[0][0], 0) && f(0, 0, 1)) cout << "Yes";
	else cout << "No";
    return 0;
}


Measured memory_bytes: 34304
/*
反省点
二次元配列は大きくしすぎると実行前にエラーが出てしまう。
maxを変数に使うと、max関数が使えないので注意s
DP法の場合、配列を引数にしたら、計算量がえぐいことになってしまう。
そこの注意をしておこう。
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define big 1000000007
vector<vector<ll>> memo(200000, vector<ll>(3));
vector<vector<ll>> done(200000, vector<ll>(3));
vector<vector<ll>> data1(200000, vector<ll>(3));
ll n;
ll dp(int m, int p)
{ //(基本的にpは0,1,2で前の状態をあら合わす。)
    if (m == n)
    {
        return 0;
    }
    if (p != -1)
    {
        if (done[m][p] == 1)
        {
            //    cout <<"dakfa";
            return memo[m][p];
        }
    }
    ll res = -1;
    ll count;
    for (int i = 0; i < 3; i++)
    {
        if (i == p)
        {
            continue;
        }
        count = data1[m][i] + dp(m + 1, i);
        if (res == -1)
        {
            res = count;
        }
        else
        {
            res = max(res, count); //とりあえず
        }
    }
    if (p != -1)
    {
        memo[m][p] = res;
        done[m][p] = 1;
    }

    return res;
}
int main()
{

    cin >> n;
    data1.resize(n);
    rep(i, data1.size()) data1[i].resize(3, 0);
    memo.resize(n);
    rep(i, n) cin >> data1[i][0] >> data1[i][1] >> data1[i][2];
    memo.resize(n);
    done.resize(n);
    rep(i, memo.size()) memo[i].resize(3, 0);
    memo.resize(n);
    rep(i, memo.size()) done[i].resize(3, 0);
    cout << dp(0, -1) << endl; //前の状態が指定された時の今後の最大値
                               /* rep(i,n){
  rep(j,3){
  cout <<done[i][j];
  
  }
  }*/
}


Measured memory_bytes: 39296
import java.util.Scanner;

// D - Caracal vs Monster
// https://atcoder.jp/contests/abc153/tasks/abc153_d
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long H = Long.parseLong(scanner.next());
        scanner.close();

        System.out.println(f(H));
    }

    private static long f(long H) {
        if (H == 1) return 1;
        return f(H / 2) * 2 + 1;
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
int N, Y;
 
int main() {
	cin >> N>> Y;
	int a = 0, b = 0, c = 0;
	bool ans = false;

	for (int i = 0; i <= (Y - 1000 * N) / 9000; i++) {
		a = i;
		if (floor((Y - 1000 * N - 9000*a) / 4000) == (double)(Y - 1000 * N - 9000 * a) / 4000 ){
			b = (int)floor((Y - 1000 * N - 9000 * a) / 4000);
			if (N - a - b >= 0) {
				c = N - a - b;
				ans = true;
				break;
			}
		}
	}

	if (!ans) {
		a = -1;
		b = -1;
		c = -1;
	}
	cout << a << " " << b << " " << c << endl;

}

Measured memory_bytes: 256
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */

    //#pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    #define mp make_pair
    #define pb push_back
    //#define M_PI           3.1415926535  /* pi */
    typedef long double ld;
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef vector<ll> vi;
    const int maxN = 100224;

    void solve(){
      ll n, m,y,c;
      cin >> n >> m >>c;
      ll b[m],x, sum=0, cnt=0;
      rep(i,m) cin >> b[i];
      rep(j,n){
        sum = c;
        rep(i,m) cin>>x, sum+=x*b[i];
        //cout<<sum<<endl;
        sum > 0 ? cnt++:0; 
      }
      cout<<cnt<<endl;
    }
    
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      solve();
      return 0;
    }   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD ((int)(1e9+7))
using namespace std;

const int N=1e5+5;

vector<int> adj[N];
int n,k;

long long go(int node,int pa,int cpa,int ccp)
{
	long long ans=k-(cpa+ccp);
	//cout << node << " " << ans << " " << cpa << " " << ccp << endl;
	int co=0;
	for(int i:adj[node])
	{
		if(i!=pa)
			ans=(ans*go(i,node,min(cpa+1,2),co++))%MOD;
	}
	return ans;
}

int main()
{
	cin >> n >> k;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	cout << go(1,0,0,0) << endl;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define MAXN 32768
#define MOD 998244353
#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
inline int fxp(int s, int n=MOD-2){int a=1; for(; n; n&1 ? a = 1ll*a*s%MOD : 0, s = 1ll*s*s%MOD, n >>= 1); return a;}
int A[MAXN+5], B[MAXN+5], Rv[MAXN+5], fac[MAXN+5], efac[MAXN+5], Gw[40], m, n, x, y, Ans; char S[MAXN+5], T[MAXN+5];
inline void RV(int n){for(rint i = 1, l = ~-ilogb(n); i < n; Rv[i] = Rv[i>>1]>>1|(i&1)<<l, i++);}
void NTT(int R[], int n, int z)
{
	static int root, per, t; for(rint i = 0; i < n; i<Rv[i]?swap(R[i],R[Rv[i]]),0:0, i++);
	for(rint d = 0, i, j, m; (m=1<<d) < n; d++) for(i = 0, per = Gw[d]; i < n; i += m<<1) for(j = 0, root = 1; j < m; j++)
		t = 1ll*R[i+j+m]*root%MOD, (R[i+j+m]=R[i+j]-t)<0?R[i+j+m]+=MOD:0, (R[i+j]+=t)<MOD?:R[i+j]-=MOD, root = 1ll*root*per%MOD;
	if(z<0){t = fxp(n); for(rint i = 0; i < n; R[i] = 1ll*t*R[i]%MOD, i++); reverse(R+1,R+n);}
}
int main()
{
	for(rint i = 0; i < 20; Gw[i] = fxp(3,~-MOD/(1<<-~i)), i++); scanf("%s%s",S+1,T+1), m = strlen(S+1);
	for(rint i = 1; i <= m; x += S[i]^'0'&&T[i]^'0', y += S[i]^'0'&&T[i]^'1', i++); for(n = 1; n <= x; n <<= 1); RV(n<<=1); m = x+y+1;
	for(rint i = fac[0] = 1; i <= m; fac[i] = 1ll*i*fac[i-1]%MOD, i++); efac[m] = fxp(fac[m]); for(rint i = m; i; efac[i-1] = 1ll*i*efac[i]%MOD, i--);
	for(rint i = 0; i <= x; B[i] = efac[i+1], i++); A[0] = 1;
	for(rint i, t = y; t; t >>= 1)
	{
		if(NTT(B,n,1), t&1){NTT(A,n,1); for(i = 0; i < n; A[i] = 1ll*A[i]*B[i]%MOD, i++); NTT(A,n,-1); for(i = x+1; i < n; A[i++] = 0);}
		for(i = 0; i < n; B[i] = 1ll*B[i]*B[i]%MOD, i++); NTT(B,n,-1); for(i = x+1; i < n; B[i++] = 0);
	}	for(rint i = 0; i <= x; (Ans+=A[i])<MOD?:Ans-=MOD, i++); printf("%d\n",1ll*fac[x]*fac[y]%MOD*fac[x+y]%MOD*Ans%MOD); return 0;
}

Measured memory_bytes: 768