akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, m, a[50], b[50], c[50], d[50];
	cin >> n >> m;
	REP(i, n) cin >> a[i] >> b[i];
	REP(i, m) cin >> c[i] >> d[i];

	REP(i, n){
		int min = INF;
		REP(j, m){
			int man = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(man < min) min = man;
		}
		REP(j, m){
			int man = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(min == man){
				cout << j + 1 << endl;
				break;
			}
		}
	}

	rtn 0;
}

Measured memory_bytes: 256
import math
A,B,N = map(int,input().split())
x = 0
# Bに対して一番余剰が大きくなる数字をとりたい
if B <= N:
    x = B-1
else:
    x = N
print(math.floor((A*x)/B)-A*math.floor(x/B))


Measured memory_bytes: 9112
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

signed main() {
    int n; cin >> n;
    int mx = 0;
    int sum = 0;
    for(int i = 0; i < n; i++) {
        int p; cin >> p;
        mx = max(mx, p);
        sum += p;
    }
    cout << sum - mx / 2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using data=pair<ll,ll>;
#define Rep(i,N) for(i=0;i<N;i++)
#define mod 1000000007

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
ll modncr(ll n,ll r){
  ll i,plus=1;
  Rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){
  ll i,j,N,K,m=0,ans,pl=0,mi=0;
  cin>>N>>K;
  Rep(i,N-1){
    cin>>m;
    K=euclidean_gcd(K,m);
  }
  cout << K<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;


int main() {
    int N, M;
    int A;
    int popular;
    vector < int > arrA;

    cin >> N;
    cin >> M;

    for (int i = 0; i < N; i++) {
        cin >> A;
        arrA.push_back(A);
    }

    float total;
    total = accumulate(arrA.begin(), arrA.end(), 0);

    for (auto i: arrA) {
        float denom = 4 * M;
        float check = total * (1 / denom);
        if (i >= check) {
            popular++;
        }
    }

    if (popular >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import collections
count = 0
N = int(input())
candidates = []
for i in range(N):
    candidates.append("".join(sorted(input())))
new = set(candidates)
a = collections.Counter(candidates)
for j in a.values():
    if j == 2:
        count += 1
    elif j != 1:
        count += int(j*(j-1)/2)
print(count)

Measured memory_bytes: 72660
#include<bits/stdc++.h>
using namespace std;
#define N 100004
int S[N];
int memo[N];
int n;
int dp(int pos) {
    if(pos == n-1) {
        return 0;
    }
    if(memo[pos]!=-1) return memo[pos];
    if(pos + 2 < n) {
        int r1 = abs(S[pos] - S[pos+1]) + dp(pos+1);
        int r2 = abs(S[pos] - S[pos+2]) + dp(pos+2);
        return memo[pos] = min(r1, r2);
    }
    if(pos + 1 < n){
        return memo[pos] = abs(S[pos] - S[pos+1]) + dp(pos+1);
    }
}
int main(){
    scanf("%d",&n);
    for(int i = 0; i < n; i++) {
        scanf("%d",S + i);
        memo[i] = -1;
    }
    printf("%d\n", dp(0));
}


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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


int main() {
    int n;
    cin >> n;
    if (n >= 30)
    prt("Yes");
    else
    prt("No");

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

using namespace std;

int main() {
    string s; cin >> s;
    int tmp=0, ans=0;
    rep(i, s.size()) {
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') {
            tmp++;
        } else {
            ans = max(ans, tmp);
            tmp = 0;
        }
    }

    ans = max(ans, tmp);

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int 
using namespace std; 
ll dp[3004][3004];
string solve1(string a,string b,int i,int j)
{
  string v;
 
  while(i>0 && j>0)
  {
    if(a[i-1]==b[j-1])
    {
      
     
      v.push_back(a[i-1]);
      i--;
     j--;
    }
    else
    {
      if(dp[i-1][j]>=dp[i][j-1])
      {
        i--;
      }
      else
      {
        j--;
      }
      
    }
    
  }
  return v;

}
int main() 
{ 
  FastIO;
  string a;
  string b;
  cin>>a>>b;
  
  for(ll i=0;i<=a.length();i++)
  {
    dp[i][0]=0;
  }
  for(ll i=0;i<=b.length();i++)
  {
    dp[0][i]=0;
  }
  for(int i=1;i<=a.length();i++)
  {
    for(int j=1;j<=b.length();j++)
    {
      if(a[i-1]==b[j-1])
      {
        dp[i][j]=dp[i-1][j-1]+1;
      }
      else
      {
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
      
    }
  }
  string s=solve1(a,b,a.size(),b.size());
  reverse(s.begin(),s.end());
  cout<<s;
} 


Measured memory_bytes: 74044
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<P,double> C;
typedef vector<P> Poly;
#define X real()
#define Y imag()
#define EPS (1e-10)


double dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}

double cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}

int main(){
  int N;
  cin >> N;
  vector<P> V;
  double x, y;
  for(int i = 0; i < N; ++i){
    cin >> x >> y;
    V.emplace_back(x,y);
  }
  for(int i = 1; i < N; ++i){
    P d = V[i] - V[i-1];
    double l = 0, r = 0;
    for(int j = i+1; j < N; ++j){
      //if(i == j || j == i-1) continue;
      P v = V[j] - V[i];
      if(cross(d,V[j]-V[i]) > 0){
        l = max(l,acos(dot(d,v)/abs(d)/abs(v)));
      }else{
        r = max(r,acos(dot(d,v)/abs(d)/abs(v)));
      }
    }
    if(r + l > acos(-1)){
      cout << "Impossible" << endl;
      return 0;
    }
    for(int j = 0; j < i; ++j){
      P v = V[j] - V[i];
      if(cross(d,V[j]-V[i]) > 0){
        if(l > acos(dot(d,v)/abs(d)/abs(v))){
          cout << "Impossible" << endl;
          return 0;
        }
      }else{
        if(r > acos(dot(d,v)/abs(d)/abs(v))){
          cout << "Impossible" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Possible" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int ans;
int N;

int main(void) {
    scanf("%d", &N);

    int pmax = 0;
    REP(i, 0, N) {
    	int p;
    	scanf("%d", &p);
    	ans += p;
    	pmax = max(p, pmax);
    }
    ans -= pmax / 2;

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

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int insection_sort(int *A, int n, int g){
	int cnt = 0;
	int i,j,v;

	for(i=g;i<=n-1;i++){
		v = A[i];
		j = i - g;
		while( j>=0 && A[j]>v ){
			A[j+g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j+g] = v;
	}

	return cnt;
}

int shell_sort(int *A, int n, int *G, int m){
	int total_cnt = 0;
	int i,cnt;

	for(i=0;i<=m-1;i++){
		cnt = insection_sort(A, n, G[i]);
		total_cnt += cnt;
	}

	return total_cnt;
}

int is_sorted(int *A, int n){
	int i;

	for(i=0;i<n-1;i++){
		if( A[i] > A[i+1] ){
			return 0;
		}
	}

	return 1;
}

int main(int argc, char** argv){
	int *A,n,*G,m,total_cnt;
	int i,j;

	// Create A
	scanf("%d",&n);
	A = malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d",A+i);
	}

	// Create G
	j = 1;
	m = 0;
	while( j <= n ){
		m++;
		j = j * 3 + 1;
	}
	G = malloc(sizeof(int)*m);
	j = 1;
	for(i=0;i<m;i++){
		G[m-i-1] = j;
		j = j * 3 + 1;
	}

	// Sort
	total_cnt = shell_sort(A,n,G,m);
	// Output
	printf("%d\n",m);
	for(i=0;i<m;i++){
		if( i > 0 ){
			putchar(' ');
		}
		printf("%d",G[i]);
	}
	putchar('\n');
	printf("%d\n",total_cnt);
	for(i=0;i<n;i++){
		printf("%d\n",A[i]);
	}

	// Delete G
	free(G);

	// Delete A
	free(A);

	return 0;
}

Measured memory_bytes: 4252
#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <string>
#define MAX_N 1001
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef pair<string, int> P;
P p[MAX_N];
int n;

int main(){
    string s;
    n = 0;
    while(cin >> s){
        bool flag = false;
        rep(i, n){
            if(p[i].first == s){
                p[i].second++;
                flag = true;
            }
        }
        if(!flag){ 
            p[n].first = s;
            p[n].second++;
            n++;
        }
    }
    // rep(i, n) cout << p[i].first << " " << p[i].second << endl;
    sort(p, p+n, [](const P &left, const P &right){
        return left.second > right.second;
    });
    cout << p[0].first << " ";
    sort(p, p+n, [](const P &left, const P &right){
        return left.first.size() > right.first.size();
    });
    cout << p[0].first << endl;
    return 0;
}


Measured memory_bytes: 3180
NN = 19
XX = [0] * (2**(NN+1)-1)

def addvalue(j, x):
    i = 2**NN + j - 1
    while i >= 0:
        XX[i] += x
        i = (i-1) // 2

def rangesum(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    s = 0
    while l < r:
        if l%2:
            s += XX[l-1]
            l += 1
        if r%2:
            r -= 1
            s += XX[r-1]
        l >>= 1
        r >>= 1
    return s

N, Q = map(int, input().split())
C = [int(a) - 1 for a in input().split()]
X = [[] for _ in range(N)]
for i in range(Q):
    l, r = map(int, input().split())
    X[r-1].append((l - 1, i))
last = [-1] * N
ANS = [-1] * Q
addvalue(1, N)
for r in range(N):
    c = C[r]
    addvalue(last[c] + 2, -1)
    addvalue(r + 2, 1)
    last[c] = r
    for l, i in X[r]:
        ANS[i] = rangesum(l + 2, 1 << NN)
    
print(*ANS, sep = "\n")

Measured memory_bytes: 208840
#include<iostream>

using namespace std;

string R,G,D;
int pr,pg;
char now;
bool isR;

void init(){
  pr = 0;
  pg = 1;
  now = G[0];
  isR = false;
}
int main(){
  while(cin >> R && R != "-"){
    cin >> G >> D;
    init();
    
    string ans = "";
    int nr = 0;

    for(int i = 0; i < D.length(); i++){
      //  cout  << "now " << now << endl;
      if(now == D[i]){
	//push_down
	now = R[pr++];
      }else{
	//push_right
	ans += now;
	now = G[pg++];
	i--;
	nr++;
      }
    } 

    while(nr < G.length()){
      ans += now;
      now = G[pg++];
      nr++;
    }
    cout << ans << endl;
  }
  return 0;
}

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



int main() {
  string N,N2;
  int K,S=0;
  vector<int> T(0);
  cin>>N>>K;
  N2=N;
  S=N.size();
  rep(i,S){

      T.push_back(N.at(i)-'0');
  }
  
  if(K==1){cout<<9*(S-1)+T.at(0)<<endl;}
  if(K==2){
      if(S<2){cout<<0<<endl;}
      else{
      ll ans=0;
      bool judge=true;//2桁目以降0が続いているかどうか
      for(int i=2;i<S;i++){ans+=81*(i-1);}
      rep(i,S-1){
          if(judge){ans+=T.at(0)*9-9+T.at(i+1);}
          else{ans+=T.at(0)*9;}
          if(T.at(i+1)!=0){judge=false;}
      }
      cout<<ans<<endl;}
  }
  if(K==3){
      if(S<3){cout<<0<<endl;}
      else{
      ll ans=0;
      for(int i=3;i<S;i++){ans+=729*(i-1)*(i-2)/2;}
      
      ans+=(T.at(0)-1)*9*9*(S-1)*(S-2)/2;
      bool j=false;
      vector<int> T2(0);
      for(int i=1;i<S;i++){
          if(T.at(i)!=0){j=true;}
          if(j){T2.push_back(T.at(i));}
      }
      int S2=T2.size();

      bool judge=true;//2桁目以降0が続いているかどうか
      for(int i=2;i<S2;i++){ans+=81*(i-1);}
      rep(i,S2-1){
          if(judge){ans+=T2.at(0)*9-9+T2.at(i+1);}
          else{ans+=T2.at(0)*9;}
          if(T2.at(i+1)!=0){judge=false;}
      }
      cout<<ans<<endl;}
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

#define MAX_V 10000
vector<int> G[MAX_V];


int main(){
    int v,e;
    cin>>v>>e;
    vector<int> in_deg(v,0);
    vector<int> list;
    
    rep(i,e){
        int s,t;
        cin>>s>>t;
        in_deg[t]++;
        G[s].pb(t);
    }
    
    stack<int> st;
    rep(i,v)if(in_deg[i]==0)st.push(i);
    
    while(st.size()){
        int q = st.top();
        st.pop();
        list.pb(q);
        
        rep(i,G[q].size()){
            int to = G[q][i];
            in_deg[to]--;
            if(in_deg[to]==0)st.push(to);
        }
    }
    
    rep(i,list.size())cout<<list[i]<<endl;
    
    if(list.size()!=v){/*????????????*/}
}

Measured memory_bytes: 3916
#coding: utf-8
import math

def up(n):
    print(n % 1)

if __name__ == "__main__":
    n,k = map(int,input().split())
    a = input().split(" ")
    prev = True
    pre,post = (0,0)
    remain = k
    result = 0
    for i in range(n):
        a[i] = int(a[i])
        if a[i] != 1 and prev == True:
            pre += 1
        if a[i] == 1:
            prev = False
            result += int(pre / (k-1)) + 1
            remain = k - (pre % (k-1) + 1)
            continue
        if prev == False and remain > 0:
            a[i] = 1
            remain -= 1
            continue
        if a[i] != 1 and prev == False:
            post += 1

    result += math.ceil(post / (k-1))

    print(result)
    

Measured memory_bytes: 10420
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i< (n);++i)
typedef long long ll;

using namespace std;


int main(){
    
    ll N,D;
    cin>>N>>D;
    
    ll count=0;
    
    
    rep(i,N){
        ll x,y;
        cin>>x>>y;
        
        double d=sqrt(x*x+y*y);
        if(d<=(double)D){
            ++count;
        }
    }
    
    cout<<count<<endl;

}



Measured memory_bytes: 3676
def main():
    N = int(input())
    # 赤が青の左下にあるようなペアを最大幾つとれるか
    # 全ての点のx,yそれぞれが同じ値になる事はない
    # bluesの左側から見ていって、その点より左下のredsがあるならその中でyが一番大きいものをとる
    reds,blues = [],[]
    for i in range(N):
        a,b = map(int,input().split())
        reds.append([a,b])
    for i in range(N):
        c,d = map(int,input().split())
        blues.append([c,d])
    reds = sorted(reds, key=lambda x:-x[1])
    blues = sorted(blues, key=lambda x:x[0])
    ans = 0
    for i in range(N):
        flag = False
        for j,r in enumerate(reds):
            if blues[i][0]>r[0] and blues[i][1]>r[1]:
                flag = True
                reds.pop(j)
                ans += 1
                break
    print(ans)

main()


Measured memory_bytes: 3064
import java.util.Scanner;
import java.lang.Math;
import java.util.Arrays;

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

        String S = sc.next();
        String T = sc.next();

        char[] charS = new char[S.length()];
        for(int i = 0; i<S.length(); i++){
            charS[i] = S.charAt(i);
            //System.out.println(charS[i]);
        }
        char[] charT = new char[T.length()];
        for(int i = 0; i<T.length(); i++){
            charT[i] = T.charAt(i);
            //System.out.println(charT[i]);
        }

        //完全一致は先に除く
/*        if(S.matches(String.format(".*%s.*", T))){
            System.out.println("0");
        }*/

        //全部調べて、それぞれ何回変更したかをカウントする、[]は調べる回数
        int[] count = new int[S.length()-T.length()+1];


        //この回数ずらしてforを回す
        for(int j = 0; j<S.length()-T.length()+1; j++){
            //それぞれの文字が変更される回数を調べる
            for(int k = 0; k<T.length(); k++){
                if(charS[j+k] != charT[k]){
                    count[j]++;
                }
            }
        }

        Arrays.sort(count);
        System.out.println(count[0]);

    }
}

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

int n, m;
vector<int> et[50];

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		et[a-1].push_back(b-1);
		et[b-1].push_back(a-1);
	}
	
	for (int i = 0; i < n; i++) {
		cout << et[i].size() << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var (
		N   int
		ans = 0
	)
	fmt.Scan(&N)
	A := make([]int, N)
	B := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&A[i], &B[i])
	}

	for i := N - 1; i >= 0; i-- {
		A[i] += ans
		if A[i]%B[i] != 0 {
			ans += abs((A[i] % B[i]) - B[i])
		}
	}
	fmt.Println(ans)
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}


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

int main() {
  int N, A; cin >> N >> A;
  vector<int> X(N);
  for (int i = 0; i < N; i++) cin >> X.at(i);
  // dp[i][k][s] := i 枚目までのうち k 枚採用し、合計が s となる
  vector<vector<vector<long long>>> dp(N+1, vector<vector<long long>>(N+1, vector<long long>(2555)));
  dp.at(0).at(0).at(0) = 1;
  for (int i = 0; i < N; i++) {
    for (int k = 0; k < i+1; k++) {
      for (int s = 0; s <= 50*i; s++) {
        // 選ぶ
        dp.at(i+1).at(k+1).at(s+X.at(i)) += dp.at(i).at(k).at(s);
        // 選ばない
        dp.at(i+1).at(k).at(s) += dp.at(i).at(k).at(s);
      }
    }
  }
  long long ans = 0;
  for (int k = 1; k <= N; k++) {
    ans += dp.at(N).at(k).at(k*A);
  }
  cout << ans << endl;
}

Measured memory_bytes: 56220
using System;

class Program {
    static void Main(string[] args) {
        //入力
        string s = Console.ReadLine();
        string[] t = s.Split(' ');

        //変数の割り当て
        int N = int.Parse(t[0]);
        int H = int.Parse(t[1]);
        int W = int.Parse(t[2]);

        string[] u = new string[N];
        int[] A = new int[N];
        int[] B = new int[N];

        //全ての長方形の板の入力
        for (int i = 0; i < N; i++) {
            u[i] = Console.ReadLine();
            A[i] = int.Parse(u[i].Split(' ')[0]);
            B[i] = int.Parse(u[i].Split(' ')[1]);
        }

        //カウンタ
        int ans = 0;

        //チェック
        for (int i = 0; i < N; i++) {
            if (A[i] >= H && B[i] >= W) {
                ans++;
            }
        }

        //出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11204
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<char> s(N + 1);
  vector<int> t(N);
  scanf("%s", s.data());

  int count = 0;
  for (int i = 0; i < N - 1; i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      t[i] = count;
      count++;
      t[i + 1] = count;
      i++;
    } else {
      t[i] = count;
    }
  }
  t[N - 1] = count;

  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << (t[r - 1] - t[l - 1]) << endl;
  }

  return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main(void)
{

        int a,b,c,n,m;

        scanf("%d%d%d",&a,&b,&c);

        if(a-b<0) n=b-a;
        else n=a-b;

        if(a-c<0) m=c-a;
    else m=a-c;

        if(n>m) printf("B\n");
        else printf("A\n");

        return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


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

    ll n;
    cin >> n;
    ll h[n];
    ll tmpm = 0;
    ll ans =0;
    F0R(i,n){
      cin >> h[i];
      if(tmpm <= h[i]) {
        ++ans;
        tmpm = h[i];
      }
    }

    cout << ans<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main(){
  int N;
  cin >> N;
  int x=7;
  int y=4;
  for(int i=0;;i++){
    if(x*i>N){
      break;
    }
    for(int j=0;;j++){
      if(y*j>N){
        break;
      }
      if(x*i+y*j==N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n,a[1001]={};
  while(1){
    int min=1000000;
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++) cin>>a[i];

    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
	  if(min>abs(a[i]-a[j]))min=abs(a[i]-a[j]);

    cout<<min<<endl;
  }
  return 0;
}

Measured memory_bytes: 3044
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define LL long long
const LL mod = 1e9 + 7;
LL dp[41][1 << 17];//現在地、前の数字
int n, x, y, z;
int main() {
	std::cin >> n >> x >> y >> z;
	int xyz = (1 << (x + y + z - 1)) + (1 << (y + z - 1)) + (1 << (z - 1));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < (1 << x+y+z); j++) {
			for (int k = 0; k < 10; k++) {
				int ac = j << (k + 1) | 1 << k;
                ac &= (1<<(x+ y+z))-1;
				if ((ac&xyz)==xyz)continue;                
				dp[i + 1][ac] += dp[i][j];
				dp[i + 1][ac] %= mod;
			}
		}
	}
	LL ans = 0;
	for (int i = 0; i < (1 << (x+y+z)); i++) {
		ans += dp[n][i];
		ans %= mod;
	}
    LL all=1;
    for(int i=0;i<n;i++){
        all*=10;
        all%=mod;
    }
    ans=all-ans;
    if(ans<0)ans+=mod;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 41216
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    ll Y;
    cin >> N >> Y;
    rep(i, N+1){
        rep(j, N+1){
            int k = N - (i + j);
            if(k < 0) break;
            ll x, y, z;
            x = i * 10000;
            y = j * 5000;
            z = k * 1000;
            ll sum = x + y + z;
            if(sum == Y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100005;
int ar[N];
ll dp[N];
int n, k;
int main(){
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		cin >> ar[i];
	}
	dp[0] = dp[1] = 0;
	for (int i = 2; i <= n; i++){
		ll mn = 1000000000000;
		for (int j = 1; j <= k && i - j > 0; j++){
			mn = min(mn, dp[i - j] + (ll) abs(ar[i] - ar[i - j]));
		}
		dp[i] = mn;
	}
	cout << dp[n] << '\n';
	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int NA = min(X / 500, A);
  int NB = min(X / 100, B);
  int NC = min(X / 50, C);
  int cnt = 0;
  for (int i = 0; i <= NA; ++i) {
    for (int j = 0; j <= NB; ++j) {
      for (int k = 0; k <= NC; ++k) {
        cnt += 500 * i + 100 * j + 50 * k == X;
      }
    }
  }
  printf("%d\n", cnt);
}

Measured memory_bytes: 3220
s = input()

t, u = '', ''
for i in range(len(s)):
    t += '1' if i%2 == 0 else '0'
    u += '0' if i%2 == 0 else '1'

s = int(s, 2)
t = int(t, 2)
u = int(u, 2)
print(min(bin(s^t).count('1'), bin(s^u).count('1')))

Measured memory_bytes: 9276
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N, A;
    cin >> N >> A;
    cout << ( ( N % 500 ) <= A ? "Yes" : "No" ) << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import queue
N = int(input())

d = defaultdict(lambda: defaultdict(int))
for i in range(N-1):
    u, v, w = list(map(int, input().split()))
    d[u-1][v-1] = w
    d[v-1][u-1] = w
for i in range(N):
    if len(d[i]) == 1:
        start = i
        break

visited = [False for _ in range(N)]
visited[start] = True
all_length =  [0 for _  in range(N)]
q = queue.Queue()
q.put(start)
while not q.empty():
    i = q.get()
    for v, w in d[i].items():
        if not visited[v]:
            q.put(v)
            visited[v] = True
            all_length[v] = all_length[i] + w
for length in all_length:
    print(length % 2)




Measured memory_bytes: 59876
n = int(input())
a = list(map(int, input().split()))

count = 0
while(True):
    flag = True
    for i in range(n):
        if a[i] % 2 != 0:
            flag = False
            break

    if flag == False:
        break
    else:
        count += 1
        for i in range(n):
            a[i] = a[i] // 2

print(count)


Measured memory_bytes: 3060
def resolve():
    import sys
    input = sys.stdin.readline
    nm = [int(x) for x in input().rstrip().split()]
    a = [int(x) for x in input().rstrip().split()]


    if sorted(a, reverse=True)[nm[1]-1] < sum(a) / (4 * nm[1]):
        print("No")
    else:
        print("Yes")

resolve()

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <utility>
#include <iomanip>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j;
  ld result=0;
  ld a[200010];
  string s;
  cin >> n;
  rep(i,n){
    cin >> a[i];
    result += 1.0 / a[i];
  }
  cout << fixed << setprecision(16) << 1.0/result << endl;
  return 0;
}

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

int main(){
  int W, H, N;
  cin >> W >> H >> N;
  vector<vector<int>> vec(H, vector<int>(W));
  int x, y, a, x0, x1, y0, y1;
  rep(n, N) {
    x0 = 0;
    y0 = 0;
    x1 = W;
    y1 = H;
    cin >> x >> y >> a;
    if (a == 1) x1 = x ;
    if (a == 2) x0 = x ;
    if (a == 3) y1 = y ;
    if (a == 4) y0 = y ;
    
    for(int i = x0; i < x1; i++){
      for(int j = y0; j < y1; j++){
        vec.at(j).at(i)++;
      }
    }
  }
  
  int area = 0;
  
  rep(i, W){
    rep(j, H){
      if(vec.at(j).at(i) == 0) area++;
    }
  }
  cout << area << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    A, B, C, K = map(int, input().split())

    ans = 0
    k = 0
    ans += min(A, K-k)
    k += min(A, K-k)
    k += min(B, K-k)
    ans -= K-k

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main(){
	
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		int a[2000];
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		sort(a, a + n);
		int ans = 0;
		int j = n - 1;
		bool flag = true;
		for(int i = 0; i < n; i++){
			while(true){
				if(j <= i){
					if(i == 0){
						flag = false;
					}
					break;
				}
				if(a[i] + a[j] <= m){
					ans = max(ans, a[i] + a[j]);
					break;
				}
				j--;
			}
		}
		if(flag){
			cout << ans << endl;
		}else{
			cout << "NONE" << endl;
		}
	}
	
	
	return 0;
	
}



Measured memory_bytes: 3084
def main():
    D = int(input())
    C = list(map(int, input().split()))
    S = []
    for i in range(D):
        S.append(list(map(int, input().split())))
    T = []
    for i in range(D):
        T.append(int(input()))
    # print(D, C, S, T)
    last = [0]*26
    score = 0
    ans = []
    for d in range(D):
        t = T[d] - 1
        score += S[d][t]
        last[t] = d + 1
        for i in range(26):
            score -= C[i]*(d + 1 - last[i])
        ans.append(score)
    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long x,ans;
	cin >> x;
	x;
	ans= x / 11*2;
	//cout << ans << endl;
	x = x % 11;
	if (x <= 6&&x!=0) {
		ans += 1;
	}
	else if(x!=0)
	{
		ans += 2;
	}
	cout <<ans<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(int i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(int i=(a);i<(n);i++)cout<<(arr)[i]<<' ';

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
	fast;
	ll a, b, c;
	cin>>a>>b>>c;
	ll x = min(a, min(b, c));
	ll y = max(a, max(b, c));
	ll z = a+b+c-x-y, ans = 0;
	
	if(y - x>=2){
		ans+=(y-x)/2;
		x+=(ans*2);
	}
	
	if(y-z>=2){
		ll aa = 0;
		aa+=(y-z)/2;
		z+=(aa*2);
		ans+=aa;
	}
	
	if((y!=x && y == z) || (y==x && y!=z)){
		ans+=2;
	}
	if(y!=x && y!=z)ans++;
	
	cout<<ans<<endl;

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
string s;
int ind;
char let(){
  if(s[ind]=='+'){
    ++ind;
    char tmp=let();
    if(tmp=='?') return '?';
    else if(tmp=='Z') return 'A';
    else return ++tmp;
  }else if(s[ind]=='-'){
    ++ind;
    char tmp=let();
    if(tmp=='?') return '?';
    else if(tmp=='A') return 'Z';
    else return --tmp;
  }else{
    char tmp=s[ind];
    ++ind;
    return tmp;
  }
}
string cip(){
  string tmp="";
  if(ind>=s.size()||s[ind]==']') return "";
  else if(s[ind]=='['){
    ++ind;
    string rev=(cip());
    ++ind;
    tmp+=string(rev.rbegin(),rev.rend());
  }else{
    char tc=let();
    if(tc=='?') tc='A';
    tmp.push_back(tc);
  }
  return tmp+cip();
}

int main(void)
{
  for(;;){
    cin >> s;
    ind = 0;
    if(s==".") return 0;
    cout << cip() << endl;
  }
}

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

using namespace std;

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

  if( d < a || b < c){
    cout << 0 << endl;
  }else{

    if( a < c){
      s = c;
    }else{
      s = a;
    }

    if( d < b){
      e = d;
    }else{
      e = b;
    }

    cout << e-s << endl;

  }
  
}

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

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, k;
	LinkedList<E>[] es;

	@SuppressWarnings("unchecked")
	void run(){
		for(;;){
			n=sc.nextInt();
			k=sc.nextInt();
			if((n|k)==0){
				break;
			}
			es=new LinkedList[n];
			for(int i=0; i<n; i++){
				es[i]=new LinkedList<E>();
			}
			for(int i=0; i<k; i++){
				if(sc.nextInt()==0){
					int a=sc.nextInt()-1;
					int b=sc.nextInt()-1;
					println(dijkstra(a, b)+"");
				}else{
					int u=sc.nextInt()-1;
					int v=sc.nextInt()-1;
					int w=sc.nextInt();
					es[u].add(new E(v, w));
					es[v].add(new E(u, w));
				}
			}
		}
	}

	int dijkstra(int s, int g){
		int[] d=new int[n];
		PriorityQueue<P> que=new PriorityQueue<P>();
		Arrays.fill(d, INF);
		d[s]=0;
		que.offer(new P(s, 0));
		for(; !que.isEmpty();){
			P p=que.poll();
			if(d[p.v]<p.d){
				continue;
			}
			for(E e : es[p.v]){
				if(d[e.to]>d[p.v]+e.cost){
					d[e.to]=d[p.v]+e.cost;
					que.offer(new P(e.to, d[e.to]));
				}
			}
		}
		return d[g]<INF?d[g]:-1;
	}

	class E{
		int to, cost;

		E(int to, int cost){
			this.to=to;
			this.cost=cost;
		}
	}

	class P implements Comparable<P>{
		int v, d;

		P(int v, int d){
			this.v=v;
			this.d=d;
		}

		@Override
		public int compareTo(P p){
			return d-p.d;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int n;
	cin >> n;
	int a = n % 10;
	if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9) cout << "hon" << endl;
	else if (a == 0 || a == 1 || a == 6 || a == 8) cout << "pon" << endl;
	else cout << "bon" << endl;
}

Measured memory_bytes: 3624
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//
constexpr ll MOD = 1e9 + 7;
/*/
const ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  string s;
  cin >> s;
  string t;
  rep(i, SZ(s)){
    t += (!(i&1) ? 'g' : 'p');
  }
  ll ans = 0;
  rep(i, SZ(s)){
    if(s[i] == 'g' && t[i] == 'p') ans++;
    if(s[i] == 'p' && t[i] == 'g') ans--;
  }
  print(ans);
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

LL n,d,a,x,y,ans,dam;
vector <LL> vv;
vector <pii> v;
vector <vector <LL> > era(200010);

int main()
{
	cin>>n>>d>>a;
	rep(i,n)
	{
		cin>>x>>y;
		v.pb(mpr(x,y));
	}
	sort(v.begin(),v.end());
	rep(i,n) vv.pb(v[i].fi);
	ans=(v[0].se+a-1)/a;
	LL pos=v[0].fi+d*2,pos2=upper_bound(vv.begin(),vv.end(),pos)-vv.begin();
	era[pos2].pb(ans*a);
	dam=ans*a;
	repn(i,n-1)
	{
		rep(j,era[i].size()) dam-=era[i][j];
		v[i].se=max(0LL,v[i].se-dam);
		LL tmp=(v[i].se+a-1)/a;
		pos=v[i].fi+d*2;
		pos2=upper_bound(vv.begin(),vv.end(),pos)-vv.begin();
		era[pos2].pb(tmp*a);
		ans+=tmp;
		dam+=tmp*a;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15852
N = int(input())
R = [list(map(int,input().split())) for k in range(N)]
B = [list(map(int,input().split())) for k in range(N)]

R = sorted(R, key = lambda x: -1*x[1])
B = sorted(B)

ans = 0
for b in B:
    for r in R:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            R.remove(r)
            break

print(ans)


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

	else if(a<b){
		if(a<c){
			if(b<c) printf("%d %d %d\n",a,b,c);
			else printf("%d %d %d\n",a,c,b);
		}if(c<a){
			printf("%d %d %d\n",c,a,b);
		}
	}else if(b<a){
		if(a<c){
			printf("%d %d %d\n",b,a,c);
		}if(c<a){
			if(b<c) printf("%d %d %d\n",b,c,a);
			else printf("%d %d %d\n",c,b,a);
		}
	}

	return 0;
}


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

int main()
{
	int N, M, temp;
	while (cin >> N >> M, N || M) {
		vector<int> h, w, dis;
		h.reserve(N);
		w.reserve(M);
		dis.reserve(N * (N - 1) / 2);
		h.push_back(0);
		w.push_back(0);
		for (int i = 1; i <= N; i++) {
			cin >> temp;
			h.push_back(h[i - 1] + temp);
		}
		for (int i = 1; i <= M; i++) {
			cin >> temp;
			w.push_back(w[i - 1] + temp);
		}
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j <= N; j++) {
				dis.push_back(h[j] - h[i]);
			}
		}
		sort(dis.begin(), dis.end());
		int res = 0;;
		for (int i = 0; i < M; i++) {
			for (int j = i + 1; j <= M; j++) {
				auto p = equal_range(dis.begin(), dis.end(), w[j] - w[i]);
				res += distance(p.first, p.second);
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 11908
s = input()
if s[0] == s[1] == s[2] == s[3]:
  print("No")
elif s[0] == s[1] and s[2] == s[3]:
  print("Yes")
elif s[0] == s[2] and s[1] == s[3]:
  print("Yes")
elif s[0] == s[3] and s[1] == s[2]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);

	ll a;
	string b;
	cin >> a >> b;

	string s;
	for(int i = 0; i < b.size(); i++){
		if(b[i] == '.')continue;
		s.push_back(b[i]);
	}

	int number = atoi(s.c_str());

	cout << a * number / 100 << endl;

	return 0;
}

Measured memory_bytes: 3588
use std::io::stdin;
#[allow(unused)]
use std::vec::Vec;
#[allow(unused)]
use std::f64;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let a:f64 = r.reads();
    let b:f64 = r.reads();
    let x:f64 = r.readl();
    let pi = f64::consts::PI;

    if a * a * b / 2_f64 > x{
        let tan:f64 = a * b * b / (2_f64 * x);
        println!("{}",(tan.atan() / pi) * 180_f64);
    }else{
        let tan:f64 = (2_f64 * a * a * b - 2_f64 * x) / (a * a * a);
        println!("{}",(tan.atan() / pi) * 180_f64);
    }
}


Measured memory_bytes: 4352
start = int(input())

def calc(x):
  if x %2 ==0:
    Answer = x /2
  else:
    Answer = 3*x+1
  return Answer
counter = 1
number = 0
Answer_list = [start]
while number < 1:
  if calc(start) in Answer_list:
    Answer_list.append(calc(start))
    number = counter+1
    print(number)
  else:
    start = calc(start)
    Answer_list.append(start) 
    counter +=1

Measured memory_bytes: 3060
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main(){

    int a,b,c,d,e,k;cin >> a>>b>>c>>d>>e>>k;
    
    if(e-a>k){
        cout << ":("<<endl;
    }else{
        cout << "Yay!"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
A = []
B = []
ans = [True] * N
for i in range(M):
    a, b = list(map(int, input().split()))
    if H[a-1] <= H[b-1]:
        ans[a-1] = False
    if H[a-1] >= H[b-1]:
        ans[b-1] = False

print(ans.count(True))



Measured memory_bytes: 20068