akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	ll H, W, K;
	cin >> H >> W >> K;
	vector<string> vec(H);
	rep(i, H) cin >> vec[i];

	vector<vector<ll>> ans(H, vector<ll>(W,0));

	vector<bool> rows(H,false);
	rep(i, H) rep(j, W) {
		if (vec[i][j] == '#') rows[i] = true;
	}
	
	ll num = 1;
	rep(i, H) {
		if (rows[i] == false) {
			rep(j, W) {
				if (i != 0 && ans[i - 1][j] != 0) ans[i][j] = ans[i - 1][j];
			}
		}
		else {
			ll same = 1;
			rep(j, W) {
				if (vec[i][j] == '.') ans[i][j] = num;
				else {
					if (same == 1) { ans[i][j] = num; same = 0; }
					else { num++; ans[i][j] = num; }
				}
			}
			num++;
		}
		
	}
	
	for (ll i = H - 1; i >= 0; i--) {
		if (rows[i] == true) continue;
		rep(j, W) {
			if (ans[i][j] == 0) ans[i][j] = ans[i + 1][j];
		}
	}
	
	rep(i, H) {
		
		rep(j, W) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
		
	}
	
}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 1664
# N, Y = list(map(int, input().split()))
# 
# xx, yy, zz = -1,-1,-1
# 
# flag = False
# for x in range(min(Y//10000, N)+1):
#     for y in range(min((Y-x*10000)//5000, N)+1):
#         z = N-x-y
#         if x*10000+y*5000+z*1000 == Y:
#             xx = x
#             yy = y
#             zz = z
#             flag = True
#             break
#     if flag:
#         break
# print(xx, yy, zz)

n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if i*10000+j*5000+(n-i-j)*1000 == y:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    S = readstr()
    if S == 'RRR':
        print(3)
    elif 'RR' in S:
        print(2)
    elif 'R' in S:
        print(1)
    else:
        print(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9032
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<vvvi> vvvvi;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(b, n*a) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define For(i,a,b) for(int i=a;i>=b;i--)
#define Maxn 1002

using namespace std;

int read(){
    char c=getchar(); int flag=1, x=0;
    while(!isdigit(c)){ if(c=='-') flag=-1; c=getchar(); }
    while( isdigit(c)){ x=x*10+(c-'0'); c=getchar(); }
    return flag*x;
}

int num[Maxn+10];

signed main(){

    memset(num,0x3f,sizeof(num));
    
    int n=read();
    FOR(i,1,n-1){
        int a=read();
        num[i]=min(num[i],a);
        num[i+1]=min(num[i+1],a);
    }

    int Ans=0;
    FOR(i,1,n) Ans+=num[i];
    cout<<Ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

int main() {
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	REP(i, n) {
		cin >> x[i] >> y[i];
	}
	int res = n;
	int dif = 0;
	REP(i, n) {
		REP(j, n) {
			if (i != j) {
				int p = x[i] - x[j];
				int q = y[i] - y[j];
				int cnt = 0;
				REP(k, n) {
					REP(l, n) {
						if (x[k] - x[l] == p && y[k] - y[l] == q) {
							cnt++;
						}
					}
				}
				chmax(dif, cnt);
			}
		}
	}
	put(res - dif);
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
hoge=[]
for i in range(m):
  huga=list(map(int,input().split()))
  huga=huga[1:]
  hoge.append(huga)
moge=list(map(int,input().split()))
ans=0
for i in range(2**n):
  hi=0
  light=format(i, '010b')
  #ランプにjこめついて
  for j in range(m):
    kei=0
    #ボタンkこめについて
    for k in range(n):
      #print(light[-(k+1)],hoge[j].count(k+1))
      if(light[-(k+1)]=="1" and hoge[j].count(k+1)>0):
        kei+=1
    if(kei%2==moge[j]):
      hi+=1
  if(hi==m):
    ans+=1
    
print(ans)

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

using namespace std;
using ll = long long;

int main()
{
    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    while(1 + ans * (A - 1) < B) {
        ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	string s;
	cin >> s;
	cout << s.substr(0, s.size() - 8) << endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
typedef long long ll;

int main(){
    ll M; cin >> M;
    vector<ll> d(M), c(M);
    rep(i, 0, M) cin >> d[i] >> c[i];

    ll sum = 0;
    ll ans = 0;
    rep(i, 0, M) ans += c[i];
    rep(i, 0, M){
        sum += d[i] * c[i];
    }
    if(sum % 9 == 0) ans--;
    cout << ans - 1 + sum / 9 << endl;
}

Measured memory_bytes: 3328
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    S = input()

    return N, S


def main(N: int, S: str) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 桁数(4 <= N <= 30000)
        S (str): ラッキーナンバー(半角数字からなる長さNの文字列)
    """
    # 求解処理
    ans = 0
    S_i_list = []
    for i in range(N - 2):
        S_i = S[i]
        if S_i in S_i_list:
            continue
        S_j_list = []
        for j in range(i + 1, N - 1):
            S_j = S[j]
            if S_j in S_j_list:
                continue
            ans += len(set(S[j + 1: N]))
            S_j_list.append(S_j)
        S_i_list.append(S_i)

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, S = get_input()

    # メイン処理
    main(N, S)


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


#define fi first
#define se second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define el '\n'

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

const int N = 2e5 + 10;

int q;
int n;
vector<ll> le[N], ri[N];

ll dp1[N], dp2[N];

void init(){
    fill(dp1, dp1 + n + 3, 0);
    fill(dp2, dp2 + n + 3, 0);
    for (int i=0;i<=n + 1;i++){
        le[i].clear();
        ri[i].clear();
    }
}

void init_dp(){
    // dp1 aka left, dp2 aka right
    priority_queue<ll> setdah;
    for (int i=n;i>=1;i--){
        for (auto x : le[i]) setdah.push(x);
        if (!setdah.empty()){
            dp1[i] = setdah.top();
            setdah.pop();
        }
    }
    while (!setdah.empty()) setdah.pop();
    for (int i=1;i<=n;i++){
        for (auto x : ri[i]) setdah.push(x);
        if (!setdah.empty()){
            dp2[i] = setdah.top();
            setdah.pop();
        }
    }
    int last = 1;
    for (int i=1;i<=n;i++){
        last = max(last, i);
        if (dp1[i] == 0){
            while (last < n && dp1[last] == 0) last++;
            if (dp1[last]) swap(dp1[i], dp1[last]);
        }
    }
    last = n;
    for (int i=n;i>=1;i--){
        last = min(last, i);
        if (dp2[i] == 0){
            while (last > 1 && dp2[last] == 0) last--;
            if (dp2[last]) swap(dp2[i], dp2[last]);
        }
    }

    ll tot = 0;
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    for (int i=1;i<=n;i++){
        tot += dp1[i];
        pq.push(dp1[i]);
    }
    for (int i=n;i>=1;i--){
        dp1[i] = tot;
        tot -= pq.top();
        pq.pop();
    }
    tot = 0;
    for (int i=1;i<=n;i++){
        tot += dp2[i];
        pq.push(dp2[i]);
    }
    for (int i=1;i<=n;i++){
        dp2[i] = tot;
        tot -= pq.top();
        pq.pop();
    }
}

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

    cin >> q;
    while (q--){
        cin >> n;

        init();
        ll base = 0;
        for (int i=1;i<=n;i++){
            ll k, l, r;
            cin >> k >> l >> r;

            if (l > r){
                le[k].pb(l - r);
            } else{
                ri[k + 1].pb(r - l);
            }
            base += min(l, r);
        }
        init_dp();
        ll tot = 0;
        for (int i=0;i<=n;i++){
            // cout << dp1[i] << " " << dp2[i] << el;
            tot = max(tot, dp1[i] + dp2[i + 1]);
        }
        cout << base + tot << el;
    }

    return 0;
}

Measured memory_bytes: 22424
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    println!("{}", &s.chars().filter(|&c| c == '1').count());
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int X,A,B;
  cin >> X >> A >> B;
  if(B<=A)
    cout << "delicious" << endl;
  else if((A+X)>=B)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#define MOD 10000
#define INF 1000000000
#define MAX 101
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
int main() {
    int ans=0;
    string s;
    cin>>s;
    bool f=true;
    for(int i=0;i<s.length();i++){
        if(i==0){
            ans+=s[i]-'0'-1;
        }else{
            ans+=9;
        }
        if(i==0||s[i]=='9'){
            f=true;
        }else{
            f=false;
        }
    }
    if(f){
        ans++;
    }
    cout<<ans<<endl;
}
                           

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
typedef long long ll;

int main(){

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	int i, j, k, l, m, n, len;
	int A, B, C;
	char S[3];


	scanf("%s", S);

	len = strlen(S);
	if (S[0] == '7' || S[1] == '7' || S[2] == '7'){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;

}
    


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

int main() {
  int N; cin >>N;
  int ma=0;
  map<string,int> cnt;
  for (int i=0; i<N; i++){
    string s;
    cin >>s;
    cnt[s]++;
    //cout <<s <<":" <<cnt[s] <<endl;
    ma=max(ma,cnt[s]);
  }
  //cout <<ma <<endl;;
  vector<string> ans;
  for(auto i:cnt){
    int num = i.second;
    if (num == ma){
      ans.push_back(i.first);
    }
  }
  sort(ans.begin(),ans.end());
  for (auto i:ans){
    cout <<i <<endl;
  }
}


Measured memory_bytes: 26868
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main(){
	string a, b;
	cin >> a >> b;
	REP(i, 3) {
		if (a[i] != b[2 - i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using ll=long long;
using namespace std;
int main(){
    ll h;
    cin>>h;
    ll tmp=h;
    ll count=1;
    while(tmp>1){
        tmp/=2;
        count++;
    }
    ll ans=0;
    for(ll i=0;i<count;i++){
        ans+=pow(2,i);
    }
    cout<<ans<<endl;
} 

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

//?????????????????°????????????
int getChar(char ch)
{
    if( ch == 'A' ) return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

//?????????????????°??????????????????key???????????????
long long getKey(char str[])
{
    long long sum = 0, p = 1, i;
    for( i = 0; i < strlen(str); i++ ){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int Key){ return Key % M; }
int h2(int Key){return 1 + (Key % (M - 1));}

int find(char str[])
{
    long long key, i, h;
    key = getKey(str);
    for( i = 0; ; i++ ){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0) return 1;
        else if( strlen(H[h]) == 0 ) return 0;
    }
    return 0;
}

int insert(char str[])
{
    long long key, i, h;
    key = getKey(str);
    for( i = 0; ; i++ ){
        h = (h1(key) + i * h2(key)) % M;
        if( strcmp(H[h], str) == 0 ) return 1;
        else if (strlen(H[h]) == 0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main()
{
    int i, n, h;
    char str[L], com[9];
    for( i = 0; i < M; i++ ) H[i][0] = '\0';
    scanf("%d", &n);
    for( i = 0; i < n; i++ ){
        scanf("%s %s", com, str); //?????????????????\???scanf????????¨

        if( com[0] == 'i' ){
            insert(str);
        }else{
            if( find(str) ){
                puts("yes");
            }else{
                puts("no");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 16072
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;







int main(){
    string s;
    cin>>s;
    ll ans=0;
    for(int i=0;i<s.size();i++){
        if(i%2==1 && s[i]=='g'){ans++;}
        if(i%2==0 && s[i]=='p'){ans--;}
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int ans = 0;
		if (A < B) {
			ans = B;
			B -= 1;
		} else {
			ans = A;
			A -= 1;
		}
		ans += Math.max(A, B);
		System.out.println(ans);
		scanner.close();
	}
}

Measured memory_bytes: 21844
import sys
input=sys.stdin.readline

def f(n,W):
    wv = [list(map(int, input().split())) for _ in range(n)]
    dp = [-1] * (W + 1)
    dp[0] = 0
    for w, v in wv:
        for i in range(W - w, -1, -1):
            if dp[i] == -1: continue
            nv = dp[i] + v
            if nv > dp[i + w]:
                dp[i + w] = nv
    print(max(dp))

n,W=map(int,input().split())
f(n,W)


Measured memory_bytes: 7664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <inttypes.h>

//int compare_int(const void *a, const void *b){//qsort 整数比較<
//	return *(int*)a - *(int*)b;
//}
//int compare_int2(const void *a, const void *b){//qsort 整数比較>
//	return *(int*)b - *(int*)a;
//}
//

//long long int combination(int n, int r)
//{
//	if (r == 0 || r == n)
//		return (1);
//	else if (r == 1)
//		return (n);
//	return (combination(n - 1, r - 1) + combination(n - 1, r));
//}

int main(void){
	int n;
	int d1[110]={0};
	int d2[110]={0};
	int i;
	int count=0;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&d1[i],&d2[i]);
		if(d1[i]==d2[i]){
			count++;
		}else{
			count=0;
		}
		if(count==3){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define ll long long 
#define N 200005
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define piii pair<int, pii>
#define print(x) cout << #x << "=" << x << "\t";
#define endl "\n"
#define newline cout << endl;

int n;
int a[20][20];
ll pre[1<<16];
ll dp[1<<16];

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); 
    cin >> n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin >> a[i][j];

    int lim = (1 << n);
    for(int i=1;i<lim;i++) {
        int p = i;
        vector<int> v;
        while (p) {
            v.push_back(__builtin_ctz(p));
            p -= p&-p;
        }
        for(int j=0;j<(int)v.size();j++)
            for(int j2=j+1;j2<(int)v.size();j2++)
                pre[i] += a[v[j]][v[j2]];
    }

    memset(dp, 0xaf, sizeof(dp));
    dp[0] = 0;
    for(int i=1;i<lim;i++)
        for(int x=i;x>0;x=((x - 1)&i))
            dp[i] = max(dp[i], dp[i - x] + pre[x]);
    
    cout << dp[lim - 1];
    return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
//*********************************************************
ll gcd(ll a, ll b)
{
	ll tmp, r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
int main(int argc, char* argv[]) {
	ll k, answer = 0;
	cin >> k;
	for (int a = 1; a <= k; a++)
	{
		for (int b = 1; b <= k; b++)
		{
			ll tmp = gcd(a, b);
			for (int c = 1; c <= k; c++)
			{
				answer += gcd(tmp, c);
			}
		}
	}
	cout << answer << endl;
	return 0;
}

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

int main(){
  int i,N,count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    int n,j,l=0;
    scanf("%d",&n);
    if(n==1||n==2){
      count++;
      continue;
    }
    if(n%2==0){
      continue;
    }
    for(j=3;j<=sqrt(n);j+=2){
      if(n%j==0){
        l+=1;
        break;
      }
    }
    if(l!=1){
      count++;
    }
    l=0;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1812
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  ll n = s.size(), ans = 0;
  for(int i=0;i<(1<<(n-1));i++){
    string t = "";
    ll tmp = 0;
    for(int j=0;j<n;j++){
      t+=s[j];
      if(((i>>(n-j-2))&1)||j==n-1){
        tmp += stoll(t);
        t = "";
      };
    }
    //std::cout << i << " " << tmp << '\n';
    ans += tmp;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 632
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int a,b,k;cin >> a >> b >> k;
    for(int i = 0; i < k; i++){
        if(a%2 != 0) a = a -1;
        b += a/2;
        a = a/2;
       // cout << a << " " << b << endl;
        i++;
        if(i == k)break;
        if(b%2 != 0) b = b -1;
        a = a + b/2;
        b = b/2;
        //cout << a << endl;
    }
    cout << a <<  " " << b << endl;
        
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int N,M,R;
    cin >> N >> M >> R;

    vector<int> r(R);
    rep(i,0,R){
        cin >> r[i];
        --r[i];
    }
    sort(r.begin(),r.end());

    vector<vector<i64>> dist(N,vector<i64>(N,inf64));
    rep(i,0,N) dist[i][i]=0;
    rep(i,0,M){
        int A,B;
        i64 C;
        cin >> A >> B >> C;
        --A;
        --B;
        dist[A][B]=dist[B][A]=min(dist[A][B],C);
    }

    rep(k,0,N) rep(i,0,N) rep(j,0,N) dist[i][j]=dist[j][i]=min(dist[i][j],dist[i][k]+dist[k][j]);

    i64 ans=inf64;
    do{
        i64 s=0;
        rep(i,0,R-1) s+=dist[r[i]][r[i+1]];
        ans=min(ans,s);
    }while(next_permutation(r.begin(),r.end()));

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main(int argc, char const *argv[]) {
    int N;
    cin >> N;

    switch (N%10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
    }


    return 0;
}


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


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

    int rest = n % 500;

    string answer;
    if (rest <= a) {
        answer = "Yes";
    } else {
        answer = "No";
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s.size()&1){puts("No");return 0;}
    for(int i=0;i<s.size();i+=2) if(s[i]!='h'||s[i+1]!='i'){puts("No");return 0;}
    puts("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}


int main(){
    fast();
    char x;
    cin >> x;
    cout << (char)(x-'a'+1+'a') << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
//input
string S;


//processing
int A,B;


//dpTable
//int dp[100050];

int main(){
    cin >> S;
    rep (i,S.size()){
        if (i % 2 == 0){
            if (S.at(i) == '1') A++;
        }
        else {
            if (S.at(i) == '0') A++;
        }
    }
    rep (i,S.size()){
        if (i % 2 == 0){
            if (S.at(i) == '0') B++;
        }
        else {
            if (S.at(i) == '1') B++;
        }
    }
    cout << min(A,B) << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;

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


int main() {
    ll X;
    cin >> X;
    ll ans=0;

    if(X == 1){
        cout << 1 << endl;
        return 0;
    }

    for(ll i=2;i<=X;i++){
        ll result=i*i;
        if(result > X){
            break;
        }
        while(result <= X){
            result *= i;
        }
        result /= i;
        // cout << result << endl;
        ans = max(ans,result);
    }

    cout << ans << endl;
}




Measured memory_bytes: 3552
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

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

	int n, k;
	cin >> n >> k;
	int ans = 0;
	rep(i, n) {
		int h;
		cin >> h;
		if (h >= k) ++ans;
	}

	cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
struct axis
{
    double x,y;

};
double area(axis a,axis b,axis c)
{
    double are=(a.x* (b.y-c.y)-a.y*(b.x-c.x)+(b.x * c.y- c.x * b.y))/2;
    return abs(are);
}
int main()
{
    axis a,b,c,x;
    while(cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>x.x>>x.y)
    {

        double areatot=area(a,b,c),areaa=area(a,b,x),areab=area(b,c,x),areac=area(c,a,x);
        if(areatot==(areaa+areab+areac))
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;


    }


    return 0;
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int n , a[ N ] , b[ N ];

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        cin >> n;
        LL ans = 0;
        for( int i = 1; i <= n + 1; i++ ) cin >> a[i];
        for( int i = 1; i <= n; i++ ) cin >> b[i];
        for( int i = 1; i <= n; i++ ) {
                ans += min( a[i] , b[i] );
                b[i] -= min( a[i] , b[i] );
                ans += min( a[i+1] , b[i] );
                a[i+1] -= min( a[i+1] , b[i] );
        }
        cout << ans << endl;
        return 0;
}





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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	int n;
	cin >> n;

	vi a(n);
	rep(i,n){
		cin >> a[i];
	}
	
	int money = 1000;
	int kabu = 0;

	bool isDown = true;
	bool isChange = false;
	if(a[0] < a[1]) isDown = false;
	if(!isDown){
		kabu = money / a[0];
		money -= (money / a[0]) * a[0];
	}
	rep(i,n-1){
		if(a[i] < a[i+1]){
			if(isDown) isChange = true;
			else isChange = false;
			isDown = false;
		}
		else if(a[i] > a[i+1]){
			if(!isDown) isChange = true;
			else isChange = false;
			isDown = true;
		}
		else{
			continue;
		}

		if(isChange){
			if(isDown){
				money += kabu * a[i];
				kabu = 0;
			}
			else{
				kabu = money / a[i];
				money -= (money / a[i]) * a[i];
			}
		}
	}

	if(kabu != 0){
		money += kabu * a[n-1];
	}
	cout << money << endl;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3556
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    a, b, c = [int(x) for x in input().split()]
    dic = set()
    dic.add(a)
    dic.add(b)
    dic.add(c)
    if len(dic) == 2:
        return 'Yes'
    return 'No'


if __name__ == "__main__":
    print(main())

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

#define vi vector<int>
#define vvi vector<vi>

const int INF = 1e9 + 5;

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

    int n;
    cin >> n;

    if(n % 10 == 2 || n%10 == 4||n%10 == 5 || n % 10 == 7 || n % 10 == 9){
        cout << "hon";
    }else if(n % 10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8){
        cout << "pon";
    }else if(n%10 == 3){
        cout << "bon";
    }


    return 0;
}

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

#define unsigned int
#define int long long

int32_t main() 
{ 
    int n;
    cin>>n;
    vector<int> a;
    for(int i = 0; i < n; i++)
    {
        int w;
        cin>>w;
        a.push_back(w);
    }
    sort(a.begin(), a.end(), greater<int>());
    int sum = a[0];
    vector<int> ans;
    for(int i = 1; i < n; i++)
    {
        ans.push_back(a[i]);
        ans.push_back(a[i]);
    }
    for(int i = 0; i < n-2; i++)
    {
        sum += ans[i];
    }
    cout<<sum<<endl;
} 

Measured memory_bytes: 8996
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod=1e9;
static const ll INF=1LL<<50;
using namespace std;

int main() {
	int n,k;
  	cin>>n>>k;
  	string s;
  	cin>>s;
  	s[k-1]=s[k-1]+32;
  	cout<<s<<endl;return 0;
}

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

int main(){
    int a1, b1, a2, b2, a3, b3;
    cin >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;

    int adj[5] = {0};
    ++adj[a1];
    ++adj[b1];
    ++adj[a2];
    ++adj[b2];
    ++adj[a3];
    ++adj[b3];

    int cnt = 0;
    for(int i = 1; i < 5; ++i){
        if(adj[i]&1){
            ++cnt;
        }
    }

    if(cnt != 2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int arr[MAX], cnt[MAX];

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

    int n;

    cin>>n;

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

    ll sum = 0;
    for(int i = 1; i <= n; i++){
        ll k = (ll) cnt[i];
        if(k > 0){
            sum += 1LL * (k * (k - 1)) >> 1;
        }
    }

    ll tsum = sum;
    for(int i = 0; i < n; i++){
        ll k = (ll) cnt[arr[i]];
        sum -= (1LL * k * (k - 1)) >> 1;
        k--;
        sum += 1LL * (k * (k - 1)) >> 1;
        cout<<sum<<endl;
        sum = tsum;
    }


    return 0;
}


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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    int n;
    ll d;
    cin>>n>>d;
    ll x,y;
    int ans=0;
    while(n--){
        cin>>x>>y;
        if(ceil(sqrt(x*x+y*y))<=d)ans++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3656
N = int(input())
P = list(map(int,input().split()))
count = 1
 
if N > 0:
  min = P[0]
  
for i in range(1, N):
  isbreak = False
  
  if min < P[i]:
    continue
  elif min >= P[i]:
    min = P[i]
    count += 1
    continue  
  for j in range(0,i):
    if (P[i] > P[j]):
      isbreak = True
      break
  if isbreak == False:
    count += 1
    
print(count)

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


#define rep(i,r,l) for(int i = r; i < l; i++)
#define elif else if
#define ll long long

int nextint(void){int n;scanf("%d",&n);return n;}
void printint(int d){printf("%d\n",d);}


int main(void){ 

    
    int n,x,t;
    scanf("%d %d %d",&n,&x,&t);
    printf("%d",t*(n/x)+((n%x==0)?0:t));
    
    
    return 0;
}



Measured memory_bytes: 1732
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
//const ll INFL = 1LL << 60;//10^18 = 2^60
const ll INFL = 1LL << 60;
const int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll dp[200010][3];

int main(void){
  string S;
  cin >> S;
  if(S.size() == 1){
    cout << 1 << endl;
    return 0;
  }
  if(S.size() == 2){
    if(S[0] == S[1]){
      cout << 1 << endl;
      return 0;
    }else{
      cout << 2 << endl;
      return 0;
    }
  }

  rep(i, 200010)rep(j, 3) dp[i][j] = -INFL;
  dp[1][1] = 1;
  if(S[0] == S[1]){
    dp[2][2] = 1;
  }else{
    dp[2][1] = 2;
    dp[2][2] = 1;
  }
  for(int i = 3; i <= S.size(); i++){
    dp[i][1] = max(dp[i][1], dp[i-1][2] + 1);
    if(S[i-1] != S[i-2]){
      dp[i][1] = max(dp[i][1], dp[i-1][1] + 1);
    }
    dp[i][2] = max(dp[i][2], dp[i-2][1] + 1);
    if(i-4 >= 0 && S[i-2] + S[i-1] != S[i-4] + S[i-3]){
      dp[i][2] = max(dp[i][2], dp[i-2][2] + 1);
    }
  }
  
  cout << max(dp[S.size()][1], dp[S.size()][2]) << endl;

}


Measured memory_bytes: 6660
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define v vector<ll>
#define vv vector<v>
ll MOD=1e9+7;
int main() 
{ 
	int n;
	cin>>n;
	v h(n+1,0),dp(n+1,1e9);
	dp[1]=0;
	cin>>h[1];
	for (int i=2; i<=n; i++)
	{
		cin>>h[i];
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n];
    return 0;
} 

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		
		long[] T = new long[5];
		
		for(int i = 0; i < 5; i++) {
			T[i] = sc.nextLong();
		}
		
		Arrays.sort(T);
		long min = T[0];
		
		long t = 4;
		
		if(N <= min) {
			t += 1;
		} else {
			if(N % min != 0) {
				t += N / min + 1;
			} else {
				t += N / min;
			}
		}
		System.out.println(t);
	}
}


Measured memory_bytes: 23252
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
using namespace std;

int N,M;
int x,l;
pair<int,int> itv[100005];

int main()
{
 scanf("%d %d",&N,&M);
 for(int i=0;i<M;i++)
 {
	scanf("%d %d",&itv[i].second,&itv[i].first); //secondがa firstがbであることに注意
 }
 //bでソートして(b-1)-(b)橋を壊す
 sort(itv,itv+M);
int ans=0,brk=-1;
 for(int i=0;i<M;i++)
 {
	if(brk<itv[i].second){brk=itv[i].first-1; ans++;}
 }
 printf("%d",ans);

}

Measured memory_bytes: 4540
#                         author:  kagemeka 
#                         created: 2019-11-06 21:30:22(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    a, b = (int(x) for x in sys.stdin.read().split())

    count = 0
    for n in range(a, b+1):
        n = str(n)
        if n == n[::-1]:
            count += 1

    print(count)       

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940