akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;

int main() {
    cin >> n >> m;
    cout << (n + m + 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N;cin >> N;
    vector<LL> dp(20000000);
    dp[1] = 1;
    for(int i = 2;i <= N;i++){
        dp[i] = dp[i-1] + i;
    }

    vector<int> ans;
    for(int i = 1;i <= N;i++){
        if(N <= dp[i]){
            int tmp = N;
            bool ok = false;
            for(int j = i;j >= 1;j--){
                if(tmp - j == 0){
                    ans.push_back(j);
                    ok = true;
                    break;
                }
                else if(tmp - j > 0){
                    ans.push_back(j);
                    tmp -= j;
                }
            }
            if(ok)break;
        }
    }
    sort(all(ans));

    for(auto t : ans){
        cout << t << endl;
    }
}

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

/* define*/
#define Yes(X) puts ( X ? "Yes" : "No")
#define YES(X) puts ( X ? "YES" : "NO")
#define FOR(i, a, b) for ( i = a; i < b ; i++)
#define REP(i, n) for ( i = 0; i < n ; i++)
#define DER(i, n) for ( i = n; n ; i--)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1e9 + 7;

/* alias */
typedef long long ll;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}

/* main */
int i, j, k;

int main() {
	int n, c = 0;
	char s;
	scanf("%d%*c", &n);
	REP(i, n) {
		scanf("%c", &s);
		if (s == 'R')c++;
		else c--;
	}
	Yes(c > 0);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w;
int n;
int a[10001];
int res[101][101];

int main(void){
	scanf("%d%d",&h,&w);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int nh=0,nw=0,flag=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<a[i];j++){
			res[nh][nw]=i+1;
			if(flag==0)nw++;
			else nw--;
			if(nw==-1){
				nw=0;
				nh++;
				flag=0;
			}
			if(nw==w){
				nw=w-1;
				nh++;
				flag=1;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%d%c",res[i][j],j+1==w?'\n':' ');
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#define ll long long

using namespace std;

int main() {
    ll x;
    ll result = 0;

    cin >> x;

    int a = x / 500;
    result += a * 1000;
    x -= 500 * a;

    result += x / 5 * 5;

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

///////////////////////////


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

    ll a[26] = {};

    ll ans = 1;

    rep(i, S.size()) {
        ans += i - a[S[i] - 'a'];
        a[S[i] - 'a']++;
    }

    cout << ans;
	system("PAUSE");
}

Measured memory_bytes: 764
n = int(input())

m = 0
a = 0
r = 0
c = 0
h = 0

for i in range(n):
  s = input()
  f = s[0]
  if f == 'M':
    m += 1
  elif f == 'A':
    a += 1
  elif f == 'R':
    r += 1
  elif f == 'C':
    c += 1
  elif f == 'H':
    h += 1

print(m * a * (r + c + h) + m * r * (c + h) + m * c * h + a * r * (c + h) + a * c * h + r * c * h)


Measured memory_bytes: 3064
run (function * (write, gets) {
	var counts = [0, 0, 0, 0, 0];

	var n = parseInt(yield, 10);
	for (var i=0; i<n; ++i) {
		var name = yield;
		switch (name[0]) {
			case 'M': ++counts[0]; break;
			case 'A': ++counts[1]; break;
			case 'R': ++counts[2]; break;
			case 'C': ++counts[3]; break;
			case 'H': ++counts[4]; break;
			default: break;
		}
	}

	var ans = 0;
	for (var i=0; i<5; ++i)
	for (var j=i+1; j<5; ++j)
	for (var k=j+1; k<5; ++k) {
		ans += counts[i] * counts[j] * counts[k];
	}

	write(ans);
});

/**
 * @param {(write: (line: string, end?: string) => void, gets: () => IterableIterator<string|null>) => IterableIterator<any>} main 
 */
function run (main) {
	var istream = process.stdin;
	var ostream = process.stdout;

	/**
	 * @type {[string|null]}
	 */
	var words = [];
	/**
	 * @type {[string]}
	 */
	var lines = [];
	var rest = "";
	var ended = false;
	var INPUT_MODE_LINE = 0;
	var INPUT_MODE_WORD = 1;
	var input_mode = INPUT_MODE_WORD;

	/**
	 * @param {string} line 
	 * @param {string} [end] 
	 */
	function write (line, end) {
		ostream.write(line + (undefined === end ? os.EOL : end));
	}
	function *gets () {
		if (0 < lines.length) {
			return lines.shift();
		} else {
			input_mode = INPUT_MODE_LINE;
			/**
			 * @type {string}
			 */
			var line = yield;
			input_mode = INPUT_MODE_WORD;
			return line;
		}
	}

	var main_itr = main(write, gets);

	/**
	 * @param {string|null} chunk 
	 */
	function get_chunk (chunk) {
		istream.pause();
		if (null === chunk) {
			lines.push(null);
		} else {
			rest += chunk;
			var line_exp = /.*(\r?\n|\r)/g;
			var line_match, lastIndex = 0;
			while (null !== (line_match = line_exp.exec(rest))) {
				lastIndex = line_exp.lastIndex;
				lines.push(line_match[0]);
			}
			rest = rest.substring(lastIndex);
		}
		loop();
	}

	function loop () {
		while (0 < lines.length) {
			switch (input_mode) {
				case INPUT_MODE_LINE:
				{
					words.push(lines.shift());
				}
				break;
				case INPUT_MODE_WORD:
				{
					if (null === lines[0]) {
						words.push(lines.shift());
					} else {
						var word_exp = /[^\s]+/g;
						var line_match;
						if (null !== (line_match = word_exp.exec(lines[0]))) {
							words.push(line_match[0]);
							lines[0] = lines[0].substring(word_exp.lastIndex);
						} else {
							lines.shift();
						}
					}
				}
				break;
			}

			while (0 < words.length) {
				var result = main_itr.next(words.shift());
				if (undefined !== result.value) {
					if ('string' === typeof result.value) {
						write(result.value, "");
					} else {
						write(`${result.value}`, "");
					}
				}
				if (result.done) return;
			}
		}

		ended ? setTimeout(get_chunk, 0, null) : process.stdin.resume();
	}
	istream.on('data', get_chunk);
	istream.on('end', function () {
		ended = true;
		get_chunk(null);
	});

	istream.setEncoding('utf8');
	get_chunk(null);
};

var os = require('os');


Measured memory_bytes: 19156
#include<stdio.h>
#include<string.h>
int main(void){
int A,B,C,D,E,N,M,x,y,cou=0,cou2,v[1000000],w[1000000],min_i,en=0;
    char S[20],W[10],s[10],X,Y;
   scanf("%d %c %d",&A,&X,&B);
   if(X=='+'){
       printf("%d",A+B);
   }else{
       printf("%d",A-B);
   }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int n,A[21];

int search(int i, int m)
{
    if(m==0) return 1;
    if(i>=n) return 0;

    int research=search(i+1,m)||search(i+1,m-A[i]);
    return research;
}
int main()
{
    int i,q,M;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++) {
        scanf("%d",&M);
        if(search(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



Measured memory_bytes: 2104
from sys import stdin
import sys

N = int(input())
S = [input() for i in range(N)]

M = int(input())
T = [input() for i in range(M)]

words_count = {}
for i in range(N):
    words_count[S[i]] = words_count.get(S[i], 0) + 1

for i in range(M):
    words_count[T[i]] = words_count.get(T[i], 0) - 1

print(max(0, max(words_count.values())))


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(c>a && a+b>=c){
        cout << c-a;
    }
    else if(a>c){
        cout << "0";
    }
    else{
        cout <<"NA";
    }
    cout << "\n";
    return 0;
}


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

int main()
{
  int n, a, b;
  while (cin >> n >> a >> b) {
    if ((n|a|b) == 0)
      break;

    vector<int> dp(n+1, 0);
    for (int i = 0; i <= n; i += a) {
      if (!dp[i]) {
	for (int j = i; j <= n; j += b)
	  dp[j] = 1;
      }
    }

    cout << count(dp.begin(), dp.end(), 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 4880
from collections import defaultdict as dd
from itertools import permutations as p

def factorize(n):
    d = dd(int)
    for i in range(2, int(n**0.5)+1):
        while n%i==0:
            d[i] += 1
            n //= i
        if not n:
            break
    if n>1:
        d[n] += 1
    return d

N = int(input())
d = dd(int)
for i in range(1, N+1):
    e = factorize(i)
    for i,j in e.items():
        d[i] += j
vl = d.values()

ans = sum(1 for i, j, k in p(vl, 3) if i>=2 and j>=4 and k>=4)//2
ans += sum(1 for i, j in p(vl, 2) if i>=2 and j>=24)
ans += sum(1 for i, j in p(vl, 2) if i>=4 and j>=14)
ans += sum(1 for i in vl if i>=74)
print(ans)

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

int main()
{
	int n;
	cin>>n;
	double a[n],s=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		
	}
	sort(a,a+n);
	for(int i=1;i<n;i++)
	{
		a[i]=(a[i]+a[i-1])/2.0;
	}
	cout<<a[n-1]<<endl;
}

Measured memory_bytes: 256
import java.util.*;

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

		boolean ans = A<C && C<B || B<C && C<A;


		if(ans){
			System.out.println("Yes");
		} else{
			System.out.println("No");
		}


	}


}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, k;
  cin >> n >> k;
  pair<int, int> a[n];
  for(int i=0; i<n; i++)
    cin >> a[i].first >> a[i].second;
  sort(a, a+n);
  for(int i=0; i<n; i++){
    k-=a[i].second;
    if(k<=0){
      cout << a[i].first;
      return 0;
    }
  }
}


Measured memory_bytes: 4380
#include <iostream>
using namespace std;
int include2(int a);

int main(int argc,char** argv){
	int N,count=0,a;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a;
		count += include2(a);
	}
	cout << count << endl;
	return 0;
}

int include2(int a){
	int num=0;
	while(a%2 == 0){
		a /= 2;
		num++;
	}
	return num;
}

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

int main() {
	int candy[3];
	for (int i = 0; i < 3; i++)
		cin >> candy[i];
	sort(candy, candy + 3);
	if (candy[0] + candy[1] == candy[2])
		cout << "Yes\n";
	else
		cout << "No\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

typedef long long ll;
ll n, cnt[100100], p = 998244353;
int main(void) {
	scanf("%lld", &n);
	ll x; scanf("%lld", &x);
	if (x != 0) {
		return !printf("0\n");
	}
	cnt[0] = 1;

	for (ll i = 1; i < n; i++) {
		scanf("%d", &x);
		cnt[x]++;
	}
	
	if (cnt[0] != 1) {
		return !printf("0\n");
	}

	while (cnt[n] == 0) n--;

	ll ans = 1;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < cnt[i + 1]; j++) {
			ans *= cnt[i];
			ans %= p;
		}
	}
	
	printf("%lld\n", ans);
}

Measured memory_bytes: 896
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let mut count = 0;
    for elem in v {
        if elem % 2 == 1 {
            count += 1;
        }
    }
    if count % 2 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	string s,t="yuiophjklnm";
	while(1){
		cin>>s;
		string u="";
		if(s=="#") break;
		rep(i,0,s.size()){
			if(t.find(s[i])!=string::npos) u+='1';
			else u+='0';
		}
		int ans=0;
		rep(i,1,u.size()){
			if(u[i]!=u[i-1]) ans++;
		}
		o(ans);
	}
}

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

int main(){
    int h , n,a;
    cin >> h >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        h -= a;
    }
    if(h <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define lint long long

using namespace std;

int main()
{
  int N,M;
  cin >> N >> M;

  if(N==M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*{{{*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif

#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()

using namespace std;
using ll = long long;
using ld = long double;
template < typename t >
using V = vector< t >;

template< typename t > 
int size(const t& c)
{return c.size();}

void print()
{cout << '\n';}

template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}

template< typename a, typename b >
inline ostream& operator<<(ostream& os, const pair< a, b > p)
{return os << '(' << p.st << ", " << p.nd << ')';}

template< typename t >
void print_range(t a, const t& b)
{while (a != b) cout << (*a++) << ' '; cout << '\n';}

#define flag() __LINE__"| "__PRETTY_FUNCTION__
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
#define dump_range(...) debug(cout<<#__VA_ARGS__": ";print_range(__VA_ARGS__))
/*}}}*/



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

    int n, a, b; cin >> n >> a >> b;

    V< int > tab {a + 1, b + 1, 21};
    V< int > zl {0, 0, 0};

    for (int i = 0; i < n; ++i)
    {
        int v; cin >> v;
        ++zl[upper_bound(all(tab), v) - begin(tab)];
    }

    print(*min_element(all(zl)));
}

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

int f(int a, int b, int s, int k) {
	k -= s - 1;
	return max(0, min({ a, b, k, a + b - k }));
}

int g(int a, int s, int k) {
	k -= s - 1;
	return (0 < k && k <= a ? k : 0);
}

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	y = n + 1 - y;
	int m = (n - x - y) % 2;
	int z = (n - x - y) / 2;
	int X = n - x - z;
	int Y = n - y - z;
	for(int k = 1; k < n; k++) {
		int ans =
			f(x, y, 1, k) +
			f(x, z, 2, k) +
			f(y, z, 2, k) +
			f(X, X, 1 - X, k) + 
			f(Y, Y, 1 - Y, k) +
			g(z, m + 1, k) +
			g(z - 1, 3, k)
		;
		cout << ans << "\n";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e4+100;
int a[maxn];
int main()
{
    int ans=0,n;
    while(cin>>n)
    {
        ans=0;
        for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=0;i<n;i++)
        {
            int t=a[i];
            while(t%2==0)
            {
                ans++;
                t/=2;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main() {
  
  int r=0, g=0, b=0;
  
  cin >> r >> g >> b;
  
  int cul = g*10 + b;
  
  if(cul%4==0) {
    
    cout << "YES" <<endl;
    
  } else {
    
    cout << "NO" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
  int i,j,k;
  int n=0;
  char s[81];
  while(scanf("%s",s)!=-1){
    for(i=0;i<strlen(s);i++){
      if('1'<=s[i]&&s[i]<='9'){
	for(j=i+1;j<strlen(s);j++){
	  if(s[j]<'0'||'9'<s[j])
	    break;
	}
	for(k=0;k<j-i;k++)
	  n+=(s[i+k]-'0')*pow(10,j-i-k-1);
	i=j;
      }
    }
  }
  printf("%d\n",n);
  return 0;
}

Measured memory_bytes: 0
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion

signed main() {
    int n;cin >> n;
    vi v(n);rep(i, n) cin >> v[i];
    int ans = 0;
    rep(i, n) {
        if(v[v[i]-1]==i+1) ans++;
    }
    cout << ans/2 << endl;
    return 0;
}

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

int main() {
  int A,B,ans;
  cin >> A >> B;
  ans = (A + B) / 2 + (A + B) % 2;
  cout << ans << endl;
}


Measured memory_bytes: 3552
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int days = 0;
            switch (sc.next()) {
            case "MON":
                days++;
            case "TUE":
                days++;
            case "WED":
                days++;
            case "THU":
                days++;
            case "FRI":
                days++;
            case "SAT":
                days++;
                break;
            case "SUN":
                days = 7;
            }
            System.out.println(days);
        }
    }
}

Measured memory_bytes: 19796
while True:
    H,W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            if i == 0 or i == H-1:
                print("#" * W)
            else:
                print("{}{}{}".format("#","." * (W-2), "#"))
    
        print()


Measured memory_bytes: 5612
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999;
ll dp[MAX_N];

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> h(n);
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=0;i<MAX_N;i++){
        dp[i]=INF;
    }
    dp[0]=0;
    for(ll i=1;i<=k;i++){
        for(ll j=0;j<i;j++){
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    for(ll i=k+1;i<n;i++){
        for(ll j=i-k;j<i;j++){
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 4992
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
 
 
 
class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
 
    Scanner cin;
 
    void calc()
    {
        cin = new Scanner();
        int A, B;
        A = cin.nextInt();
        B = cin.nextInt();
        int ans = A + B;
        if (ans >= 10) Console.WriteLine("error");
        else Console.WriteLine(ans);
        
    }
}
 
 
 
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
 
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
const int maxn=405;
int n;
long long C[maxn][4];
map<long long,int> mp;
inline long long get(int x) {
    return (C[x][0]<<30)|(C[x][1]<<20)|(C[x][2]<<10)|C[x][3];
}
inline long long get(long long a,long long b,long long c,long long d) {
    return (a<<30)|(b<<20)|(c<<10)|d;
}
inline void update(long long x,int y) {
    for (int i=0;i<4;++i) {
        mp[x]+=y;
        x=((x<<10)|(x>>30))&((1ll<<40)-1);
        //x=(x>>10)|((x&1023)<<30);
    }
}
inline bool check(long long a,long long b,long long c,long long d) {
    if (mp.find(a)==mp.end()) return false;
    if (mp.find(b)==mp.end()) return false;
    if (mp.find(c)==mp.end()) return false;
    if (mp.find(d)==mp.end()) return false;
    return true;
}
int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;++i) {
        for (int j=0;j<4;++j) cin>>C[i][j];
        update(get(i),1);
    }
    long long res=0;
    for (int i=0;i<n;++i) {
        update(get(i),-1);
        for (int j=i+1;j<n;++j) {
            update(get(j),-1);
            for (int k=0;k<4;++k) {
                long long a=get(C[i][1],C[i][0],C[j][(1+k)&3],C[j][(  k)&3]);
                long long b=get(C[i][2],C[i][1],C[j][(  k)&3],C[j][(3+k)&3]);
                long long c=get(C[i][0],C[i][3],C[j][(2+k)&3],C[j][(1+k)&3]);
                long long d=get(C[i][3],C[i][2],C[j][(3+k)&3],C[j][(2+k)&3]);
                if (!check(a,b,c,d)) continue;
                long long c1=mp[a];
                update(a,-1);
                long long c2=mp[b];
                update(b,-1);
                long long c3=mp[c];
                update(c,-1);
                long long c4=mp[d];
                if (c1>0&&c2>0&&c3>0&&c4>0) res+=c1*c2*c3*c4;
                update(a,1);
                update(b,1);
                update(c,1);
            }
            update(get(j),1);
        }
        update(get(i),1);
    }
    cout<<res/3<<endl;
    return 0;
}


Measured memory_bytes: 3748
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (a, b) = readListOfInt()

    println(if(a+b >= 10) "error" else a+b)
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }


// Extensions
fun<T> List<T>.toBuckets(bucketKeys: List<T>): Map<T, Int> {
    val buckets = bucketKeys.associate { t -> Pair(t, 0) }.toMutableMap()
    this.forEach { t ->
        buckets[t] = buckets[t]!! + 1
    }
    return buckets
}

fun <K, V> Map<K, V>.toMutableMap(): MutableMap<K, V> = HashMap(this)

// Util Functions
fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun Double.isDecimal(): Boolean = ((this - Math.floor(this)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 37808
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

ll N;
ll MOD = 1000000007;
ll a = 10;
ll b = 9;
ll c = 8;

int main(){
  cin >> N;

  rep(i, N-1){
    a = (a * 10) % MOD;
    b = (b * 9) % MOD;
    c = (c * 8) % MOD;
  }

  ll ac = (a + c) % MOD;
  ll ans = (ac - 2*b) % MOD;

  if (ans < 0) ans += MOD;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

int main(){
  string s;
  map<string,int> m;
  while(cin>>s){
    if(m.find(s)==m.end()){
      m[s]=1;
    }else{
      m[s]+=1;
    }
  }
  int max_len=0;
  int max_frequency=0;
  //イテレータに不等号は使えない
  //ポインタなら使えるので勘違いした
  //max_len、max_frequencyにそれぞれペアを入れればfor文を三回回す必要がないかと思ったが、pairの作成に時間がかかるので、三回回しても大して時間はかからないと判断した
  for(auto i=m.begin();i!=m.end();i++){
    max_len=max(max_len,(int)((i->first).length()));//stringのlengthはsize_t型
    max_frequency=max(max_frequency,i->second);
  }
  for(auto i=m.begin();i!=m.end();i++){
    if(i->second==max_frequency){
      cout << i->first << " ";
      break;
    }
  }
  for(auto i=m.begin();i!=m.end();i++){
    if((int)((i->first).length())==max_len){
      cout << i->first << endl;
      break;
    }
  }
}



Measured memory_bytes: 3140
main(){float a,b,c,d,e,f,L;for(;~scanf("%f,%f,%f,%f,%f,%f",&a,&b,&c,&d,&e,&f);printf("%f %f\n",a+L*c-e,b+L*d-f))c-=a,d-=b,e-=a,f-=b,L=2*(c*e+d*f)/(c*c+d*d);}

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



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	vector<int> al(n + 1, -1), ar(n + 1, -1), bl(n + 1, -1), br(n + 1, -1);
	for(auto i = 0; i < n; ++ i){
		cin >> a[i];
	}
	for(auto i = 0; i < n; ++ i){
		cin >> b[i];
	}
	int tot = 0;
	vector<int> cnt(n + 1);
	for(auto x = 1, ai = 0, bi = 0; x <= n; ++ x){
		while(ai < n && a[ai] < x){
			++ ai;
		}
		if(ai < n && a[ai] == x){
			int aj = ai;
			while(aj < n && a[aj] == x){
				++ aj;
			}
			tie(al[x], ar[x]) = pair{ai, aj};
			ai = aj;
		}
		while(bi < n && b[bi] < x){
			++ bi;
		}
		if(bi < n && b[bi] == x){
			int bj = bi;
			while(bj < n && b[bj] == x){
				++ bj;
			}
			tie(bl[x], br[x]) = pair{bi, bj};
			bi = bj;
		}
		if(~al[x] && ~bl[x]){
			++ tot;
			if(ar[x] - al[x] + br[x] - bl[x] > n){
				cout << "No\n";
				return 0;
			}
			if(bl[x] <= al[x]){
				if(br[x] <= al[x]){
					++ cnt[0];
					-- cnt[al[x] - br[x] + 1];
					++ cnt[ar[x] - bl[x]];
					-- cnt[n];
				}
				else{
					++ cnt[ar[x] - bl[x]];
					-- cnt[al[x] + n - br[x] + 1];
				}
			}
			else{
				++ cnt[max(0, ar[x] - bl[x])];
				-- cnt[al[x] + n - br[x] + 1];
			}
		}
	}
	for(auto t = 0; t < n; ++ t){
		if(cnt[t] == tot){
			cout << "Yes\n";
			rotate(b.begin(), b.begin() + n - t, b.end());
			for(auto x: b){
				cout << x << " ";
			}
			cout << "\n";
			return 0;
		}
		cnt[t + 1] += cnt[t];
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 8756
#!/usr/bin/env python
N = int(input())
A = list(map(int, input().split()))

c = 0
S = 0
m = pow(10, 9)
for a in A:
    if a < 0:
        c += 1
        abs = -a
    else:
        abs = a
    S += abs
    if abs < m:
        m = abs

if c % 2 == 0:
    print(S)
else:
    print(S - 2 * m)

Measured memory_bytes: 14412
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=5005;
const int MAXM=205;
int B[MAXN][MAXM],n,m,A[MAXN];
int sta[MAXM][MAXN],tp[MAXM];
LL S[MAXN];
int main()
{
	n=read();m=read();
	for(int i=1;i<n;i++)A[i]=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)B[i][j]=read();
	
	LL ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			while(B[sta[j][tp[j]]][j]<=B[i][j]&&tp[j])
				S[sta[j][tp[j]]]-=B[sta[j][tp[j]]][j],S[sta[j][tp[j]-1]]+=B[sta[j][tp[j]]][j],--tp[j];
			S[sta[j][tp[j]]]-=B[i][j];S[i]+=B[i][j];sta[j][++tp[j]]=i;
		}LL sum=0;
		for(int j=i;j>=1;j--)
		{
			sum+=S[j];
			if(j<i)sum-=A[j];
			chkmax(ans,sum);
		}
	}pr2(ans);
	return 0;
}



Measured memory_bytes: 6784
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  ll sum_xor = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum_xor ^= a[i];
  }
  for (int i = 0; i < N; i++) {
    ll ans = a[i] ^ sum_xor;
    cout << ans << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4788
fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}.toIntArray()

fun <T> T.print() = println(this)

fun main() {
	abc000X()
}

fun abc000X() {
	println(list().indexOf(0)+1)
}


Measured memory_bytes: 40112
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll dp[3234][3234], step[3124][3123];
vector <ll> vec;

ll solve(int l, int r){
    int cnt = vec.size()-1 - (r-l+1);
    //cout << l << "|" << r << " " << cur << endl;
   if(dp[l][r] != -1){
       return dp[l][r];
   }
   if(l == r){
      if(cnt%2 == 0) 
      return vec[l];
      else 
      return -1LL*vec[l];
   }
   ll x, y;
   if(cnt % 2 == 0){
      
       x = solve(l+1, r);
       y = solve(l, r-1);
   } else{
       x = solve(l+1, r);
       y = solve(l, r-1);
   }
   //cout << l << "|" << r << "|" << x << "|" << y << endl;
   if(cnt%2 == 0){
       if(vec[l]+x > vec[r]+y){
           dp[l][r] = vec[l]+x;
       } else{
           dp[l][r] = vec[r]+y;
       }
      
   }else{
       if(-1LL*vec[l]+x < -1LL*vec[r]+y){
           dp[l][r] = -1LL*vec[l]+x;
       } else{
           dp[l][r] = -1LL*vec[r]+y;
       }
   }
   //cout << dp[l][r] << endl;
   return dp[l][r];
}

int main()
{
   ll n;
   cin >> n;
   vec.resize(n+1);

   for(int i = 1; i <= n; i++){
       cin >> vec[i];
   }
   for(int i = 1; i <= n; i++){
       for(int j = 1; j <= n; j++) dp[i][j] = -1;
   }

   cout << solve(1, n);
   
}


Measured memory_bytes: 78336
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N =nextInt();
		int[] a = nextInts();
		Arrays.sort(a);
		int n=a[a.length-1];
		int r=a[0];
		for(int i=0;i<N;i++){
			if(Math.abs((n+1)/2-r)>Math.abs((n+1)/2-a[i])){
				r=a[i];
			}
		}
		System.out.println(n+" "+r);
	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 38008
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch AtcodeerAndJanken | diff AtcodeerAndJanken.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address AtcodeerAndJanken.cpp && ./a.out

/*
 
 3/29/2020
 
 9:13-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
string S;

void solve() {
  int res=0,gcnt=0,pcnt=0;
  REP(i,SZ(S)) {
    char c='?';
    if(gcnt>pcnt) c='p';
    else c='g';
    if(S[i]=='p'&&c=='g') res-=1;
    else if(S[i]=='g'&&c=='p') res+=1;
    (c=='p'?pcnt:gcnt)+=1;
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S;
  solve();
  
  return 0;
}


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


int main(void)
{
	//変数の宣言
	
	int d,n;
	
	//データの読み込み
	
	scanf("%d %d",&d,&n);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	if(n<=99){
		if(d==0){
			printf("%d",n);
		}else if(d==1){
			printf("%d",n*100);
		}else{
			printf("%d",n*10000);
		}
	}else{
		if(d==0){
			printf("101");
		}else if(d==1){
			printf("%d",10100);
		}else{
			printf("%d",1010000);
		}
	}
/*	for(i=0;i<n;i++){
		if(i!=0) printf(" ");
		printf("%d",a[i]);
	}
	
	printf("\n");
	
	for(i=0;i<n;i++){
		if(i!=0) printf(" ");
		printf("%d",b[i]);
	}
	printf("\n");
*/	
	
	
	
	
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	
//	printf("結果の出力終了\n");
	
	return 0;
}

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

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

const int MAX=510000;

int main()
{
    int a,x;
    cin>>x>>a;
    if(x>=a)cout<<10;else cout<<0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll mod = 998244353;

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

  int n, s;
  cin >> n >> s;
  vi a(n);
  rep(i,n) cin >> a[i];
  // dp[i][j] = i番目まで見たとき、和がjである集合の個数
  vll dp(n+1, vl(s+1));
  dp[0][0] = 1;
  rep(i,n) {
    dp[i][a[i]] %= mod;
    rep(j,s+1) {
      dp[i+1][j] += dp[i][j] * 2;
      dp[i+1][j] %= mod;
      if(j + a[i] <= s) {
        dp[i+1][j+a[i]] += dp[i][j];
        dp[i+1][j+a[i]] %= mod;
      }
    }
  }
  cout << dp[n][s];
}

Measured memory_bytes: 73664
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();
    let t: String = read();
    let mut s_chars: Vec<char> = s.chars().collect();
    let mut t_chars: Vec<char> = t.chars().collect();
    s_chars.sort();
    t_chars.sort();
    let s_sorted: String = s_chars.into_iter().collect();
    let t_sorted: String = t_chars.into_iter().rev().collect();

    let mut res = "";
    for (s, t) in s_sorted.as_bytes().iter().zip(t_sorted.as_bytes().iter()) {
        if s < t {
            res = "Yes";
            break
        } else if s > t {
            res = "No";
            break
        }
    }
    if res == "" {
        if s_sorted.len() >= t_sorted.len() { 
        res = "No";
        } else {
            res = "Yes";
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n; cin>>n; int arr[n];
	for(int i = 0; i <n; i++){
			cin>>arr[i];
	}
	int dp[n+1]; dp[0] = 0;
	for(int i = 1; i < n; i++) dp[i] = INT_MAX;
	for(int i = 1; i < n; i++){
		if(i-1 >= 0) dp[i] = min(dp[i],dp[i-1]+abs(arr[i]-arr[i-1]));
		if(i-2 >= 0) dp[i] = min(dp[i],dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n-1]<<"\n";
}

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

using ll = long long;

int main() {

    ll a, b, ab, x, y;

    cin >> a >> b >> ab >> x >> y;

    ll minXY = min(x, y);

    ll ans = minXY * min(a + b, 2 * ab);

    if(x > y) {
        ll restX = x - y;
        ans += restX * min(a, 2 * ab);
    }
    else {
        ll restY = y - x;
        ans += restY * min(b, 2 * ab);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
	class Program
	{
		static void Main(string[] args)
		{
			int k = int.Parse(Console.ReadLine());
			string input = Console.ReadLine();
			if (input.Length<=k)

			{
				Console.WriteLine(input);
			}
			else
			{
				Console.WriteLine(input.Substring(0,k)+"...");

			}
			
			
		}
	}
}


Measured memory_bytes: 27512