akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
using namespace std;
long long INF = 1000000009;
map<int, int> mp;
int main()
{
	ios::sync_with_stdio(false);
	int h;
	cin >> h;
	int w;
	cin >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}

	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

ll a , b;

int main(){
    cin >> a >> b;
    if(a == b) {
        cout << 1 << endl;
    } else {
        per(i,0,60) if((a >> i & 1) != (b >> i & 1)){
            ll l = (a & ((1ll << i) - 1));
            ll r = (b & ((1ll << i) - 1));
            ll ans = (1ll << i) - l;
            int top=-1;
            rep(j,0,i) if(r >> j & 1) top = j;
            ll R = (1ll << (top + 1)) - 1;
            ll L = l;
            ans += (1ll << i) - max(0ll , L - R - 1);
            cout << ans << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

LL Factorial(LL n)
{
    if (n == 1) return 1;
    return (n * Factorial(n - 1)) % MOD;
}

int main()
{
    LL N, M;
    cin >> N >> M;
    if (abs(N - M) >= 2)
    {
        cout << 0 << endl;
        return 0;
    }
    LL dog = Factorial(N);
    LL monkey = Factorial(M);
    LL ans = (dog * monkey) % MOD;
    if (N == M)
    {
        ans = (ans * 2) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
open Printf
open Scanf

let id x = x

let solve n =
  let la = List.init n @@ fun _ -> scanf "%d " id in
  let rec loop ct l =
    match l with
      x::_::xs -> if x mod 2 = 1 then loop (ct + 1) xs else loop ct xs
    | [x] -> if x mod 2 = 1 then ct + 1 else ct
    | _ -> ct in
  loop 0 la

let () =
  scanf "%d " solve |> printf "%d\n"


Measured memory_bytes: 3840
N = int(input())
A = list(map(int, input().split()))
count = 0
tf =True
while tf:
    for i in range(0, len(A)):
        if A[i] % 2 ==1:
            tf = False
        A[i] = A[i]/2
    if not tf:
        break
    count += 1
print(count)


Measured memory_bytes: 3060
def f(n):
  if n == 3:
    ret = 100000
  elif n == 2:
    ret = 200000
  elif n == 1:
    ret = 300000
  else:
    ret = 0
  return ret

X, Y = map(int, input().split())
ans = f(X) + f(Y)
if X == 1 and Y == 1:
  ans += 400000

print(ans)

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

int main(void){
    int n,max = 0,cou = 0;
    string s,t,c;
    cin >> n >> s;
    for(int i = 0,num[26] = {};i < n;i++){
        t = s.substr(0,i+1);
        c = s.substr(i+1);
        for(int j = 0;j < t.size();j++){
            if(c.find(t[j]) != string::npos){
                num[t[j]-'a']++;
            }
        }
        for(int k = 0;k < 26;k++){
            if(num[k] > 0)++cou;
            num[k] = 0;
        }
        if(max < cou)max = cou;
        cou = 0;
    }
    cout << max;
}

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

int main()
{
  int n, a;
  cin >> n;
  array<int, 100003> dp;
  fill(dp.begin(), dp.end(), 0);
  REP(i, n) {
    cin >> a;
    ++dp[a];
    ++dp[a - 1];
    ++dp[a + 1];
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x,y;
	cin >> x>> y;

    cout << (x-1)/y+1 << endl;
}

Measured memory_bytes: 256
n=int(input())
ss=input()
dps=['a']*n
from collections import defaultdict
d=defaultdict(list)
for i in range(n):
    d[ss[i]].append(i)
    dps[i]=ss[i]
sorted(d.items())

Q=int(input())
import bisect
for i in range(Q):
    num,ii,c=input().split()
    #print(d)
    if num=='1':
        if c==dps[int(ii)-1]:
            continue
        bisect.insort_left(d[c],int(ii)-1)
        d[dps[int(ii)-1]].remove(int(ii)-1)
        dps[int(ii)-1]=c
    else:
        l,r=int(ii)-1,int(c)-1
        count=0
        for k,lst in d.items():
            idx=bisect.bisect_left(lst,l)
            idx1=bisect.bisect_right(lst,r)
            count+=((idx1-idx)>0)
            #print(lst,l,r,count)
        print(count)
        pass

Measured memory_bytes: 95688
#include <stdio.h>
int main(void){
    while(1){
        int t,n,start,finish,time=0,i;
        scanf("%d",&t);
        if(t==0)
        break;
        scanf("%d",&n);
        for(i=1;i<=n;i++){
        
            scanf("%d %d",&start,&finish);
        
            time+=(finish-start);
        
        
        }
        if(time>=t){
            printf("OK\n");
        
        }
        else{
            printf("%d\n",t-time);
        }
    }
    
    
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    cin.tie(0); cin.sync_with_stdio(false);
    int x, a;
    cin >> x >> a;
    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define rep(i,s,n) for(int i = s;i<n;i++)
#define long long ll
using namespace std;
struct Num{
    int ai;
    int aj;
    int de;
};
int main()
{
    int n;
    while(cin>>n){
       // vector<int> a;
        int a[n];
        rep(i,0,n){
           // a.push_back(n);
            cin>>a[i];
        }
        //sort(a.begin(),a.end());
        sort(a,a+n);
        int num =a[n-1];
        int t = num/2;
        //int no = lower_bound(a,a+n,t);
        int no = (lower_bound(a, a + n, t))-a;
        if(n==2) cout<<a[1]<<" "<<a[0]<<endl;
        else{
        int s = abs(a[no]-t);
        int s2 = abs(a[no-1]-t);
        int ab;
        int nn;
        if(s==s2){
            ab = s;
            nn =no;
        }else if(s>s2){
            ab = s2;
            nn = no-1;
        }else{
            ab =s;
            nn = no;
        }
         if(no+1<n){
            int s3 = abs(a[no+1]-t);
            if(ab>s3){
            ab = s3;
            nn = no+1;
            }
        }
        cout<<num<<" "<<a[nn]<<endl;
        }
    }
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a;
  string s;
  cin>>a>>s;
  if(a>=3200){
    cout<<s<<endl;
  }
  else{
    cout<<"red"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
long long a[maxn], b[maxn];
long long sum = 0;
int main()
{
	long long n;
	cin >> n;
	for(int i = 1; i <= n + 1; i++){
		scanf("%lld", a + i);
	}
	for(int i = 1; i < n + 1; i++){
		scanf("%lld", b + i);
	}
	for(int i = 1; i < n + 1; i++){
		for(int j = i; j <= i + 1; j++){
			int num = min(b[i], a[j]);
			sum += num;
			b[i] -= num;
			a[j] -= num;
		}
	}
	printf("%lld", sum);
	return 0;
}

Measured memory_bytes: 1792
S = input()
ans = 0
for i in range(len(S)):
  tmp = S[i]
  if(i == 0):
    tmp2 = tmp
  else:
    if(i % 2 == 0 and tmp2 != tmp):
      ans += 1
    elif(i % 2 != 0 and tmp2 == tmp):
      ans += 1
print(str(ans))

Measured memory_bytes: 3188
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let ab: Vec<(usize, usize)> = (0..m)
        .map(|_| {
            let a = input();
            let b = input();
            (a, b)
        })
        .collect();

    let mut v = vec![0; n];
    for (a, b) in ab {
        v[a - 1] += 1;
        v[b - 1] += 1;
    }

    for i in v {
        println!("{}", i);
    }
}


Measured memory_bytes: 4352
from scipy.sparse import*
n,m,s,*t=map(int,open(0).read().split())
row,col,dat=[],[],[]
for u,v,a,b in zip(*[iter(t[:m*4])]*4):
    for i in range(2501-a):
        row+=(i+a)*51+u,(i+a)*51+v
        col+=i*51+v,i*51+u
        dat+=b,b
for i,(c,d)in enumerate(zip(*[iter(t[m*4:])]*2),1):
    for j in range(2501-c):
        row+=j*51+i,
        col+=(j+c)*51+i,
        dat+=d,
d=csgraph.dijkstra(csr_matrix((dat,(row,col)),[8**6]*2),1,min(2500,s)*51+1)
for i in range(2,n+1):print(int(d[i::51].min()))

Measured memory_bytes: 123084
def foo(n, h)
	(0...n - 1).each { |i|
		gap = h[i] - h[i + 1]
		if gap > 1
			return "No"
		elsif gap == 1
			h[i + 1] += 1
		end
	}
	"Yes"
end

n = gets.chomp.to_i
h = gets.split.map(&:to_i)
puts foo(n, h)

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

#define ll long long 
const int N = 2e5 + 5;
const ll INF = 1e17;

int n, q, a, b, p[N];
ll lz[4 * N];

struct node{
	ll val, lef, rig;
} st[4 * N];
node merge(node x, node y){
	node res;
	res.val = min(x.val, y.val);
	res.lef = min(x.lef, y.lef);
	res.rig = min(x.rig, y.rig);
	return res;
}

void build(int id, int l, int r){
	if(l == r){
		if(l == b){
			st[id] = {0, -l, l};
		} else {
			st[id] = {INF, INF - l, INF + l};
		}
		return;
	}
	int mid = (l + r) >> 1;
	build(id << 1, l, mid);
	build(id << 1 | 1, mid + 1, r);
	st[id] = merge(st[id << 1], st[id << 1 | 1]);
}

void pushDown(int id, int l, int r){
	if(lz[id] != 0){
		st[id].val += lz[id];
		st[id].lef += lz[id];
		st[id].rig += lz[id];
		if(l < r){
			lz[id << 1] += lz[id];
			lz[id << 1 | 1] += lz[id];
		}
		lz[id] = 0;
	}
}

void update(int id, int l, int r, int i, int j, ll x){
	pushDown(id, l, r);
	if(l > j || r < i || i > j){
		return;
	}
	if(l >= i && r <= j){
		lz[id] += x;
		pushDown(id, l, r);
		return;
	}
	int mid = (l + r) >> 1;
	update(id << 1, l, mid, i, j, x);
	update(id << 1 | 1, mid + 1, r, i, j, x);
	st[id] = merge(st[id << 1], st[id << 1 | 1]);
}

node get(int id, int l, int r, int i, int j){
	pushDown(id, l, r);
	if(l > j || r < i || i > j){
		return {2 * INF, 2 * INF, 2 * INF};
	}
	if(l >= i && r <= j){
		return st[id];
	}
	int mid = (l + r) >> 1;
	return merge(get(id << 1, l, mid, i, j), get(id << 1 | 1, mid + 1, r, i, j));
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n >> q >> a >> b;
	for(int i = 1; i <= q; i++) cin >> p[i];
	
	build(1, 1, n);
	
	int pre = a;
	for(int i = 1; i <= q; i++){
		int cur = p[i];
		ll ans = INF;
		
		node res = get(1, 1, n, pre, pre);
		ans = min(ans, res.val + abs(cur - pre));
		node ans1 = get(1, 1, n, 1, cur);
		ans = min(ans, ans1.lef + cur);
		node ans2 = get(1, 1, n, cur + 1, n);
		ans = min(ans, ans2.rig - cur);
		
		update(1, 1, n, pre, pre, ans - res.val);
		update(1, 1, n, 1, pre - 1, abs(cur - pre));
		update(1, 1, n, pre + 1, n, abs(cur - pre));
		pre = p[i];
	}
	cout << st[1].val;
}

Measured memory_bytes: 21504
n = int(input())
dist = list(map(int, input().split() ))
mod = 998244353

if dist[0] != 0:
	print(0)
	exit()

dist2 = sorted(dist[1:])
dist2.append(-1)
idx = 0
ans = 1
before = 1

for now in range(1, n):
	count = 0
	if dist2[idx] == -1:
		break
	if dist2[idx] != now:
		print(0)
		exit()
	while dist2[idx] == now:
		idx += 1
		count += 1

	ans *= (before ** count)
	ans %= mod
	before = count

print(ans)


Measured memory_bytes: 13908
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const long double pi=acos(-1);
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
struct Node
{
	long double x,y,l;
	inline bool operator < (const Node &nt) const
	{
		return l>nt.l;
	}
}a[110];
signed main(void)
{
	reg long double ans=0.0;
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i].x>>a[i].y;
	for(long double i=0;i<2*pi;i+=0.0001)
	{
		long double sx=0.0,sy=0.0;
		for(int j=1;j<=n;++j)
			a[j].l=a[j].x*cos(i)+a[j].y*sin(i);
		sort(a+1,a+n+1);
		for(int j=1;j<=n;++j)
			if(a[j].l<0)
				break;
			else
				sx+=a[j].x,sy+=a[j].y;
		ans=max(ans,(long double)sqrt(sx*sx+sy*sy));
	}
	printf("%.12Lf\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main()
 {
    int n, m, x;
    cin >> n >> m >> x;
    long long int result = LLONG_MAX;
    Graph A(n, vector<int>(m));
    vector<int> C(n);
    for(int i = 0; i < n; i++) {
        cin >> C[i];
        for(int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }
    for(int bit = 0; bit < (1<<n); bit++) {
        vector<int> S;
        vector<int> level(m, 0);
        for(int i = 0; i < n; i++) {
            if(bit & (1 << i)) {
                S.push_back(i);
            }
        }
        long long int tmp = 0;
        for(int i : S) {
            tmp += C[i];
            for(int j = 0; j < m; j++) {
                level[j] += A[i][j];
            }
        }
        bool ok = true;
        for(int i = 0; i < m; i++) {
            if(level[i] < x) {
                ok = false;
            }
        }
        if(ok) {
            result = min(result, tmp);
        }
    }
    if(result == LLONG_MAX) {
        result = -1;
    }
    cout << result << endl;
    return 0;
}


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

int main() {
  long long H;
  cin >> H;
  long long count = 0;
  while (H != 1) {
    H /= 2;
    count++;
  }
  
  long long ans = 2;
  for (int i = 0; i < count; i++) 
    ans *= 2;
  
  cout << ans - 1 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cctype>
#include <stdio.h>
using namespace std;

int main(){
    int N,M;cin>>N;
    int T[N],sum=0;
    for (int i = 0;i < N;i++){
        int tmp = 0;
        cin >> tmp;
        T[i] = tmp;
        sum = sum + tmp;
    }
    cin >> M;
    int result[M];
    for (int i = 0;i<M;i++){
        int A,B;
        cin >> A >> B;
        result[i] = sum - T[A-1] + B;
    }

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

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

int main(void){
    // Your code here!
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    rep(i, k){
        if(a > 0){
            ++ans;
            --a;
            continue;
        }
        if(b > 0){
            --b;
            continue;
        }
        if(c > 0){
            --ans;
            --c;
            continue;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
# https://atcoder.jp/contests/abc179/tasks/abc179_b
t = int(input())
count = 1
result = 0
test = 0
p = ''
for i in range(t):
    a, b = map(int, input().split())
    
    if (a == b):
        result = 1
    else:
        result = 0
    
    if result == 1:
        test += 1
        if test >= 3:
            p = 'Yes'
    else:
        test = 0

if p == 'Yes':
    print('Yes')
else:
    print('No')
        



Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
    string str;
    int n;
    cin >> str >> n;
    string front = "";
    string back = "";
    bool flip = false;
    rep(i, n){
        int t;
        cin >> t;
        if(t == 1){
            flip = flip ? false : true;
        }else{
            int f;
            cin >> f;
            char c;
            cin >> c;
            if(!flip){
                if(f == 1){
                    front += c;
                }else{
                    back += c;
                }
            }else{
                if(f == 1){
                    back += c;
                }else{
                    front += c;   
                }
            }
        }
    }
    std::reverse(all(front));
    string res = front + str + back;
    if(flip) std::reverse(all(res));
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1348
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}


int main()
{
	int N,M;
	long long K;
	cin>>N>>M>>K;
	vector<long long> sumA(N+1);
	vector<long long> sumB(M+1);
	sumA[0]=0;
	for(int i=1; i<=N; i++)
	{
		long long _a;
		cin>>_a;
		sumA[i] = _a + sumA[i-1];
	}
	sumB[0]=0;
	for(int j=1; j<=M; j++)
	{
		long long _b;
		cin>>_b;
		sumB[j] = _b + sumB[j-1];
	}
	int result = 0;

	//Aの方ばっか読んだ時の最大数を出す
	int Amax = distance(sumA.begin(), upper_bound(sumA.begin(),sumA.end(), K));
	for(int i=0; i<Amax; i++)
	{
		int Acnt = i;
		int Bmax = K - sumA[i];
		int Bcnt = distance(sumB.begin(), upper_bound(sumB.begin(),sumB.end(), Bmax)) - 1;

		//cout<<"A:"<<Acnt+1<<", B:"<<Bcnt+1<<endl;

		result = max(Acnt+Bcnt,result);
	}
	cout<<result<<endl;
}

Measured memory_bytes: 6372
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H[] = new int[N];
		for (int i = 0; i < H.length; i++) {
			H[i] = sc.nextInt();
		}
		int max = H[0];
		int cnt = 0;

		for (int i = 0; i < N; i++) {
			if (H[i] >= max) {
				cnt++;
				max = H[i];
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 23892
def L(N):
    if N == 0:
        return 1
    return 3 + 2 * L(N-1)
def P(N):
    if N == 0:
        return 1
    return 1 + 2 * P(N-1)

def A(N,X):
    res = 0
    if N == 0:
        return 1
    if X == 1:
        return 0
    if 1 < X <= L(N-1) + 1:
        res = A(N-1,X-1)
    elif L(N-1) + 2 == X:
        res = 1 + P(N-1)
    elif L(N-1) + 2 < X <= 2 * L(N-1) + 2:
        res = 1 + P(N-1) + A(N-1,X-(2+L(N-1)))
    elif 2 * L(N-1) + 3 == X:
        res = 1 + 2 * P(N-1)
    return res

def main():
    N, X = map(int, input().split())
    print(A(N,X))


if __name__ == "__main__":
    main()

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

typedef struct{ 
double x,y;
}Point;

void kochcurve( int n , Point a , Point b ){
  if( n == 0 ){
    return; 
  }
  Point c,d,e;
  double th = M_PI * 60.0 / 180.0;

  c.x = ( 2.0 * a.x + 1.0 * b.x ) / 3.0;
  c.y = ( 2.0 * a.y + 1.0 * b.y ) / 3.0;
  d.x = ( 1.0 * a.x + 2.0 * b.x ) / 3.0;
  d.y = ( 1.0 * a.y + 2.0 * b.y ) / 3.0;
  e.x = ( d.x - c.x ) * cos( th ) - (d.y - c.y ) * sin( th ) + c.x;
  e.y = ( d.x - c.x ) * sin( th ) + (d.y - c.y ) * cos( th ) + c.y;

  kochcurve( n - 1 , a , c );
  printf("%.8f %.8f\n" , c.x , c.y );
  kochcurve( n - 1 , c , e );
  printf("%.8f %.8f\n" , e.x , e.y );
  kochcurve( n - 1 , e , d );
  printf("%.8f %.8f\n" , d.x , d.y );
  kochcurve( n - 1 , d , b );
}

int main ( void ){
  Point a,b;
  int n;
  scanf("%d" , &n );
  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;
  printf("%.8f %.8f\n" , a.x , a.y );
  kochcurve( n , a , b );
  printf("%.8f %.8f\n" , b.x , b.y );
 
  return 0;
}

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

using namespace std;

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

  map<char, int> m;

  for (int i = 0; i < S.size(); i++) {
    m[S[i]]++;
  }

  for (int i = 0; i < 26; i++) {
    if (m.count((char) ('a' + i)) == 0) {
      cout << (char) ('a' + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}

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

int main(){
  string s;
  long long int K;
  cin >> s;
  cin >> K;
  if(s.at(0)!='1'){
    cout << s.at(0) << endl;
    return 0;
  }else{
    for(int i=1;i<K;i++){
      if(s.at(i)!='1'){
        cout << s.at(i) << endl;
        return 0;
      }
    }
  }
  cout << 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int n, a, b, c, cnt;
int main() {
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> c;
		if (a <= c && c < b)cnt++;
	}
	cout << n - cnt << endl;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int h,w;cin>>h>>w;
    string s[2*h];
    rep(i,h){cin>>s[2*i];s[2*i+1]=s[2*i];}
    rep(i,2*h){
        co(s[i]);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

void cp()
{
	int x;
	cin>>x;
	if(x>=30)
		cout<<"Yes";
	else
		cout<<"No";
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(){

  int stone,m[50],sf,flag;
  int n,p;
  int i,j;

  while(1){
    for(i=0;i<50;i++){
      m[i]=0;
    }
    flag=0;
    scanf("%d %d",&n,&p);
    if(n==0 && p==0)break;
    stone=p;
    while(1){
      if(flag==1)break;
    for(i=0;i<n;i++){
      if(stone!=0){
	stone--;
	m[i]++;
	if(m[i]==p){
	  sf=i;
	  flag=1;
	  break;
	}
      }else{
	stone+=m[i];
	m[i]=0;
      }
    }
    }
    printf("%d\n",sf);
    }
  return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

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

  int r;
  cin >> r;

  cout << r * r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <vector>
using namespace std;

int main()
{
    int s;
    cin >> s;
    int front = floor(s/100);
    int back = s - front*100;
    if(front>12||front==0){
       if(back<=12&&back!=0){
            cout << "YYMM";
            return 0;
        }else{
            cout << "NA";
            return 0;
        }
    }
    int tmp;
    tmp = front;
    front = back;
    back = tmp;

    if(front>12||front==0){
        if(back<=12&&back!=0){
            cout << "MMYY";
            return 0;
        }else{
            cout << "NA";
            return 0;
        }
    }

    if(front<=12&&front!=0&&back<=12&&back!=0)
        cout << "AMBIGUOUS";
        return 0;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
al = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
k = -1
sum = []
for i in range(13):
  k += 26**i
  sum.append(k)
j = 0
while sum[j]<N:
  j += 1

N += -sum[j-1]-1
ans = ""
for m in range(j):
  z = N//(26**(j-m-1))
  N += -26**(j-m-1)*z
  ans+=al[z]
print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
   string s;
   ll k;
   cin >> s >> k;
   if(s[0]=='1'){
       if(k==1)
           cout << s[0] << endl;
        else{
            if(k<=100){
                bool flag = true;
                rep(i, k){
                    if(s[i]!='1'){
                        flag = false;
                        cout << s[i] << endl;
                        break;
                    }
                }
                if(flag)
                    cout << s[0] << endl;
            } else {
                bool flag = true;
                rep(i, 100) {
                    if(s[i]!='1'){
                        flag = false;
                        cout << s[i] << endl;
                        break;
                    }
                }
                if(flag)
                    cout << s[0] << endl;
            }
        }

   }else{
       cout<< s[0] << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define N 1010000
#define maxn 1000000000
using namespace std;
int tt;
int f[N],n,p,q;
int a[N];
int main()
{
    int n,A,B;
    scanf("%d%d%d",&n,&A,&B);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    //sort(a+1,a+n+1);
    long long l=0,r=1e9;
    while(r-l>1)
    {
        long long cnt=0,mid=(l+r)/2,tmp;
        for(int i=1;i<=n;i++)
        {
            tmp=(long long)a[i]-mid*B;
            if(tmp>0)cnt+=(tmp-1+A-B)/(A-B);
            if(cnt>mid)break;
        }
        if(cnt>mid)l=mid;
        else r=mid;
    }
    cout<<r<<endl;
}
//a0,a1,a2,a3,a4,a5,a6
//f(a-b)
//(a-b)^(c-b)
/*
 1 2 3 4 5 0 P (p+1,p+q)  p                q
0 1 2 3 4 5 6 1 1 1 1 1 0 0 0 0 0 0 1  1 1 1 1
1 2 3 4 5 6 7 8
...
3 0
1 2
4 5
 */

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.isEmpty()) {
                break;
            }
            String[] values = line.split(" ");
            double xa = Double.parseDouble(values[0]);
            double ya = Double.parseDouble(values[1]);
            double xb = Double.parseDouble(values[2]);
            double yb = Double.parseDouble(values[3]);
            double xc = Double.parseDouble(values[4]);
            double yc = Double.parseDouble(values[5]);
            double xd = Double.parseDouble(values[6]);
            double yd = Double.parseDouble(values[7]);
            double ip = (xb - xa) * (xd - xc) + (yb - ya) * (yd - yc);
            String result = ip == 0.0 ? "YES" : "NO";
            out.println(result);
        }
    }
}

Measured memory_bytes: 9912
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    
    static final int MOD = 1000000007;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
            Map<Integer, Integer> map2 = primeFactorization(a[i]);
            for (Integer j : map2.keySet()) {
                map.put(j, Math.max(map.getOrDefault(j, 0), map2.get(j)));
            }
        }
        
        long x = 1;
        for (Integer i : map.keySet()) {
            int j = map.get(i);
            for(int k = 0; k < j; k++){
                x *= i;
                x %= MOD;
            }
        }
        
        long ans = 0;
        for(int i = 0; i < n; i++){
            ans += x * modinv(a[i], MOD);
            ans %= MOD;
        }
        
        System.out.println(ans);
    }
    
    static long modpow(long a, long n, long mod){
        
        long res = 1;
        while(n > 0){
            if((n & 1) == 1) res = res * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }
    
    static long modinv(long a, long mod){
        return modpow(a, mod - 2, mod);
    }
    
    static Map<Integer, Integer> primeFactorization(int n){
        
        Map<Integer, Integer> map = new HashMap<>();
        while(n%2 == 0){
            n /= 2;
            map.put(2, map.getOrDefault(2, 0) +1);
        }
        double sqrt = Math.sqrt(n);
        for(int i = 3; i <= sqrt; i += 2){
            while(n%i == 0){
                n /= i;
                map.put(i, map.getOrDefault(i, 0) +1);
            }
        }
        if(n > 1){
            map.put(n, map.getOrDefault(n, 0) +1);
        }
        return map;
    }
}

Measured memory_bytes: 32596
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n : usize = read();
    let mut a :Vec<usize> = read_vec();
    let mut res = 0;
    let mut b :Vec<usize> = read_vec();
    for i in 0..n {
        if b[i] > a[i] {
            b[i] -= a[i];
            res += a[i];
            a[i] = 0;
            if b[i] > a[i+1] {
                res += a[i+1];
                a[i+1] = 0;
            } else {
                res += b[i];
                a[i+1] -= b[i];
            }
        } else {
            res += b[i];
            a[i] -= b[i];
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 10492
while True:
    n, r = map(int, raw_input().split())
    if n == 0 and r == 0: break

    x = range(1, n+1)[::-1]
    for _ in range(r):
        p, c = map(int, raw_input().split())
        a = p-1
        b = p+c-1
        y = x[a:b] + x[:a] + x[b:]
        x = y[:]
        #print x
    print x[0]


Measured memory_bytes: 4224
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val x = sc.nextLong
    val a = new Array[Long](n)
    for (i <- 0 until n) {
      a(i) = sc.nextLong
    }

    val abss = a.map(v => (v - x).abs).sorted
    var divisor = abss.min
    for (i <- 1 until n) {
      if (abss(i) % divisor != 0) {
        divisor = gcd(abss(i), divisor)
      }
    }
    println(divisor)
  }

  def gcd(x: Long, y: Long): Long = {
    if (x == 0) y
    else gcd(y % x, x)
  }

}


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

signed main() {
	int a, b;
	char op;

	while (cin >> a >> op >> b and op != '?') {
		if (op == '+') cout << a + b;
		if (op == '-') cout << a - b;
		if (op == '*') cout << a * b;
		if (op == '/') cout << a / b;
		cout << endl;
	}
}



Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int[] x = new int[5];
		int[] y = new int[5];

		int total=0;
		int miny=10;
		for (int i=0;i<5;i++) {
			x[i] = sc.nextInt();
			y[i] = x[i]%10;
			total += x[i] - y[i];
			if(y[i]>0) {
				if(y[i]<miny) {
					miny = y[i];
				}
				y[i] = 10;
			}
		}

		for (int i=0;i<5;i++) {
			total += y[i];
		}

		System.out.println(miny==10 ? total : total+miny-10);

	}
}

Measured memory_bytes: 22868
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n;
ll a[100000];
ll s[100001];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) cin >> a[i];
	s[0] = 0;
	REP(i, n) s[i + 1] = s[i] + a[i];
	ll res1 = 0, res2 = 0;
	ll d = 0;
	REP(i, n) {
		if (i % 2 == 0) {
			if (s[i + 1] + d > 0) continue;
			ll temp = 1 - s[i + 1] - d;
			res1 += temp;
			d += temp;
		}
		else {
			if (s[i + 1] + d < 0) continue;
			ll temp = s[i + 1] + d + 1;
			res1 += temp;
			d -= temp;
		}
	}
	d = 0;
	REP(i, n) {
		if (i % 2 == 0) {
			if (s[i + 1] + d < 0) continue;
			ll temp = s[i + 1] + d + 1;
			res2 += temp;
			d -= temp;
		}
		else {
			if (s[i + 1] + d > 0) continue;
			ll temp = 1 - s[i + 1] - d;
			res2 += temp;
			d += temp;
		}
	}
	cout << min(res1, res2) << endl;
	return 0;
}


Measured memory_bytes: 1792
S=input()
mod=10**9 + 7
dp=[[0,0,0] for i in range(len(S))]
dp[0][0]=2
dp[0][2]=1

for i in range(1,len(S)):
   if S[i]=="1":
      dp[i][0]+=dp[i-1][0]* 2 % mod  
      dp[i][2]+=dp[i-1][0]* 1 % mod 
   else:
      dp[i][0]+=dp[i-1][0]* 1 % mod 
   dp[i][1]+=(dp[i-1][1]+dp[i-1][2]) * 2 % mod
   dp[i][2]+=(dp[i-1][1]+dp[i-1][2]) * 1 % mod                 
   dp[i][0]%=mod             
   dp[i][1]%=mod
   dp[i][2]%=mod
value=(dp[-1][0]+dp[-1][1]+dp[-1][2])%mod
print(value)
            
                 
   

Measured memory_bytes: 22868
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(double);
		void decrement(void);
		void decrement(double);
		double getResult(void);
	private:
		double result;
	};
	void Ans::showResult(void) {
		printf("%.0lf\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(double value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(double value) {
		this->result -= value;
	}
	double AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void input(Str* str) {
		str->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				str->push_back(row);
				row = "";
			} else {
				row += buf[i];
			}
		}
		str->push_back(row);
	}
	void input(Num* num) {
		num->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				num->push_back(std::atoi(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		num->push_back(std::atoi(row.c_str()));
	}
	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::Num s;
	AtCoder::input(&s);
	const int n = s[0];

	AtCoder::input(&s);

	AtCoder::Ans* ans = new AtCoder::Ans();

	const int nbuf = n - 1;
	for (int i = 0; i < nbuf; i++) {
		for (int j = (i + 1); j < n; j++) {
			const int ansbuf = s[i] * s[j];
			ans->increment(ansbuf);
		}
	}

	ans->showResult();

	delete(ans);

	return 0;
}


Measured memory_bytes: 256
// 
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static String file = "../in";

    static int test = 10;  // 0 for local testing, 1 for std input

    public static void main(String[] args) throws Exception
    {
        int _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}
        
        /****************************************************/
        /****************************************************/
        /****************************************************/
        /****************************************************/
    
        new Main().b();
    }

    void b() throws Exception
    {
        in.readLine();
        char[] chs = in.readLine().toCharArray();
        int n = chs.length;
        int re = 0;
        for(int i = 0; i < n - 2; i++)
        {
            if(chs[i] == 'A' && chs[i + 1] == 'B' && chs[i + 2] == 'C')
                re++;
        }
        System.out.println(re);
    }

    void a() throws Exception
    {
        String[] sp = in.readLine().split(" ");
        int a = Integer.valueOf(sp[0]);
        int b = Integer.valueOf(sp[1]);
        if(a * 500 >= b) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,x,y;
    cin>>n>>k;
    if(k==1){
        cout<<"0";
    }
    else{
        x=n%k;
        y=abs(x-k);
        if(x<y){
            cout<<x;
        }
        else{
            cout<<y;
        }
    }

}


Measured memory_bytes: 256
<?php
list($N)=sscanf(trim(fgets(STDIN)),"%d");
$S = array();
for ($i=0; $i < $N; $i++) { 
    list($W)=sscanf(trim(fgets(STDIN)),"%s");
    if(!isset($S[$W])){
        $S[$W] = 1;
    }else{
        $S[$W]++;
    }
}
print(count($S));

Measured memory_bytes: 31972
{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> Int -> VU.Vector Int32 -> Int32
solve !n !k !an = VU.last dp
 where
  dp :: VU.Vector Int32
  dp = VU.foldl'
    (\(!dpi) (!i) -> VU.scanl'
      (\(!dpij) (!j) ->
        let !p = if j - fromIntegral (an VU.! i) - 1 >= 0
              then dpi VU.! (j - fromIntegral (an VU.! i) - 1)
              else 0
            !q = dpi VU.! j
            !a = dpij + q - p
        in  a `mod` (10 ^ 9 + 7)
      )
      1
      (VU.generate k (+ 1))
    )
    (VU.generate (k + 1) (\i -> if i == 0 then 1 else 0))
    (VU.generate n id)

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, k) <-
    (\(!vec) -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  an <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n k an


Measured memory_bytes: 6364
using System;

class ITP1_1_D
{
  static void Main()
  {
    int t = int.Parse(Console.ReadLine());
    int h = t / 3600;
    int m = t % 3600 / 60;
    int s = t % 3600 % 60;
    Console.WriteLine("{0}:{1}:{2}", h, m, s);
  }
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());

    int p = 0, ans = 0;
    while(p < n){
        int x = v.at(p);
        int cnt = 0;
        while(p < n && v.at(p) == x){
            p++;
            cnt++;
        }
        if(cnt < x){
            ans += cnt;
        }else if(cnt > x){
            ans += cnt - x;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll C;
ll X[101010],V[101010];
ll ret;

template<class V,int NV> class SegTree_1 {
public:
	vector<V> val;
	static V const def=0;
	V comp(V l,V r){ return max(l,r);};
	
	SegTree_1(){val=vector<V>(NV*2,def);};
	V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i<y
		if(r<=x || y<=l) return def;
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=v;
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};

SegTree_1<ll,1<<20> st,st2;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>C;
	FOR(i,N) cin>>X[i+1]>>V[i+1];
	
	
	// R->L
	ll sum=0;
	for(i=1;i<=N;i++) {
		sum+=V[i];
		st.update(i,sum-2*X[i]);
	}
	sum=0;
	for(i=N;i>=1;i--) {
		sum+=V[i];
		ret=max(ret,sum-(C-X[i])+st.getval(0,i));
	}
	
	// L->R
	sum=0;
	for(i=N;i>=1;i--) {
		sum+=V[i];
		st2.update(i,sum-2*(C-X[i]));
	}
	sum=0;
	for(i=1;i<=N;i++) {
		sum+=V[i];
		ret=max(ret,sum-X[i]+st2.getval(i+1,N+1));
	}
	
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main(){
  int N;cin >>N;
  int res=1000000000;
  for (int i=1;i<N;++i){
    int k=0;
    int a=i;
    int b=N-i;
    while(a>0){
      k += a%10;
      a /=10;
    }
    while(b>0){
      k += b%10;
      b /= 10;
    }
    res = min(k,res);
  }
  cout << res << endl;
}

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

#define N 205
#define M 20005

int n, m, e;

int ans = 0;

bitset<N> vis;

array<int, N> mac;

array<vector<int>, N> to;

bool dfs(int u)
{
	if (u == -1)
		return true;
		
	for (auto v : to[u])
		if (!vis[v])
		{
			vis.set(v);
			if (dfs(mac[v]))
			{
				mac[v] = u;
				return true;
			}
		}
		
	return false;
}

signed main(void)
{
	cin >> n >> m >> e;
	
	for (int x, y; e--; )
	{
		cin >> x >> y;
		to[x].push_back(y + n);
		to[y + n].push_back(x);
	}
	
	memset(begin(mac), -1, sizeof(mac));
	
	for (int i = 0; i < n; ++i)
	{
		vis.reset();
		ans += dfs(i);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3268
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

int n;
int m;
string s;

int main(){
	while(1){
		scanf("%d", &n);
		if(n == 0) break;
		char t[1000001];
		scanf("%d", &m);
		scanf("%s", t);

		s = t;
		vector<int> v;
		for(int i=0; i<s.size()-2;){
			if(s[i] ==  'I' && s[i+1] == 'O' && s[i+2] == 'I'){
				v.push_back(1);
				i += 3;
				while(1){
					if(i >= s.size()) break;
					if(s[i] == 'O' && s[i+1] == 'I'){
						v[v.size() - 1]++;
						i+=2;
					}else{
						break;
					}
				}
			}else{
				i++;
			}
		}
/*		for(int i=0; i<v.size(); i++)
			printf("%d\t", v[i]);
		printf("\n");
*/		int ans = 0;
		for(int i=0; i<v.size(); i++){
			if(v[i] >= n){
				ans += v[i] - n + 1;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll lcm(ll a,ll b){
  return (a/__gcd(a,b))*b;
}

struct segtree{
  ll dat[(1<<19)-1];
  ll size;

  void init(ll n_){
    size=1;
    while(size<n_) size*=2;
    for(int i=0;i<2*size-1;i++)dat[i]=1;
  }

  void update(ll k,ll a){
    k+=size-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=lcm(dat[k*2+1],dat[k*2+2]);
    }
  }

  ll subquery(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l)return 1;
    if(a<=l&&r<=b)return dat[k];
    else{
      return lcm(subquery(a,b,k*2+1,l,(l+r)/2),subquery(a,b,k*2+2,(l+r)/2,r));
    }
  }
  
  ll query(ll a,ll b){
    return subquery(a,b,0,0,size);
  }
};

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

ll n,q;
ll sum[211111];
ll p[211111];
segtree sgt;

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>q;
  rep(i,n){
    cin>>p[i];
    p[i]--;
  }
  sgt.init(n);
  rep(i,n){
    ll cnt=1,crt=p[i];
    ll s=p[i]+1;
    while(crt!=i){
      crt=p[crt];
      cnt++;
      s+=crt+1;
    }
    sgt.update(i,cnt);
    cnt%=mod;
    s%=mod;
    sum[i+1]=s*mod_pow(cnt,mod-2)%mod;
  }
  rep(i,n){
    sum[i+1]=(sum[i+1]+sum[i])%mod;
  }
  rep(hoge,q){
    ll l,r;
    cin>>l>>r;
    l--;
    ll lc=sgt.query(l,r)%mod;
    cout<<(((sum[r]-sum[l]+mod)%mod)*lc)%mod<<endl;
  }
	return 0;
}

Measured memory_bytes: 6868