akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int n;
    int h[21];
    cin >> n;
    for(int i=0; i< n; i++){
        cin >> h[i];
    }

    int count = 1;
    for(int i=1; i< n; i++){
        bool visible = true;
        for(int j=0; j<i; j++){
            if(h[i] < h[j]){
                visible = false;
            }
        }
        if(visible){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int x = 0;   // i番目の身長
  int sum = 0; // 乗れる人数
  // 身長がKcm以上であるかをN回確認する
  
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x >= K) {
      sum++;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N; cin >> N;
    ll ans = 0;
    for(ll i = 1; i * i <= N; i++)
    {
        if(N % i == 0)
        {
            ll m = N / i - 1;
            if(i < m) ans += m;
        }
    }
    cout << ans << endl;
}

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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef pair<int, int> PII;

template<typename T> inline bool chkmin(T &a, T b) {return b < a ? a = b, 1 : 0;}
template<typename T> inline bool chkmax(T &a, T b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("D.in", "r", stdin);
	freopen ("D.out", "w", stdout);
#endif
}

int h, w, n;

map<int, map<int, int> > M;
set<PII> S[10];

inline void Update(int x, int y) {
	if (x < 2 || y < 2 || x >= h || y >= w) return ;
	int tot = 0;
	For (i, x - 1, x + 1) For (j, y - 1, y + 1)
		tot += M[i][j];
	S[tot].insert(make_pair(x, y));
}

const int N = 5e5 + 1e3;

int a[N], b[N];

int main() {

	File();

	h = read(); w = read(); n = read();
	For (i, 1, n) {
		a[i] = read(); b[i] = read();
		M[a[i]][b[i]] = 1;
	}

	For (i, 1, n)
		For (x, -1, 1) For (y, -1, 1) Update(a[i] + x, b[i] + y);

	long long All = 1ll * (h - 2) * (w - 2);
	For (i, 1, 9) All -= S[i].size();

	printf ("%lld\n", All);
	For (i, 1, 9)
		printf ("%d\n", S[i].size());

	return 0;

}


Measured memory_bytes: 207232
function Main(input) {
    input = input.split('\n');
    var n = parseInt(input[0], 10);
    var testNum = input.slice(1, n+1);
    var mochi = testNum.filter(function(num,i,test){
      return test.indexOf(num) === i;
    });
    console.log(mochi.length);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include <iostream>
#define N 4
using namespace std;
int Ret(int);
int main(){
  int n,i,j,k,l,c[N],cal,cnt,min,min10,min50,min100,min500,flag=0;
  while(1){
    min=100;
    min10=min50=min100=min500=0;
    cin >> n;
    if(n==0) break;
    if(flag!=0) cout << endl;
    for(i=0;i<N;i++) cin >> c[i];
    for(i=0;i<=c[0];i++){
      for(j=0;j<=c[1];j++){
    for(k=0;k<=c[2];k++){
      for(l=0;l<=c[3];l++){
        cal=i*10+j*50+k*100+l*500;
        if(cal>=n){
          cnt=c[0]-i+c[1]-j+c[2]-k+c[3]-l;
          cnt+=Ret(cal-n);
          if(cnt<min){
        min=cnt;
        min10=i;
        min50=j;
        min100=k;
        min500=l;
          }
        }
      }
    }
      }
    }
    if(min10!=0) cout << 10 << ' ' << min10 << endl;
    if(min50!=0) cout << 50 << ' ' << min50 << endl;
    if(min100!=0) cout << 100 << ' ' << min100 << endl;
    if(min500!=0) cout << 500 << ' ' << min500 << endl;
    flag=1;
  }
  return 0;
}
int Ret(int n){
  int retcnt,n10,n50,n100,n500;
  n500=n/500;
  n%=500;
  n100=n/100;
  n%=100;
  n50=n/50;
  n%=50;
  n10=n/10;
  retcnt=n10+n50+n100+n500;
  return retcnt;
}

Measured memory_bytes: 1160
import sys

N = int(sys.stdin.readline())
#L,R,d = map(int, sys.stdin.readline().split())

ans = 0

for i,n in enumerate(map(int, sys.stdin.readline().split())):
    if i % 2 != 0:
        continue
    if n % 2 == 0:
        continue
    ans += 1


print(ans)


Measured memory_bytes: 61628
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M=mi()

    def divisors(n):
        res = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n//i)

        return res

    D = divisors(M)
    ans = 1
    for d in D:
        X = M // d
        if X-N+1 > 0:
            ans = max(ans,d)
    
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 64216
from itertools import permutations
from math import factorial, sqrt

n = int(input())
a = [x for x in range(1, n+1)]
a = list(permutations(a))
xy = [list(map(int, input().split())) for _ in range(n)]
l = len(a)
result = 0

for ae in a:
  for i in range(n-1):
    tmp = 0
    tmp += (xy[ae[i+1]-1][0] - xy[ae[i]-1][0]) ** 2
    tmp += (xy[ae[i+1]-1][1] - xy[ae[i]-1][1]) ** 2
    result += sqrt(tmp)
print(round(result / l, 10))

Measured memory_bytes: 7972
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	int a  = sc.nextInt();
      	int b  = sc.nextInt();
      	double h  = sc.nextDouble();
      	double m  = sc.nextDouble();
      	double hk = ((h / 12) * 360) + ((m / 60) * 30);
      	//System.out.println(hk);
      	double mk = 360 * (m / 60);
      	//System.out.println(mk);
      	double k = 0;
      	if(mk >= hk){
          k = mk -hk;
        }else{
          k = hk - mk; 
        }
      	if (k>=180){
          k = 360 - k;
        }
      	//System.out.println(k);      
      	double cosk = Math.cos(Math.toRadians(k));
      	//System.out.println(cosk);      
       	double c = (a*a) + (b*b) - (2*a*b*cosk);
        System.out.println(Math.sqrt(c));
    }
}

Measured memory_bytes: 37496
import itertools
import math
n, d = map(int, input().split())
X = [list(int(i) for i in input().split()) for i in range(n)]
ans = 0

for v in itertools.combinations(X, 2):
  s = 0
  for i in range(d):
    s += (v[0][i] - v[1][i]) ** 2
  if math.sqrt(s).is_integer():
    ans += 1

print(ans)


Measured memory_bytes: 3060
x = []
y = []

i = 0

while True:
    indata = input().split()
    x.append(indata[0])
    y.append(indata[1])
    if int(x[i]) == 0 and int(y[i]) == 0:
        break
    i += 1

for j in range(len(x)):
    if int(x[j]) == 0 and int(y[j]) == 0:
        pass
    else:
        if int(x[j]) < int(y[j]):
            print("{0} {1}".format(x[j],y[j]))
        else:
            print("{0} {1}".format(y[j],x[j]))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
using namespace std;


int main(){
    IOS;

    int a, b;
    cin >> a >> b;
    cout << ((a * 3) + b) / 2;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	long long n,m,ans=1;
	cin>>n>>m;
	for(int i=m/n;i>=1;i--){
		if(m%i==0){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> P;
static const int INF=1<<24;

string s;
string qf;
set<string> vis;

bool check(string a){
	char t=a[0];
	rep(i,a.size()){
		if(t!=a[i]) return false;
	}
	return true;
}

int main(){
	
	while(cin>>s,s[0]!='0'){
		//cout<<s<<endl;
		vis.clear();
		int ans=-1;
		queue<string> qu;
		if(check(s)){
			cout<<"0"<<endl;
			continue;
		}
		vis.insert(s);
		qu.push(s);
		bool f1=false;
		bool f2=false;
		bool f3=false;
		while(!qu.empty()){
			f1=false;
			f2=false;
			ans++;
			int qs=qu.size();
			rep(i,qs){
				qf=qu.front();
				qu.pop();
				rep(j,s.size()-1){
					if(qf[j]!=qf[j+1]){
						string tmp=qf;
						tmp[j] = tmp[j+1] = 'r'+'g'+'b'-qf[j]-qf[j+1];
						if(vis.find(tmp)==vis.end()){
							qu.push(tmp);
							vis.insert(tmp);
							f1=true;
							if(check(tmp)) f3=true;
						}
						f2=true;
					}
				}
			}
			if(f3) break;
		}
		if(f3) cout<<ans+1<<endl;
		else cout<<"NA"<<endl;
		
	}
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  for (int j = 0; j < N; j++)
    cin >> C.at(j);
  
  int count = 0;
  for (int k = 0; k < N; k++) {
    if (V.at(k) - C.at(k) > 0)
      count += V.at(k) - C.at(k);
  }
  cout << count << endl;
}

Measured memory_bytes: 3584
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


bool ask(int pos, string &s)
{
    cout << pos << endl;

    cin >> s;

    return s == "Vacant";
}

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

    int N;
    cin >> N;


    //0番目を最初に質問
    string s;
    if (ask(0, s)) return 0;

    int prev = -1;

    int lb = 0;
    int ub = N;
    rep(i, 19)
    {
        int mid = (lb + ub) / 2;

        //見つからないまま収束した場合ブレーク
        if (mid == prev) break;

        string t;
        if (ask(mid, t)) return 0;

        if (mid % 2 == 0 && t == s || mid % 2 != 0 && t != s)
        {
            lb = mid;
        }
        else
        {
            ub = mid;
        }

        prev = mid;
    }

    //収束した場合、左右どちらかが空席
    if (ub + 1 <  N) if (ask(ub + 1, s)) return 0;
    if (ub - 1 >= 0) if (ask(ub - 1, s)) return 0;

    return 0;
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

// 移動の累積和を計算する
int main(int argc, char const* argv[])
{
    int h,w,d;
    cin >> h >> w >> d;
    vector<PII> a(h*w+1,MP(0,0));
    VI rui(h*w+1,0);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int tmp;
            cin >> tmp;
            a[tmp] = MP(i,j);
        }
    }
    
    // 累積和
    for (int i = 1; i <= d; i++) {
        for (int j = d+i; j <= h*w; j += d) {
            rui[j] = rui[j-d] + abs(a[j].first - a[j-d].first) + abs(a[j].second - a[j-d].second);
        }
    }

    int q;
    cin >> q;
    int l,r;
    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        cout << rui[r] - rui[l] << endl;
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,a,b; cin>>x>>a>>b;
    if (b<=a){
        cout<<"delicious\n";
    }else if(b<=a+x){
        cout<<"safe\n";
    }else{
        cout<<"dangerous\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const int vx[]={1,0,-1,0}, vy[]={0,1,0,-1};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

int dp[100010], h[100010];
vector<int> g[100010];

struct UnionFind{
	vector<int> data;
	
	UnionFind(int sz){
		data.assign(sz, -1);
	}
	
	void unite(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return ;
		if(data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}
	
	int find(int k){
		if(data[k] < 0) return k;
		return data[k] = find(data[k]);
	}
	
	bool same(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return true;
		else return false;
	}
};

int solve(int p, int par = -1){
	if(dp[p]) return dp[p];
	
	int c = !(h[p] % 2);
	for(auto e:g[p]){
		if(e == par) continue;
		c += solve(e, p);
	}
	
	return c;
}

int main(){
	int n, m; cin >> n >> m;
	UnionFind uf(n);
	REP(i,0,m){
		int a, b; cin >> a >> b; a--; b--;
		if(uf.same(a, b)){
			g[a].push_back(b);
			g[b].push_back(a);
			uf.unite(a, b);
			h[a]++; h[b]++;
		}else{
			h[a]++; h[b]++;
		}
	}
	
	REP(i,0,n) if(h[i] % 2){cout << "NO" << endl; return 0;}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N, M, i, j;
	scanf("%d", &N);
	vector<int> a(N + 1);
	for(i = 1; i <= N; i++){
		scanf("%d", &a[i]);
	}
	vector<int> b = a;
	for(i = N, M = 0; i > 0; i--){
		for(j = 2; i * j <= N; j++){
			b[i] ^= b[i * j];
		}
		M += b[i];
	}
	printf("%d\n", M);
	for(i = 1; i <= N; i++){
		if(b[i] == 1){
			printf("%d ", i);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<map>
#include<vector>

using namespace std;
int main()
{
    int n;
    cin>>n;
    int div = n,sum=0;
    while(div)
    {
        sum = sum + (div%10);
        div/=10;
    }
    if(n % sum == 0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 504
/*
  AtCoder Beginner Contest 096
  C - Grid Repainting 2
*/

#include<iostream>
#include<string>
using namespace std;

int H, W;
bool s[52][52] = {0}; // true: black, false: white

bool check(int y, int x) {
  return (s[y-1][x] || s[y+1][x] || s[y][x-1] || s[y][x+1]);
}

int main() {
  scanf("%d%d", &H, &W);
  char buf[51];
  for (int y = 1; y <= H; ++y) {
    scanf("%s", buf);
    for (int x = 1; x <= W; ++x) {
      if (buf[x-1] == '#') s[y][x] = true;
    }
  }

  for (int y = 1; y <= H; ++y) for (int x = 1; x <= W; ++x) {
    if (s[y][x] && !check(y,x)) {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fill(x,y) memset(x,y,sizeof(x))
#define INF 999999999
#define MOD 1000000007
#define IOS cin.tie(0); ios::sync_with_stdio(false)
#define VV vector<vector<int>>
#define PQ priority_queue<int>
#define PQG priority_queue<int,vector<int>,greater<int>>
using namespace std;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    string S; cin >> S;
    string s; string t; int cnt=0;
    bool can = false;
    rep(i,S.size()){
        if(can){t.erase(all(t));can=false;}
        if(i==0) {s=S[0]; cnt++;}
        else {
            t+=S[i];
            if(s==t) {continue;}
            else {
                s=t;
                cnt++;
                can = true;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


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

using namespace std;

int main() {
    long long a, b, x;
    cin >> a >> b >> x;
    long long ans = b / x;
  	if (a == 0)
    	ans++;
    else
        ans -= a / x - (a % x == 0);
  	cout << ans;
}

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

int main(){
  int n;
  map<int, int> mp;
  queue<int> que;

  int tmp;
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> tmp;
    if(mp[tmp] == 0){
      que.push(tmp);
      mp[tmp]++;
    }else{
      mp[tmp]++;
    }
  }

  long long a1 = 0, a2 = 0;
  while(!que.empty()){
    tmp = que.front(); que.pop();
    if(mp[tmp] >= 2){
      if(a1 < tmp){
        if(mp[tmp] >= 4){
          a2 = tmp;
        }else{
          a2 = a1;
        }
        a1 = tmp;
      }else if(a2 < tmp){
        a2 = tmp;
      }
    }
  }

  cout << a1 * a2 << endl;

  return 0;
}



Measured memory_bytes: 5376
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if((c-a)*(c-b) < 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    if(n%2==0){
        cout << n;
    }
    else{
        cout << n*2;
    }

    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
P = gets.split.map(&:to_i)
s = P.sort

diff = 0
(0...N).each do |i|
  if P[i] != s[i]
    diff += 1
  end
end

if diff <= 2
  print "YES\n"
else
  print "NO\n"
end

Measured memory_bytes: 14384
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
d = [0] * (M - 1)

if N >= M:
    print(0)
else:
    for i in range(M - 1):
        d[i] = abs(X[i + 1] - X[i])
    d.sort(reverse=True)
    print(sum(d[N - 1:]))

Measured memory_bytes: 13960
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
vector<int> v[maxn];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, m = 0, q = 0, x = 0, y = 0;
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> x >> y; --x; --y;
		v[x].pb(y); v[y].pb(x);
	}
	cin >> q;
	vector<int> a(q);
	vector<int> d(q);
	vector<int> c(q);
	for (int i = 0; i < q; ++i)
	{
		cin >> a[i] >> d[i] >> c[i]; --a[i];
	}
	vector<int> vis(n, -1);
	vector<int> colour(n);
	for (int i = q - 1; i >= 0; --i)
	{
		queue<int> q;
		auto insert = [&](int node, int dist)
		{
			if (vis[node] < dist)
			{
				vis[node] = dist;
				if (!colour[node])
					colour[node] = c[i];
				q.push(node);
			}
		};
		insert(a[i], d[i]);
		while (!q.empty())
		{
			int fr = q.front(); q.pop();
			if (vis[fr])
			{
				for (auto j : v[fr])
					insert(j, vis[fr] - 1);
			}
		}
	}
	for (auto &i : colour)
		cout << i << "\n";
}

Measured memory_bytes: 11240
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a<b)swap(a,b);
    int ans=0;
    ans+=a;
    a--;
    ans+=max(a,b);
    cout<<ans;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long long ll;
const int N=262144;
int n,fir[N],sec[N],a[N];
void fwt(int n)
{
	for(int m=1;m<n;m<<=1)
	{
		for(int k=0;k<n;k+=(m<<1))
			for(int i=k;i<k+m;i++)
			{
				if(fir[i]>=fir[i+m])
				{
					sec[i+m]=fir[i+m]; fir[i+m]=fir[i];
					sec[i+m]=max(sec[i+m],sec[i]);
				}
				else
				{
					sec[i+m]=max(sec[i+m],fir[i]);
				}
			}
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<(1<<n);i++) scanf("%d",&a[i]),fir[i]=a[i];
	fwt(1<<n);
	int ans=0;
	for(int i=1;i<(1<<n);i++) 
	{	
		ans=max(ans,fir[i]+sec[i]);
		printf("%d\n",ans);
	}
	

	return 0;
}


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

int main() {
	int a, b, c; cin >> a >> b >> c;

	cout << (max({ a,b,c }) == 7 && (a + b + c) - max({ a,b,c }) == 10 ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}

int main() {
	int n;
	ll a[100000];
	scanf("%d", &n);
	REP(i, n) {
		scanf("%lld", &a[i]);
	}

	ll minS = 1e9;
	int cnt = 0;
	REP(i, n) {
		if (a[i] < 0) {
			cnt = 1 - cnt;
		}
		minS = Minl(minS, abs((int)a[i]));
	}
	ll ans = 0;
	REP(i, n)ans += abs((int)a[i]);
	if (cnt)ans -= minS * 2;
	PRINTL(ans);
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
 
#define MAX_V 100000
#define INF (1<<29)
 
using namespace std;
 
vector<int>G[MAX_V];
int par[MAX_V],pnum[MAX_V],lowest[MAX_V],num;
bool used[MAX_V];
 
void dfs(int v,int prev){
  pnum[v]=num,lowest[v]=num;
  num++;
  used[v]=true;
 
  for(int i=0;i<G[v].size();i++){
    int nx=G[v][i];
    if(!used[nx]){
      par[nx]=v;
      dfs(nx,v);
      lowest[v]=min(lowest[v],lowest[nx]);
    }
    else if(nx!=prev){
      lowest[v]=min(lowest[v],pnum[nx]);
    }
  }
}
 
int main(void){
 
  int n,m;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
 
  fill(pnum,pnum+MAX_V,INF);
  fill(lowest,lowest+MAX_V,INF);
  fill(used,used+MAX_V,false);
 
  dfs(0,-1);

  int cnt=0;
  vector<int>ans;
  for(int i=0;i<n;i++){
    if(par[i]==0 && i!=0)cnt++;
    if(par[i]>0 && lowest[i]>=pnum[par[i]])ans.push_back(par[i]);
  }
 
  if(cnt>=2)ans.push_back(0);
  sort(ans.begin(),ans.end());
  ans.erase(unique(ans.begin(),ans.end()),ans.end());
  for(int i=0;i<ans.size();i++)cout << ans[i] << endl;
 
  return 0;
}

Measured memory_bytes: 5908
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << ", "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << ", "; cerr << "\n"; }
#define dbm(map) cerr << #map << ":"; for (auto p : map) cerr << "(" << p.first << ", " << p.second << "), "; cerr << "\n";
#define YN(f) cout << (f ? "YES" : "NO") << "\n"
#define Yn(f) cout << (f ? "Yes" : "No") << "\n"
#define yn(f) cout << (f ? "yes" : "no") << "\n"
using ll = long long;
using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vb = vector<bool>;
using vvi = vector<vi>; using vvl = vector<vl>; using vvb = vector<vb>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using vpii = vector<pii>; using vpll = vector<pll>;
using ti3 = tuple<int, int, int>; using tl3 = tuple<ll, ll, ll>;
using mii = map<int, int>; using mil = map<int, ll>; using mli = map<ll, int>; using mll = map<ll, ll>;

int main() {
	while (true) {
		int w, h; cin >> w >> h;
		if (h == 0 and w == 0) break;
		vector<vvb> g(h, vvb(w, vb(4))); // g[i][j][k]:(i, j)から下/右/上/左に進めるか	
		rep(i, h - 1) {
			rep(j, w - 1) {
				int t; cin >> t;				
				if (t == 0) g[i][j][1] = g[i][j + 1][3] = true;
			}
			rep(j, w) {
				int t; cin >> t;
				if (t == 0) g[i][j][0] = g[i + 1][j][2] = true;
			}
		}
		rep(j, w - 1) {
			int t; cin >> t;				
			if (t == 0) g[h - 1][j][1] = g[h - 1][j + 1][3] = true;
		}
		/*
		rep(k, 4) {
			rep(i, h) {
				rep(j, w) cout << g[i][j][k];
				cout << endl;
			}
			cout<< endl;
		}
		*/
		vvi d(h, vi(w, -1));
		queue<pii> q;
		pii p(0, 0); q.push(p); d[0][0] = 0;
		vi di = { 1, 0, -1, 0 }, dj = { 0, 1, 0, -1 };
		while (!q.empty()) {
			pii u = q.front(); q.pop();
			int ui, uj; tie(ui, uj) = u;
			rep(k, 4) {
				if (!g[ui][uj][k]) continue;
				int vi = ui + di[k], vj = uj + dj[k];
				if (vi < 0 or vi >= h or vj < 0 or vj >= w) continue;
				if (d[vi][vj] != -1) continue;
				d[vi][vj] = d[ui][uj] + 1;
				pii v(vi, vj); q.push(v);				
			}			
		}
		// dbvv(d);
		cout << d[h - 1][w - 1] + 1 << endl;
	}
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n, m; cin >> n >> m;
    vll x(m); rep(i, m) cin >> x[i];
    sort(all(x));

    vll dist(m-1);
    rep(i, m-1) dist[i] = x[i+1]-x[i];

    sort(all(dist));
    ll ans = 0;
    rep(i, m-n) ans += dist[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4708
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if (e - a <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF 100000000
#define MOD 10007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

//#define DEBUG

int main_(){
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  H-=h;
  W-=w;
  cout<<H*W<<endl;
  return 0;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  vector<string>test;
  /*
   * input for debug
   */
  for(int i=0;i<test.size();++i){
    stringbuf buf;
    streambuf*out=cout.rdbuf(&buf);
    cout<<test[i]<<flush;
    cout.rdbuf(out);
    streambuf*in=cin.rdbuf(&buf);
    main_();
    cin.rdbuf(in);
    cout<<endl;
  }
#else
  main_();
#endif

  return 0;
}


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

int main(void){
	int x = 0, N;
	string S;
	cin >> N >> S;

	int m = x;
	for(int i=0;i<S.size();i++){
		if( S[i] == 'I' )
			x++;
		else
			x--;
		m = max(m,x);
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
class Union_Find():
    def __init__(self, num):
        self.par = [-1]*(num+1)
        self.siz = [1]*(num+1)

    def same_checker(self, x, y):
        return self.find(x) == self.find(y)

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)

    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
                self.siz[rx] += self.siz[ry]
            elif self.par[rx] > self.par[ry]:
                self.par[rx] = ry
                self.siz[ry] += self.siz[rx]
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
                self.siz[rx] += self.siz[ry]
        return

    def size(self, x):
        return self.siz[self.find(x)]

n, m = map(int, input().split())
lang = [[] for i in range(m+1)]
for i in range(n):
    l = list(map(int, input().split()))
    for j in range(l[0]):
        lang[l[j+1]].append(i)

tree = Union_Find(n)
for i in range(1, m+1):
    for j in range(len(lang[i])-1):
        tree.union(lang[i][j+1], lang[i][j])

if tree.size(0) == n:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 15900
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ab = a*b;
		int c = sc.nextInt();
		int d = sc.nextInt();
		int cd = c*d;
		System.out.println(String.valueOf((ab > cd) ? ab : cd));
	}
}

Measured memory_bytes: 9796
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <limits.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int n, k;
    char s[100001];
    int cnt[200001];
    int ptr;
    char last = ' '; // not '0' and not '1'
    int lastpos;
    int sum;
    int i;
    int max;

    scanf("%d %d", &n, &k);
    scanf("%s", s);

    for (i = 0; i < 200001; i++) {
        cnt[i] = 0;
    }

    lastpos = 0;
    last = s[lastpos];
    ptr = 0;
    i = 0;
    do {
        i++;
        if (last != s[i]) {
            int len = i - lastpos;
            int dest = ptr + (last - '0');
            cnt[dest] = len;

            if (last == '1') {ptr += 2;}
            lastpos = i;
            last = s[lastpos];
        }
    } while(s[i] != '\0');

    sum = 0;
    for (i = 0; i < k * 2; i++) {
        sum += cnt[i];
    }
    max = sum;

    for (i = k * 2; cnt[i] != 0; i++) {
        if (i % 2 == 0) {
            sum += cnt[i];
            sum -= cnt[i - (k * 2)];
            if (i > (k * 2 + 1)) {
                sum -= cnt[i - (k * 2 + 1)];
            }
        } else {
            sum += cnt[i];
        }
        if (sum > max) {max = sum;}
    }

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

    return 0;
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define endl '\n'



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

	string s, t;
	cin >> s >> t;
	t.resize(t.size() - 1);
	if (s.compare(t))
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	//system("pause");
	return 0;
}

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

class SegmentTree {
private:
	int sz;
	vector<int> ws;
	vector<int> val;
	vector<int> lazy;
	void push(int k, int l, int r) {
		if (lazy[k] == 0) return;
		lazy[k] = 0;
		val[k] = ws[r] - ws[l] - val[k];
		if (r - l != 1) {
			lazy[k * 2] ^= 1;
			lazy[k * 2 + 1] ^= 1;
		}
	}
	void flip(int a, int b, int k, int l, int r) {
		push(k, l, r);
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			lazy[k] ^= 1;
			push(k, l, r);
			return;
		}
		flip(a, b, k * 2, l, (l + r) >> 1);
		flip(a, b, k * 2 + 1, (l + r) >> 1, r);
		val[k] = val[k * 2] + val[k * 2 + 1];
	}
public:
	SegmentTree() : sz(0), ws(vector<int>(1, 0)), val(vector<int>()), lazy(vector<int>()) {};
	SegmentTree(vector<int> w_) {
		sz = 1;
		while (sz < w_.size()) sz <<= 1;
		val = vector<int>(2 * sz, 0);
		lazy = vector<int>(2 * sz, 0);
		ws = vector<int>(sz + 1);
		for (int i = 0; i < w_.size(); i++) ws[i + 1] = w_[i];
		for (int i = 0; i < sz; i++) ws[i + 1] += ws[i];
	}
	void flip(int l, int r) {
		flip(l, r, 1, 0, sz);
	}
	int getsum() {
		return val[1];
	}
};

int n, q, p[100009], c[100009], cl[100009], cr[100009], cnt; vector<int>x[100009]; bool used[100009];

void dfs(int pos) {
	if (used[pos] == true) return;
	used[pos] = true;
	cl[pos] = cnt; cnt++;
	for (int i = 0; i < x[pos].size(); i++) {
		dfs(x[pos][i]);
	}
	cr[pos] = cnt;
}

int main() {
	cin >> n >> q;
	for (int i = 2; i <= n; i++) {
		cin >> p[i];
		x[p[i]].push_back(i);
	}
	for (int i = 1; i <= n; i++) {
		string t; cin >> t;
		if (t == "G") c[i] = 1;
		else c[i] = 0;
	}
	dfs(1);
	vector<int>S(n, 1);

	SegmentTree X(S);
	for (int i = 1; i <= n; i++) {
		if (c[i] == 1) X.flip(cl[i], cl[i] + 1);
	}
	for (int i = 1; i <= q; i++) {
		int A; cin >> A;
		X.flip(cl[A], cr[A]);
		int Z = X.getsum();
		if (Z > n / 2) cout << "broccoli" << endl;
		else cout << "cauliflower" << endl;
	}
	return 0;
}


Measured memory_bytes: 18168
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> P;
long long int H,W;
long long int id(long long int i,long long int j){return i*W+j;}
int main(){
	int flag;
	long long int M,h,w,ans=0,sum;
	cin>>H>>W>>M;
	P row[H],col[W];
	map<long long int,int> bomb;
	
	for(int i=0;i<H;i++){
		row[i].second=i;
		row[i].first = 0;
	}
	for(int i=0;i<W;i++){
		col[i].second=i;
		col[i].first = 0;
	}
	for(int i=0;i<M;i++){
		cin>>h>>w;
		h--;w--;
		bomb[id(h,w)]=1;
		row[h].first++;
		col[w].first++;
	}
	sort(row,row+H);
	sort(col,col+W);
	for(int i=H-1;i>=0;i--){
		for(int j=W-1;j>=0;j--){
			flag = bomb[id(row[i].second,col[j].second)];
			sum=row[i].first+col[j].first;
			sum-=flag;
			if(col[j].first<col[W-1].first)break;
			else ans=max(sum,ans);
			if(!flag)break;
		}
		if(row[i].first<row[H-1].first)break;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 45772
// finish date: 2019/07/20

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) {
        cin >> A[i];
    }
//    int med = N / 2;
//    int st = 1;
//    int en = N + 1;
//    while (st <= en) {
//        med = (en - st) / 2;
    vi seq(2 * N + 1, INF);
//    FOR(i, N, 2 * N + 1) seq[i] = INF;
    int cnt = 0;
    rep(i, N) {
        auto Iter = upper_bound(seq.begin(), seq.end(), -A[i]);
        if (*Iter == INF) {
            cnt++;
        }
        *Iter = -A[i];
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1408
import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int s=input.scanInt();
        int w=input.scanInt();
        if(w>=s) {
            System.out.println("unsafe");
        }
        else {
            System.out.println("safe");
        }
    }
}


Measured memory_bytes: 32312
// https://atcoder.jp/contests/abc138/tasks/abc138_d
#include <bits/stdc++.h>
using namespace std;
using children = vector<int>;

void dfs(int i, int p, vector<children> &parents, vector<int64_t> &counter)
{

    for (int c : parents.at(i))
    {
        if (c != p)
        {
            counter[c] += counter[i];
            dfs(c, i, parents, counter);
        }
    }
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector<children> parents(n, children());
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        parents.at(a).push_back(b);
        parents.at(b).push_back(a);
    }
    vector<int64_t> counter(n, 0);
    for (int i = 0; i < q; i++)
    {
        int p, x;
        cin >> p >> x;
        counter.at(--p) += x;
    }
    dfs(0, 0, parents, counter);
    for (int64_t l : counter)
    {
        cout << l << " ";
    }
}

Measured memory_bytes: 31412
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll const INF = 1e18;


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

int n;
cin >> n;
vl a(n);
rep(i,n) cin >> a[i];

rep(i,n) {
    if(a[i] == 0) {
        cout << 0 << endl;
        return 0;
    }
}

ll ans = 1;
rep(i,n) {
    if(a[i]> (INF/ans)) {
        cout << -1 << endl;
        return 0;
    }
    ans *= a[i];
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 3952