akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define rep(i, a, b) for(int i = a; i < b; i++)

const double EPS = 1e-10;

double add(double a, double b){
    if( abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
    return a + b;
}

// 二次元ベクトル構造体
struct P{
    double x, y;
    P(){}
    P(double x, double y) : x(x), y(y){
    }
    P operator + (P p){
        return P(add(x, p.x), add(y, p.y));
    }
    P operator - (P p){
        return P(add(x, -p.x), add(y, -p.y));
    }
    P operator * (double d){
        return P(x * d, y * d);
    }
    P operator / (double d){
        return P(x / d, y / d);
    }
    double dot(P p){ // 内積
        return add(x * p.x, y * p.y);
    }
    double det(P p){ // 外積
        return add(x * p.y, -y * p.x);
    }
};
vector<P> p;

// 2点間の長さ
double dist(P a, P b){
    return sqrt((b-a).dot(b-a));
}
double dist2(P a, P b){
    return (b-a).dot(b-a);
}

//　線分p1-p2上に点qがあるか判定
bool on_seg(P p1, P p2, P q){
    return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}

// 直線p1-p2と直線q1-q2の交点
P intersection(P p1, P p2, P q1, P q2){
    return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1));
}

double calc_r(P tmp){
    double r = 0;
    for(auto to: p) r = max(r, dist(tmp, to));
    return r;
}

double calc_y(double x){
    double low_y = 0;
    double high_y = 1000;
    int cnt = 500;
    while(cnt--){
        double c1 = (low_y * 2 + high_y) / 3.0;
        double c2 = (low_y + high_y * 2) / 3.0;
        if(calc_r(P(x, c1)) < calc_r(P(x, c2))) high_y = c2;
        else low_y = c1;
    }
    return low_y;
}

int main(){
    int N; cin >> N;
    
    p.resize(N);
    rep(i, 0, N) cin >> p[i].x >> p[i].y;

    double low_x = 0, high_x = 1000;
    int cnt = 500;
    while(cnt--){
        double c1 = (low_x * 2 + high_x) / 3.0;
        double c2 = (low_x + high_x * 2) / 3.0;
        if(calc_r(P(c1, calc_y(c1))) < calc_r(P(c2, calc_y(c2)))) high_x = c2;
        else low_x = c1;
    }

    cout << fixed << setprecision(10) << calc_r(P(low_x, calc_y(low_x))) << endl;

}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc098/tasks/abc098_a
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int, M: int, a: "List[int]"):
    p = [0] * (N+1)
    p[0] = 1

    for m in range(M-1):
        if a[m] + 1 == a[m + 1]:
            print(0)
            return

    a += [999999, 1999999]
    watch = 0
    if a[watch] == 1:
        watch += 1
        p[1] = 0
    else:
        p[1] = 1
    for n in range(2, N+1):
        if a[watch] == n:
            p[n] = 0
        elif a[watch] == n - 1:
            p[n] = p[n-2]
        elif a[watch] == n - 2:
            if a[watch+1] != n:
                p[n] = p[n-1]
            else:
                p[n] = 0
            watch += 1
        else:
            p[n] = p[n-1] + p[n-2]
    print(p[N] % MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()


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

A = list(map(int,input().split()))

dic = {}

for a in A:

    if a not in dic:
        dic[a] = 1
    else:
        dic[a] += 1

B = []
for i in dic:
    B.append(dic[i])

B.sort()

B_sub = B.copy()

for i in range(len(B)-1):
    B_sub[i+1] += B_sub[i] 

aind = N + 1
nind = len(B) - 1

#print (B,B_sub)

for i in range(N):

    i += 1

    while True:

        while nind > 0 and B[nind] > aind - 1:

          nind -= 1

        if i > len(B):
            print (0)
            break

        elif ((len(B) - 1) - nind ) * (aind-1) + B_sub[nind] >= (aind - 1) * i:
            print (aind - 1)
            break

        aind -= 1

        

Measured memory_bytes: 41860
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int n, m, q;
ll l, g[305][305], h[305][305];

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

    rep(i, n) rep(j, n) {
        if (i == j) g[i][j] = 0, h[i][j] = 0;
        else g[i][j] = LLINF, h[i][j] = LLINF;
    }
    rep(i, m) {
        int a, b; ll c;
        cin >> a >> b >> c;
        a--; b--;
        g[a][b] = g[b][a] = c;
    }

    // Warshall-Floyd
    rep(k, n) rep(i, n) rep(j, n) {
        chmin(g[i][j], g[i][k] + g[k][j]);
    }

    rep(i, n) rep(j, n) {
        if (i >= j || g[i][j] > l) continue;
        h[i][j] = h[j][i] = 1;
    }
    rep(k, n) rep(i, n) rep(j, n) {
        chmin(h[i][j], h[i][k] + h[k][j]);
    }

    cin >> q;
    rep(i, q) {
        int s, t; cin >> s >> t;
        s--; t--;
        if (h[s][t] == LLINF) cout << -1 << endl;
        else cout << h[s][t] - 1 << endl;
    }
}


Measured memory_bytes: 1920
//Md. Shajibul Islam..
//East West University, CSE Department'19

#include<bits/stdc++.h>
using namespace std;
#define FAST             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define loop(i,n)        for(int i=0;i<n;i++)
#define CASE_PRINT       cout<<"Case "<<C<<": "
#define CASE_PRINT2      cout<<"Case "<<C<<":"<<endl
#define ll               long long
#define ld               long double
#define Pi               2*acos(0.0) // acos(-1.0)

int main()
{
    FAST;
    ll n;cin>>n;
    int ans = n-1;
    for(int i=2;i<n;i++)
    {
        ans = ans + (n/i);
        if(n%i==0)ans--;
    }

    cout<<ans<<endl;
}






Measured memory_bytes: 3648
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations
import numpy as np
def run():
    k,q = map(int, sysread().split())
    d = list(map(int,sysread().split()))
    d = np.array(d, dtype=np.uint64)

    def check(n ,x, m):
        _d = d % m
        d0 = d % m == 0
        # n_step
        n_d = (n-1) // k
        n_rest = (n-1) % k
        x %= m
        _d_rest, d0_rest = 0, 0
        if n_rest != 0:
            _d_rest = _d[:n_rest].sum()
            d0_rest = d0[:n_rest].sum()

        a_last = x + n_d * _d.sum() + _d_rest
        n_step = a_last // m
        # n_same
        n_same = n_d * d0.sum() + d0_rest

        return n-1 - n_same - n_step


    for _ in range(q):
        n,x,m = map(int, sysread().split())
        print(int(check(n, x, m)))

if __name__ == "__main__":
    run()

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


using namespace std;

int main() {
	int k, x;
	scanf("%d %d", &k, &x);
	for (int i = x - k + 1; i <= x + k - 1; ++i) {
		printf("%d ", i);
	}
	return 0; 
}

 


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int n; cin >> n;

	vector <int> a(n);

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

	map <int, int> cnt;

	int total = 0;

	for(int i = 0; i < n; i++){
		total += cnt[a[i]]++;
	}


	for(int i = 0; i < n; i++){
		cout << total - cnt[a[i]] + 1 << endl;
	}



	
	
	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
 
using namespace std;

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    double area = w * h / 2.0;

    cout << area;
    if(w / 2 == x && h / 2 == y) {
        cout << " 1" << endl;
    } else {
        cout << " 0" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int n;
long long L;
long long kum[200009];
long long ans=0;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>L>>n;
    for(int i=1; i<=n; i++)
    {
        long long szam;
        cin>>szam;
        v.push_back(szam);
        kum[i]=kum[i-1]+szam;
    }
    if(n==1)
    {
        cout<<max(v[0], L-v[0])<<endl;
        return 0;
    }
    ans=max(ans, v[n-1]);
    long long mennyi=v[n-1]-v[n-2];
    ans=max(ans, v[n-2]+L-mennyi);
    for(int eddig=n-3; eddig>=0; eddig--)
    {
        int kezdo=eddig;
        int veg=n-2;
        if((veg-kezdo+1)%2==0)
        {
            mennyi+=(v[eddig+1]-v[eddig]);
            mennyi+=(2*v[(kezdo+veg)/2+1]);
            mennyi-=(2*v[eddig+1]);
            mennyi+=v[(kezdo+veg)/2+2];
            mennyi-=v[(kezdo+veg)/2+1];
        }
        else
        {
            mennyi+=(v[eddig+1]-v[eddig]);
            mennyi+=(2*v[(kezdo+veg)/2+1]);
            mennyi-=(2*v[eddig+1]);
        }
        int korok=n-1-eddig;
        ans=max(ans, v[eddig]+L*korok-mennyi);
    }


    //cout<<"*"<<ans<<endl;

    for(int i=1; i<=n; i++)
    {
        v[i-1]=L-v[i-1];
    }
    reverse(v.begin(), v.end());
    if(n==1)
    {
        cout<<max(v[0], L-v[0])<<endl;
        return 0;
    }
    ans=max(ans, v[n-1]);
    mennyi=v[n-1]-v[n-2];
    ans=max(ans, v[n-2]+L-mennyi);
    for(int eddig=n-3; eddig>=0; eddig--)
    {
        int kezdo=eddig;
        int veg=n-2;
        if((veg-kezdo+1)%2==0)
        {
            mennyi+=(v[eddig+1]-v[eddig]);
            mennyi+=(2*v[(kezdo+veg)/2+1]);
            mennyi-=(2*v[eddig+1]);
            mennyi+=v[(kezdo+veg)/2+2];
            mennyi-=v[(kezdo+veg)/2+1];
        }
        else
        {
            mennyi+=(v[eddig+1]-v[eddig]);
            mennyi+=(2*v[(kezdo+veg)/2+1]);
            mennyi-=(2*v[eddig+1]);
        }
        int korok=n-1-eddig;
        ans=max(ans, v[eddig]+L*korok-mennyi);
    }

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


Measured memory_bytes: 3568
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int N=100100;
const ll INF=1e18;
int n,m,u,v,o[N],p[N],fa[N],fd[N];
ll ans,a[N],b[N],f[N],sz[N];
vector<int>ad[N];
void add(int u,int v){ad[u].push_back(v);}
int fi(int x){return x==fd[x]?x:fd[x]=fi(fd[x]);}
bool cmp(int x,int y){return a[x]<a[y];}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d",&n,&m);
	FOR(i,1,n) scanf("%lld%lld",&a[i],&b[i]),a[i]-=b[i],o[i]=i;
	FOR(i,1,m) scanf("%d%d",&u,&v),add(u,v),add(v,u);
	sort(o+1,o+n+1,cmp);
	FOR(i,1,n) p[o[i]]=i,fd[i]=i;
	FOR(i,1,n){
		u=o[i];sz[u]=b[u];
		for(int x:ad[u])if(p[v=fi(x)]<i)
			fa[v]=fd[v]=u,sz[u]+=sz[v];
	}
	ans=INF;
	ROF(i,n,1){
		u=o[i];
		f[u]=max(f[fa[u]],a[fa[u]]-sz[u]);
		ans=min(ans,max(a[u],f[u]));
	}
	cout<<ans+sz[o[n]]<<'\n';
}

Measured memory_bytes: 10620
N=int(input())
*A,=map(int,input().split())
import collections

c = collections.Counter(A)

ans=0
for k,v in c.items():
    if k == v: continue
    if k < v: # kに対して要素数が多いので取り除く
        ans+=v-k
    if v < k: # kに対して要素数が少ないので、すべて取り除く
        ans+=v
print(ans)

Measured memory_bytes: 21688
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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;}

int main() {
  int n;
  cin >> n;
  cout << "ABC" << n << endl;


  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner; // ?????¨?????????????????????

public class Main {
    public static void main(String[] args) {
        // ?????????????????\?????????????????¨?????? sc ??????????????? (???????????????????????????????????????????????°???????????????).
        Scanner sc = new Scanner(System.in);

        // ????????? sc ??? int ?????¨?????? 1 ?????\???????????????.
        int a = sc.nextInt();
        int b = sc.nextInt();

        // ??????????????¨???
        if (a < b) { System.out.println("a < b"); }
        if (a > b) { System.out.println("a > b"); }
        if (a == b) { System.out.println("a == b"); }
    }
}

Measured memory_bytes: 26220
import sys
readline = sys.stdin.readline

MOD = 10**9+7
N = int(readline())
A = list(map(int, readline().split()))
SA = [0]*N
SA[0] = A[0]
for i in range(1, N):
    SA[i] = SA[i-1]^A[i]
table = [int(sa == 0) for sa in SA]
for i in range(1, N):
    table[i] += table[i-1]

table.append(0)
cnt = 0
pre = [-1]*(1<<20)
dp0 = [1]*(1<<20)
dp = [0]*(1<<20)
for i in range(N):
    a = SA[i]    
    if a:
        y = table[i]-table[pre[a]]
        pre[a] = i
        dp[a], dp0[a] = dp0[a] + (1+y)*dp[a], dp0[a] + y*dp[a]
        dp[a] %= MOD
        dp0[a] %= MOD
    else:
        cnt += 1

if SA[-1]:
    ans = dp0[SA[-1]]
else:
    ans = pow(2, cnt-1, MOD)
    for t in dp:
        ans = (ans+t)%MOD
print(ans)

Measured memory_bytes: 125440
import java.util.Scanner;
import java.util.Arrays;
 
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[] x = new int[3];
for (int i = 0; i < n; i++) {
x[0] = scn.nextInt();
x[1] = scn.nextInt();
x[2] = scn.nextInt();
Arrays.sort(x);
if (x[0] * x[0] + x[1] * x[1] == x[2] * x[2]) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}

Measured memory_bytes: 23396
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e5+5;
vector<int>v[MAXN];
int dp[MAXN];
int max(int a,int b){
    return a>b?a:b;
}
int dfs(int x){
    if(dp[x])return dp[x];
    int maxx=0;
    for(int i=0;i<v[x].size();++i){
        maxx=max(maxx,dfs(v[x][i]));
    }
    dp[x]=maxx+1;
    return dp[x];
}
int main(){
    int N,M;
    scanf("%d%d",&N,&M);
    for(int i=0;i<M;++i){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
    }
    int maxx=0;
    for(int i=0;i<N;++i){
        maxx=max(maxx,dfs(i+1));
    }
    --maxx;
    cout<<maxx<<endl;
    return 0;
}

Measured memory_bytes: 8192
#include <cstdio>           // printf(), scanf()
#include <vector>
#include <algorithm>        // sort(), reverse()

using namespace std;
static const double EPS = 1e-10;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

class Point
{
public:
	double x, y;

	Point(int x = 0, int y = 0): x(x), y(y) {}
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }

	bool operator < (const Point &p) const {
		return y != p.y ? y < p.y : x < p.x;
	}
};

typedef Point Vector;
typedef vector<Point> Polygon;

double
norm(Vector a)
{
	return a.x * a.x + a.y * a.y;
}

double
dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}

double
cross(Vector a, Vector b)
{
	return a.x * b.y - a.y * b.x;
}

int
ccw(Point p0, Point p1, Point p2)
{
	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if (cross(a, b) > EPS)
		return COUNTER_CLOCKWISE;

	if (cross(a, b) < -EPS)
		return CLOCKWISE;

	if (dot(a, b) < -EPS)
		return ONLINE_BACK;

	if (norm(a) < norm(b))
		return ONLINE_FRONT;

	return ON_SEGMENT;
}

Polygon
andrewScan(Polygon s)
{
	Polygon u, l;
	int res;

	if (s.size() < 3)
		return s;

	sort(s.begin(), s.end()); // x, y ??????????????????????????????
	// x ????°????????????????????????? u ?????????
	u.push_back(s[0]);
	u.push_back(s[1]);

	// x ?????§???????????????????????? l ?????????
	l.push_back(s[s.size() - 1]);
	l.push_back(s[s.size() - 2]);

	// ??????????????¨?????????
	for (unsigned int i = 2; i < s.size(); ++i)
	{
		for (int n = u.size(); n >= 2; --n)
		{
			res = ccw(u[n - 2], u[n - 1], s[i]);
			if (res == CLOCKWISE || res == ONLINE_FRONT)
				break;

			u.pop_back();
		}

		u.push_back(s[i]);
	}

	// ??????????????¨?????????
	for (int i = s.size() - 3; i >= 0; --i)
	{
		for (int n = l.size(); n >= 2; --n)
		{
			res = ccw(l[n - 2], l[n - 1], s[i]);
			if (res == CLOCKWISE || res == ONLINE_FRONT)
				break;

			l.pop_back();
		}

		l.push_back(s[i]);
	}

	// ????¨????????????????????????????????????????????????????
	reverse(l.begin(), l.end());
	for (int i = u.size() - 2; i >= 1; --i)
		l.push_back(u[i]);

	return l;
}

int
main(int argc, char** argv)
{
	int n;
	Polygon s, r;
	Point p;

	scanf("%d", &n);
	while (n--)
	{
		scanf("%lf %lf", &p.x, &p.y);
		s.push_back(p);
	}

	r = andrewScan(s);
	printf("%ld\n", r.size());
	for (unsigned int i = 0; i < r.size(); ++i)
		printf("%.0f %.0f\n", r[i].x, r[i].y);

	return 0;
}

Measured memory_bytes: 10064
// package app;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        final int a = sc.nextInt();
        final int b = sc.nextInt();
        final int c = sc.nextInt();
        final int d = sc.nextInt();

        // d以内にabcがおさまっているか
        // a - b < d && b - c < dであればOK
        // a - c < dであればOK
        boolean canIndirectConnect = Math.abs(a - b) <= d && Math.abs(b - c) <= d;
        boolean canDirectConnect = Math.abs(a - c) <= d;

        System.out.println(canIndirectConnect || canDirectConnect ? "Yes" : "No");

    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  string s; cin >> s;

  map<char,int> cnt;
  int ans = 0;
  REP(i,s.size()) {
    char hand = s[i];
    char myhand = cnt['p'] < cnt['g'] ? 'p' : 'g';

    if (hand == 'g' && myhand == 'p') ans++;
    else if (hand == 'p' && myhand == 'g') ans--;

    cnt[myhand]++;
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 3784
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            ReadInt(out a, out b);

            int count = 1;
            int ans = 0;
            while (count < b)
            {
                ans++;
                count += a - 1;
            }

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static string YesNo(bool condition) => condition ? "Yes" : "No";
        static string YESNO(bool condition) => condition ? "YES" : "NO";

        #endregion
    }
}

Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static bool Solve(int N, int A, int B, int C, int D)
        {
            for (int i = 0; i < N - 1; ++i)
            {
                int j = N - 1 - i;
                long p1 = Math.BigMul(C, i);
                long p2 = Math.BigMul(D, i);
                long n1 = Math.BigMul(-D, j);
                long n2 = Math.BigMul(-C, j);
                if (A + p1 + n1 <= B && B <= A + p2 + n2) { return true; }
            }
            return false;
        }
        static void Main(string[] args)
        {
            var V = ReadInts();
            Console.WriteLine(Solve(V[0], V[1], V[2], V[3], V[4]) ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 11220
#include <vector>
#include <climits>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	vector<vector<int>> f(n, vector<int>(10)), p(n, vector<int>(11));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 10; j++)
			scanf("%d", &f[i][j]);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 11; j++)
			scanf("%d", &p[i][j]);

	int mx = INT_MIN;
	for (int i = 1; i < 1024; i++)
	{
		int t = i;
		vector<int> b(10);
		for (int j = 0; j < 10; j++)
		{
			b[j] = t & 1;
			t >>= 1;
		}

		int s = 0;
		for (int j = 0; j < n; j++)
		{
			int c = 0;
			for (int k = 0; k < 10; k++)
				c += f[j][k] * b[k];
			s += p[j][c];
		}
		mx = max(mx, s);
	}
	printf("%d\n", mx);

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

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

    // const int MAX_VAL = 1010001000;
    // vector<bool> exist(MAX_VAL, false);

    // rep(i, 0, n) {
    //     int idx;
    //     cin >> idx;
    //     exist[idx - 1] = !exist[idx - 1];
    // }

    // int cnt = 0;
    // rep(i, 0, exist.size()) {
    //     if (exist[i]) {
    //         cnt++;
    //     }
    // }

    map<int, bool> m;
    rep(i, 0, n) {
        int idx;
        cin >> idx;
        if (m[idx]) {
            m[idx] = false;
        } else {
            m[idx] = true;
        }
    }

    int cnt = m.size();
    for (auto val : m) {
        if (!val.second) {
            cnt--;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>

#define DEBT 100000

using namespace std;

int main(){
    int t, dbt=DEBT, frac;
    cin >> t;
    while(t--){
        dbt*=1.05;
        if(frac=dbt%1000){
            dbt+=1000-frac;
        }
    }
    cout << dbt << endl;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    int b[m];
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    int sum=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            sum+=a[i][j]*b[j];
        }
        cout<<sum<<endl;
        sum=0;
    }
    return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>
int main()
{
    int ar[50],n,i,count=0; 
    scanf("%d",&n);
    for (i=1; i<=n; i++)
    {
        scanf("%d",&ar[i]);
        if(ar[i]!=i)
            count++;
    }
    if(count>2)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
    
}


Measured memory_bytes: 2068
import itertools

h, w, k = map(int, input().split())
c = [input() for _ in range(h)]
ans = 0
for x, y in itertools.product(range(2 ** h), range(2 ** w)):
    cnt = 0
    for i, j in itertools.product(range(h), range(w)):
        if x >> i & 1 or y >> j & 1: continue
        if c[i][j] == '#': cnt += 1
    if cnt == k:
        ans += 1
print(ans)

Measured memory_bytes: 9032
N=int(input())
A,B = map(int,input().split())
P = list(map(int,input().split()))

p1,p2,p3 = [0]*3

for p in P:
    if p<=A:
        p1+=1
    elif p<=B:
        p2+=1
    else:
        p3+=1

print(min(p1,p2,p3))


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int caldigit(ll num){
  int out =0;
  while(num>0){
    if(num>0) ++out;
    num /=10;
  }
  return out;
}

int main() {
  ll n;cin >> n;
  ll sqrtn = (ll)sqrt(n);
  ll a,b;
  for(ll i=sqrtn; i>0; --i){
    if(n%i==0){
      a=i;
      b=n/i;
      break;
    }
  }
  cout << max(caldigit(a),caldigit(b)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

string s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    for(auto &i : s){
        if(i == '?') cout << 'D';
        else cout << i;
    }
    cout << endl;
}


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  for (int n, k; cin >> n >> k, n || k; ) {
    vector<bool> bl(n);
    bool bb = false;
    rep (i, k) {
      int x; cin >> x;
      if (x == 0) {
        bb = true;
      } else {
        bl[x - 1] = true;
      }
    }

    vector<int> xs;
    int ac = 0;
    rep(i, n) {
      if (bl[i]) {
        ++ac;
      } else {
        xs.push_back(ac);
        ac = 0;
      }
    }
    xs.push_back(ac);

    if (bb) {
      int ac = -1;
      rep (i, xs.size() - 1) {
        ac = max(ac, 1 + xs[i] + xs[i+1]);
      }
      cout << ac << endl;
    } else {
      int ac = -1;
      for (int x : xs) ac = max(x, ac);
      cout << ac << endl;
    }
  }  

  return 0;
}

Measured memory_bytes: 1352
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s= sc.next();
		String p=sc.next();
		int state=0;
		int a=0;
		boolean yn=false;
		while(true){
			if(state==0){
				for(int i=a;i<s.length();i++){
					if(s.charAt(i)==p.charAt(0)){
						state=1;
						a=i;
						break;
					}
				}
				if(state==0){
					break;
				}
			}else if(state==1){
				for(int j=1;j<p.length();j++){
					int k=(a+j)%s.length();
					if(s.charAt(k)!=p.charAt(j)){
						state=0;
						a++;
						break;
					}
				}
				if(state==1){
					yn=true;
					break;
				}
			}
		}
		if(yn){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26200
#include<bits/stdc++.h>
using namespace std;
const int mo=998244353,N=305;
int mi[N],n,m,i,j,k,a[N][N];
bitset<N>b[N],x;
int main(){
	for(i=*mi=1;i<N;++i)mi[i]=2ll*mi[i-1]%mo;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i){
		x.reset();
		for(j=0;j<m;++j)scanf("%d",a[i]+j),x.set(j,a[i][j]);
		for(j=0;j<m;++j)if(x[j]){
			if(b[j].any())x^=b[j];
				else{b[j]=x;break;}
		}
		if(j==m)++k;
	}
	i=(1ll*mi[m]*mi[k]+1ll*mi[m-1]*(mi[n]+mo-mi[k]))%mo;
	i=(1ll*mi[n]*mi[m]+mo-i)%mo;
	printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 640
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>

//#include <bits/stdc++.h>
using namespace std;
using LL = int;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum, ans, dp[10000], a[2000000], b[2000000];
string str, ss;
bool f[1100][1100];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
vector<Edge>vec[200000];
vector<LL>v,pick[200000];
map<string, vector<LL>>ma;
multiset<LL>st[3];
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m;
	cout << "01"[n<=m] << endl;
	return 0;
}



Measured memory_bytes: 12536
n,m=map(int,input().split())
a = set([])
for i in range(m):
	a.add(int(input()))
"""
壊れてるが2回以上続く→0
壊れてるが1回続く→そこは2段限定,RESET.

let Bn = [n段目に登る通り数]
Ex.1
1 2 3 4 5 6
1 2 # 2 2 4
結局はDPかな？
"""
dp = [0 for _ in range(n+1)]
dp[0] = 1
mod = 10**9+7
for i in range(1,n+1):
	if i in a:
		pass
	elif i==1:
		dp[i] = dp[i-1] % mod
	else:
		dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[n] % mod)

Measured memory_bytes: 11884
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int b, c;
int a[10000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> b>>c;
    cout << max(b-2*c,0) << "\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint r, d, x; cin >> r >> d >> x;
  for (int i = 0; i < 10; ++i) {
    x = r * x - d;
    cout << x << '\n';
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}


#define N 	100*1000+5
void solve(){	
	ll n, ans = 0;
	cin>>n;
	map<string, ll>m;
	rep(i,0,n){
		string s;
		cin>>s;
		sort(all(s));
		if(m.find(s) != m.end()) ans += m[s];
		m[s]++;
	}
	cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 11904
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int k, t;
	cin >> k >> t;
	
	priority_queue< pair<int, int> > pq;
	for(int i = 0; i < t; ++i) {
		int a;
		cin >> a;
		pq.push({a, i});
	}
	
	int ans = 0;
	int last = -1;
	while( !pq.empty() ) {
		pair<int, int> x = pq.top();
		pq.pop();
		
		if( x.second != last ) {
			x.first -= 1;
			last = x.second;
			
			if( x.first > 0 ) pq.push(x);
		} else {
			if( pq.empty() ) {
				ans += x.first;
				break;
			}
			
			pair<int, int> y = pq.top();
			pq.pop();
			
			y.first -= 1;
			last = y.second;
			pq.push(x);
			
			if( y.first > 0 ) pq.push(y);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

using vi = std::vector<int>;
using vvi = std::vector<vi>;

vvi table;

void dfs(int left, int right, int level);

int main()
{
	int N;
	scanf("%d", &N);
	table.resize(N, vi(N));
	dfs(0, N, 1);
	for (int i{}; i < N; i++)
		for (int j{i + 1}; j < N; j++)
			printf("%d%c", table[i][j], j + 1== N? '\n': ' ');

	return 0;
}

void dfs(int left, int right, int level)
{
	if (right - left == 1) return;
	int top{20}, mid{(left + right) / 2};
	for (int i{left}; i < mid; i++)
		for (int j{mid}; j < right; j++)
			table[i][j] = level;
	dfs(left, mid, level + 1);
	dfs(mid, right, level + 1);
}

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

using namespace std;

/*
a_0 a_1 ... a_{n-1}
wlog assume that
a_0 >= a_1 >= ... >= a_{n-1}
a_0, ..., a_{p-1} all have a chances obviously.

Now take a_i with i >= p.


Then we can look at:

a_{p-1}, a_{p+1}, ..., a_{i-1}

We can give one to all of a_0, ..., a_{p-2} and all of a_{i+1}, ... , a_{n-1} in each round. And of course i.
That is p-1 + n-i-1 + 1 = p + n - i - 1 in total. So:
Case (1): p + n - i - 1 >= v. Then we just check if a_i + m >= a_{p-1}.

Now assume that p + n - i - 1< v. Then say that alpha = v - (p + n - i - 1) is the number of votes we need to give to a_{p-1}, ..., a_{i-1} in each round.
We assume that a_i + m >= a_{p-1} since otherwise it becomes trivial: it is not possible. The total number of votes we can afford to give to these members is:
\sum_{j={p-1}}^{i-1} (a_i + m) - a_j = (i-p+1) * (a_i + m) - A_i + A_{p-1} where A_j = a_1 + ... + a_{j-1}
So now we just check if (i-p+1) * (a_i + m) - A_i + A_{p-1} >= alpha * m or not.
Remember to calculate with long longs since A_j can be approx 10^18.
*/

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<long long> as(n);
    for (auto& a : as) {
        cin >> a;
    }
    sort(as.begin(), as.end(), [](int i, int j) { return i > j; });
    vector<long long> As(n+1, 0);
    for (int i = 0; i < n; ++i) {
        As[i+1] = As[i] + as[i];
    }
    long long count = 0;
    for (int i = 0; i < n; ++i) {
        if (i < p) {
            ++count;
            continue;
        }
        if (as[i] + m < as[p-1]) {
            continue;
        }
        long long alpha = v - (p + n - i - 1);
        if (alpha <= 0) {
            ++count;
            continue;
        }
        // Now we know that alpha > 0 and a[i] + m >= a[p-1]
        long long beta = (i-p+1) * (as[i] + m) - As[i] + As[p-1];
        if (beta >= alpha * m) {
            ++count;
        }
    }
    cout << count << endl;
    return 0;
}


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

ll dp[101][100001];

int main() {
  int n, W;
  cin >> n >> W;
  vector<int> v(n), w(n);
  rep(i, n) cin >> w[i] >> v[i];

  rep(i, n) rep(j, W + 1) {
    if (j < w[i])
      dp[i + 1][j] = dp[i][j];
    else
      dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
  }
  cout << dp[n][W] << endl;
  return 0;
}

Measured memory_bytes: 78336
#include <stdlib.h>
#include <assert.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <complex>
#include <iomanip>
#include <bitset>
#include <random>
#include <vector>
#include<string>
#include <limits.h>

using namespace std;

// Used to track farthest node. 
int x;

// Sets maxCount as maximum distance from node. 
void dfsUtil(int node, int count, bool visited[],
	int& maxCount, list<int>* adj)
{
	visited[node] = true;
	count++;
	for (auto i = adj[node].begin(); i != adj[node].end(); ++i) {
		if (!visited[*i]) {
			if (count >= maxCount) {
				maxCount = count;
				x = *i;
			}
			dfsUtil(*i, count, visited, maxCount, adj);
		}
	}
}

// The function to do DFS traversal. It uses recursive 
// dfsUtil() 
void dfs(int node, int n, list<int>* adj, int& maxCount)
{
	bool visited[n + 1];
	int count = 0;

	// Mark all the vertices as not visited 
	for (int i = 1; i <= n; ++i)
		visited[i] = false;

	// Increment count by 1 for visited node 
	dfsUtil(node, count + 1, visited, maxCount, adj);
}

// Returns diameter of binary tree represented 
// as adjacency list. 
int diameter(list<int>* adj, int n)
{
	int maxCount = INT_MIN;

	/* DFS from a random node and then see
	farthest node X from it*/
	dfs(1, n, adj, maxCount);

	/* DFS from X and check the farthest node
	from it */
	dfs(x, n, adj, maxCount);

	return maxCount;
}

int main() {
	int n, i,a,b;
	cin >> n;
	list<int>* adj = new list<int>[n + 1];
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int p = diameter(adj, n);
	if (p % 3 == 2)
		cout << "Second" << endl;
	else
		cout << "First" << endl;
}


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

int main(void)
{
	char s[100];  
    char a[100], b[100];
	int i;
  
    scanf("%s", s);
    int n = strlen(s);

    strncpy(a, s, n/2);
    strncpy(b, s+(n+3)/2-1, n/2);
  
    int f0 = 1;
    int f1 = 1;
  	int f2 = 1;
  
    for (i=0; i<n/2; i++) {
      if (s[i]!=s[n-1-i]) {
        f0 = 0;
        break;
      }
    }
        
    if (f0) {
      for (i=0; i<n/4; i++) {
        if (a[i]!=a[n/2-1-i]) { f1=0; break; }
        if (b[i]!=b[n/2-1-i]) { f2=0; break; }
      }
    }
  
    if (f0 && f1 && f2)
      printf("Yes\n");
  
    else
      printf("No\n");
  
    return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;


public class Main {
//	入力値
	static Scanner scInputData = new Scanner(System.in);
//	配列
	static ArrayList<Product> arrProduct= new ArrayList<Product>();
	
	public static void main(String[] args) {
		
//		必要なパラメータを用意する処理
//		品物情報を取得する処理
		getProduct();
//		品物を所定の順でソートする処理
		compareProduct();
//		結果を出力する処理
		putResult();
	}
	
	private static void putResult() {
		for(Product pdt : arrProduct) {
			System.out.println(pdt.getPrice() + " " 
					+ pdt.getWeight() + " " 
					+ pdt.getPattern() + " " 
					+ pdt.getDate() + " " 
					+ pdt.getName());
		}
	}
	
	private static void compareProduct() {

		Collections.sort(arrProduct, new Comparator<Product> () {//価格でソート
			public int compare(Product pdt1, Product pdt2) {
				return Integer.compare(pdt1.getPrice(), pdt2.getPrice());
			}
		}.thenComparing(new Comparator<Product>() { //価格が同じ場合、重さでソート 
			public int compare(Product pdt1, Product pdt2) {
				return Integer.compare(pdt1.getWeight(), pdt2.getWeight());
			}
		}).thenComparing(new Comparator<Product>() { //重さが同じ場合、型でソート 
			public int compare(Product pdt1, Product pdt2) {
				return pdt1.getPattern().compareTo(pdt2.getPattern());
			}
		}).thenComparing(new Comparator<Product>() { //型が同じ場合、日時でソート 
			public int compare(Product pdt1, Product pdt2) {
				return Long.compare(pdt1.getDate(), pdt2.getDate());
			}
		}).thenComparing(new Comparator<Product>() { //日時が同じ場合、名前でソート 
			public int compare(Product pdt1, Product pdt2) {
				return pdt1.getName().compareTo(pdt2.getName());
			}
		}));
	}
	private static void getProduct() {
//		 品物の数
		int iProductNum = scInputData.nextInt();
		while(arrProduct.size() < iProductNum) {
			Product pdt = new Product(scInputData.nextInt(), 
					scInputData.nextInt(), 
					scInputData.next(), 
					scInputData.nextLong(), 
					scInputData.next());
			arrProduct.add(pdt);
		}
	}
//	品物情報を扱うクラス
	static class Product{
		int price, weight;
		long date;
		String pattern, name;
		public Product(int price, int weight, String pattern, long date, String name) {
			this.price = price;
			this.weight = weight;
			this.pattern = pattern;
			this.date = date;
			this.name = name;
		}
		int getPrice() {
			return price;
		}
		int getWeight() {
			return weight;
		}
		String getPattern() {
			return pattern;
		}
		long getDate() {
			return date;
		}
		String getName() {
			return name;
		}
	}
}


Measured memory_bytes: 189000
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n , k;
    cin >> n >> k ;
    int stp =0 ,cur=0;
    while(cur<n){
        stp++;
        cur+=k;
        if(cur>=n) break;
        cur--;
    }
    cout << stp <<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int da[1000];
    int n;
    while(cin>>n)
    {
        int i,j;
        int sum=0,a;
        for(i=0;i<n;i++)
        {
            cin>>da[i];
            if(da[i]%2==0)
            {
                sum++;
            }
        }
        a=pow(3,n)-pow(2,sum);
        cout<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
	ll n;	cin>>n;
	vector<ll> a(n),b(n);
	for(int i=0;i<n;i++)	cin>>a[i]>>b[i];
	ll ans=0;
	for(int i=n-1;i>=0;i--){
		a[i]=(a[i]+ans)%b[i];
		if(a[i]!=0)	ans+=b[i]-a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int i=0,j,c=0,k;
    string s;
    cin >> s;
    k=s.size();
    if(s[0]!='A' || s[1]<'a' || s[k-1]<'a' )
    {
        cout << "WA" << endl;
        return 0;
    }
  
    for(i=2;i<k-1;i++)
    {
        if(s[i]=='C')
        {
            c++;
            if(c==2)
            {
                cout << "WA" << endl;
                return 0;
            }
            continue;
        }
        if(s[i]<'a')
        {
            cout << "WA" << endl;
            return 0;
        }
    }
    if(c==1)
    {
        cout << "AC" << endl;
    }
    else
    {
        cout << "WA" << endl;
    }
    return 0;

}


Measured memory_bytes: 3620