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

class UnionFind {
public:
    UnionFind(int64_t n) {
        //parが負の場合、このグループに属するノードの数 * (-1)を示す
        par_.resize(n, -1);
    }

    //根を求める
    int64_t root(int64_t x) {
        return (par_[x] < 0 ? x : par_[x] = root(par_[x]));
    }

    //xとyの属する集合を併合
    void unite(int64_t x, int64_t y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }

        //要素数を足す(負の数だがそのまま足せば良い)
        par_[x] += par_[y];

        //yをxに繋げる
        par_[y] = x;
    }

    //xとyが同じ集合に属するか否かを判定
    bool same(int64_t x, int64_t y) {
        return (root(x) == root(y));
    }

    int64_t size(int64_t x) {
        x = root(x);
        return -par_[x];
    }
private:
    vector<int64_t> par_;
};

int main() {
    int64_t N, M;
    cin >> N >> M;
    vector<vector<int64_t>> L(N);
    for (int64_t i = 0; i < N; i++) {
        int64_t K;
        cin >> K;
        L[i].resize(K);
        for (int64_t j = 0; j < K; j++) {
            cin >> L[i][j];
            L[i][j]--;
        }
    }

    //各言語から見てそれを何人目の人が話せるか
    vector<vector<int64_t>> speakable(M);
    for (int64_t i = 0; i < N; i++) {
        for (int64_t l : L[i]) {
            speakable[l].push_back(i);
        }
    }

    UnionFind uf(N);

    for (int64_t l = 0; l < M; l++) {
        //先頭の人につなぐ
        for (int64_t j = 1; j < speakable[l].size(); j++) {
            uf.unite(speakable[l][0], speakable[l][j]);
        }
    }

    cout << (uf.size(0) == N ? "YES" : "NO") << endl;
}

Measured memory_bytes: 9716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const char nl = '\n';

void solve()
{
    int n, k; cin >> n >> k;
    vector<int> p; int val;
    while (cin >> val) {
        p.push_back(val);
    }
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i = 0; i < k; ++i) {
        ans += p[i];
    }
    cout << ans << nl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3660
$n=<>;@t=glob<>;@v=glob<>;
for$i(0..$n-1){
	$m=0;($m+=$t[$_])-=$-=$m-$v[$_]for reverse$i+1..$n-1;
	$V=$v[$i]<$m?
		$v[$i]-$V<$t[$i]?
			($\+=($v[$i]-$V)*($v[$i]+$V)/2+($t[$i]-$v[$i]+$V)*$v[$i],$v[$i]):
			($\+=$t[$i]*($V+$t[$i]/2),$V+$t[$i])
		:$m-$V>$t[$i]?
			($\+=$t[$i]*($V+$t[$i]/2),$V+$t[$i]):
			($u=($t[$i]+$V+$m)/2,$u>$v[$i]?
				($\+=($v[$i]-$V)*($v[$i]+$V)/2+($v[$i]-$m)*($v[$i]+$m)/2+2*($u-$v[$i])*$v[$i],$m):
				($\+=($u-$V)*($u+$V)/2+($u-$m)*($u+$m)/2,$m));
}
print

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

#define MAX 200

int main(){
    int n; cin >> n;
    vector<vector<int>> adj_mat(MAX, vector<int>(MAX, 0));

    rep(i, n){
        int u, k; cin >> u >> k;

        rep(j, k){
            int v; cin >> v;
            adj_mat.at(u-1).at(v-1) = 1;
        }

    }

    rep(i, n){
        rep(j, n-1){
            cout << adj_mat.at(i).at(j) << " ";
        }
        cout << adj_mat.at(i).at(n-1) << endl;
    }
}




Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 1e6 + 10;;
unsigned long long fac[1000010];

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}
long long digits(long long m) {
    long long cnt = 0;
    while (m) {
        cnt++;
        m /= 10;
    }
    return cnt;
}

unsigned long long power(unsigned long long x, unsigned long long y){
    unsigned long long res = 1;
    x = x % MOD;

    while (y > 0) {
        // If y is odd, multiply x with result 
        if (y & 1)
            res = (res * x) % MOD;

        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % MOD;
    }
    return res;
}
unsigned long long modInverse(unsigned long long n) {
    return power(n, MOD - 2);
}


int main() {
    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int n = (x + y) / 3;
    int u = x - n;
    int     v = y - n;
    if (u < 0 || v < 0) {
        cout << 0 << endl;
        return 0;
    }
    fac[0] = 1; fac[1] = 1;
    for (int i = 1; i < MX; ++i) {
        fac[i] = fac[i - 1] * i % MOD;
    }
    
    cout << (fac[n] * modInverse(fac[u]) % MOD * modInverse(fac[n-u]) % MOD) % MOD;
    return 0;
}

Measured memory_bytes: 11464
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

typedef pair<int, int> ii;

int main() {
  int n, m;
  cin >> n >> m;
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  --sx;
  --sy;
  --tx;
  --ty;
  vector<string> s(n);
  for (int i = 0; i < n; ++i) cin >> s[i];
  vector<int> d(n * m, INT_MAX);
  priority_queue<ii, vector<ii>, greater<ii>> Q;
  vector<vector<int>> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

  d[sx * m + sy] = 0;
  Q.push({0, sx * m + sy});
  while (!Q.empty()) {
    int dd = Q.top().first;
    int u = Q.top().second;
    Q.pop();
    if (dd != d[u]) continue;
    int x = u / m, y = u % m;
    for (auto dir : dirs) {
      int nx = x + dir[0];
      int ny = y + dir[1];
      if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
      if (s[nx][ny] == '#') continue;
      int v = nx * m + ny;
      if (d[v] > d[u]) {
        d[v] = d[u];
        Q.push({d[v], v});
      }
    }
    for (int i = -2; i <= 2; ++i) {
      for (int j = -2; j <= 2; ++j) {
        int nx = x + i;
        int ny = y + j;
        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (s[nx][ny] == '#') continue;
        int v = nx * m + ny;
        if (d[v] > d[u] + 1) {
          d[v] = d[u] + 1;
          Q.push({d[v], v});
        }
      }
    }
  }
  int ret = d[tx * m + ty];
  if (ret == INT_MAX) ret = -1;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 9232
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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;
  }
};


int main(){
    ll n,k;
    cin >> n >> k;
    mint ans = 0;
    for(ll i=k;i<=n+1;i++){
        ans += (2*n-i+1)*i/2;
        ans -= i*(i-1)/2;
        ans += 1;
    }
    cout << ans.x << endl;
}

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

int main(){
  ll n;
  cin >> n;
  if(n % 2) {
    cout << 0 << endl;
    return 0;
  }
  ll p = 5;
  ll ans = 0;
  while(n/p > 0) {
    ll q = n/p;
    ans += q/2;
    p *= 5;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())

    ans = K * pow(K - 1, N - 1)
    print(ans)

    return


if __name__ == '__main__':
    main()


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

X = [[-1]*N for i in range(N)]
for i in range(N):
    a = int(input())
    for j in range(a):
        b, c = map(int, input().split())
        X[i][b-1] = c
ans = 0
for i in range(2**N):
    Y = [0]*(N)
    for j in range(N):
        if ((i >> j) & 1):
            Y[j] = 1
    flag = True
    for j in range(N):
        if Y[j] == 1:
            for k in range(N):
                if X[j][k] == -1:
                    continue
                if X[j][k] != Y[k]:
                    flag = False
    if flag:
        ans = max(ans, sum(Y))

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
	long long i, n, min = 1000000, max = -1000000, sum = 0;
	cin >> n;
	i = n;
	long long a[i];
	for(i=0;i<n;i++){
		cin >> a[i];
		sum = sum + a[i];
		if(a[i] < min){
			min = a[i];
		}
		if(a[i] > max){
			max = a[i];
		}
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3176
package main

import "fmt"

func main() {
        var n int
        fmt.Scan(&n)
        max, min, tmp := -1, 1001, 0
        for i := n; i > 0; i-- {
                fmt.Scan(&tmp)
                if tmp > max {
                        max = tmp
                }
                if tmp < min {
                        min = tmp
                }
        }
        fmt.Printf("%d\n", max-min)
}

Measured memory_bytes: 512
N = int(input())
A = [int(input()) for _ in range(N)]

count = 0
tmp = 0
for i in range(N):
    if tmp == 1 and A[i] > 0: #一つ前と自分自身で作ることができるとき
        count += 1
        A[i] -= 1
    count += A[i]//2 #同じカードが2枚ごとに1組できる
    tmp = A[i]%2 #カードが余っているかどうか

print (count)
    



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

int main() {
	int N, K;
	cin >> N >> K;
	vector<double> p(N,0);
	for (int i = 0; i < N; i++) cin >> p[i];
	double sum = 0;
	double MaxSum = 0;
	for (int i = 0; i < N; i++) {
		if (i < K) {
			sum += p[i];
			MaxSum = sum;
		}
		else {
			sum += -p[i - K] + p[i];
			MaxSum = max(MaxSum, sum);
		}
	}
	printf("%f\n", (MaxSum + K) / 2);
}


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

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

int main() {
		int n;
		cin>>n;
		chinko a=1;
		for(int i=1;i<=n;++i){
			a*=i;
			a%=1000000007;
		}
		cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod=1e9+7;
LL fastpower(LL base,LL power) 
{
    LL result=1;
    while (power>0)
    {
        if(power%2==0) 
        {
            power = power / 2;
            base = base * base % mod;
        } else{
            power = power - 1;
            result = result * base % mod;
            power = power / 2;
            base = base * base % mod;
        }
    }
    return result;
}
int main()
{
    LL n;cin>>n;
    if(n<=1)cout<<0<<endl;
    else 
    {
        LL a=fastpower(10,n);
        LL b=fastpower(9,n);
        LL c=fastpower(8,n);
        LL sum=(a-2*b+c+mod*100)%mod;
        cout<<sum<<endl;
    }
    return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int id[1005][1005];
int toP(int i, int j) {
  if (j < i) swap(i, j);
  return id[i][j];
}

void solve() {
  int N;
  cin >> N;
  vector<vector<int>> a(N);
  rep(i, N) rep(j, N - 1) {
    int k;
    cin >> k;
    k--;
    a[i].push_back(k);
  }
  dumpv(a, N);
  int idx = 0;
  rep(i, N) rep(j, N) {
    if (i < j) {
      id[i][j] = idx++;
    }
  }
  int V = idx; // 試合数 (==N*(N-1)/2)
  vector<vector<int>> to(V);
  rep(i, N) rep(j, N - 2) { //
    to[toP(i, a[i][j])].push_back(toP(i, a[i][j + 1]));
  }
  dump(idx, to);
  // トポロジカルソート
  vector<int> used(V); // 1: visited, 2: completed
  vector<int> res;
  int loop = false;
  function<void(int)> dfs = [&](int u) {
    if (used[u]) {
      if (used[u] == 1) loop = true;
      return;
    }
    used[u] = 1;
    for (auto& v : to[u]) dfs(v);
    used[u] = 2;
    res.push_back(u); // 帰りがけ順で追加
  };
  rep(i, V) {
    dfs(i);
    if (loop) { //閉路が存在
      cout << -1 << endl;
      return;
    }
  }
  reverse(res.begin(), res.end());
  dump(res);
  vector<int> dp(V);
  used.assign(V, 0);
  function<int(int)> dfs2 = [&](int u) {
    if (used[u]) return dp[u];
    used[u] = 1;
    dp[u] = 1;
    for (auto& v : to[u]) {
      dp[u] = max(dp[u], dfs2(v) + 1);
    }
    return dp[u];
  };
  int ans = 0;
  rep(i, V) { ans = max(ans, dfs2(i)); }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

using namespace std;

int main(){
    int n, x, arr[51];
    
    cin >> n;
    x = 0;
    
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        if(arr[i] != i+1){
            x++;
        }
    }
    
    if(x==2 || x==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  int t = n%10;
  if(t == 3){
    cout << "bon" << endl;
  }else if(t == 0 || t == 1 || t == 6 || t == 8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }
  
  return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        long[] nab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nab[0];
        var a = nab[1];
        var b = nab[2];

        long ans = 0;

        //矛盾していないか判定
        if (a <= b)
        {
            if (n != 1)
            {
                ans = b * (n - 2) - a * (n - 2) + 1;
            }
            else if (b - a == 0)
            {
                ans = b * (n - 2) - a * (n - 2) + 1;
            }
        }

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

Measured memory_bytes: 13396
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();


		String ans = a.substring(0, 1) + b.substring(0, 1) + c.substring(0, 1);

		System.out.println(ans.toUpperCase());

		}
	}



Measured memory_bytes: 20948
import sys
texts=sys.stdin.read()
texts=texts.lower()
cnt=[0]*26

letters=list('abcdefghijklmnopqrstuvwxyz')
for x in texts:
    i=0
    for y in letters:
        if x==y:
            cnt[i]+=1
        i+=1
for i in range(26):
    print(letters[i]+" : "+str(cnt[i]))



Measured memory_bytes: 5560
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;

LL a,b;

int main(){
	ios::sync_with_stdio(false);
	cin >> a >> b;
	cout << (a <= b ? "unsafe" : "safe") << '\n';
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define N 200009
#define inf 999999999999
#define pb push_back
#define M (L+R)/2
using namespace std;

struct node {
	ll sum;
	node *left,*right;
	node(): sum(0), left(NULL), right(NULL){}
};
node *root(NULL);

void upd(node *&parent,ll L,ll R,ll ind,ll x){
	if(!parent){
		parent=new node();
	}
	if(L+1==R){
		parent->sum+=x;
		return;
	}
	if(ind<M){
		upd(parent->left,L,M,ind,x);
	} else {
		upd(parent->right,M,R,ind,x);
	}
	parent->sum=(parent->left?parent->left->sum:0)+(parent->right?parent->right->sum:0);
	return;
}

ll get(node *&parent,ll L,ll R,ll l,ll r){
	if(parent){
		if(L>=r || R<=l)return 0;
		if(l<=L && R<=r)return parent->sum;
		return get(parent->left,L,M,l,r)+get(parent->right,M,R,l,r);
	}
	return 0;
}


ll n,A[N],a[N],b[N],c[N];

bool check(ll x){
	ll zero=0,one=0;
	for(int i=1;i<=n;i++){
		if(a[i]<x)b[i]=-1;//8ero++;
		else b[i]=1;//,one++;
	}
	for(int i=1;i<=n;i++){
		b[i]+=b[i-1];
		if(b[i] >= 0) one++;
		else zero++;
		upd(root,-2*N,2*N,b[i],1);
	}
	for(int i=1;i<=n;i++){
		upd(root,-2*N,2*N,b[i],-1);
		ll G=get(root,-2*N,2*N,b[i],N-1);
		one+=G;
		zero+=n-i-G;
	}

	if(zero>one)return false;
	else return true;
}

int main(){

	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		A[i]=a[i];
	}
	sort(A+1,A+1+n);
	ll L=1,R=n,pas=0;
	while(L<=R){
		root=NULL;
		if(check(A[M])){
			pas=A[M];
			L=M+1;
		} else {
			R=M-1;
		}
	}
	cout<<pas<<endl;
	return 0;
}


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

using namespace std;

char S[30];
int N, P[30];

int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	scanf("%s", S + 1);
	N = strlen(S + 1);
	if (N < 26)
	{
		for (int i = 1; i <= N; ++i)
			P[S[i] - 'a' + 1] = 1;
		int pos;
		for (int i = 1; i <= 26; ++i)
			if (!P[i])
			{
				pos = i;
				break;
			}
		S[N + 1] = pos + 'a' - 1;
		puts(S + 1);
	}
	else
	{
		if (!strcmp(S + 1, "zyxwvutsrqponmlkjihgfedcba"))
		{
			puts("-1");
			return 0;
		}
		for (int i = N; i >= 1; --i)
		{
			for (int j = S[i] - 'a' + 2; j <= 26; ++j)
			{
				if (P[j])
				{
					for (int k = 1; k < i; ++k) printf("%c", S[k]);
					printf("%c\n", j + 'a' - 1);
					return 0;
				}
			}
			P[S[i] - 'a' + 1] = 1;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e9+18
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=51;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
#define ub upper_bound
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
 if(a.ss>b.ss)
 return 1;

 return 0;   
}
int main()
{
    ll n,i,j,l,k,m,d,p;
    cin>>n;
   string s;
   cin>>s;
   l=s.length();
 if(l<=n)
 cout<<s;
 else
 {
    s=s.substr(0,n);
    s+="...";
    cout<<s;
 }  
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int n = Integer.parseInt(br.readLine());
    for (int i = 0; i < n; i++) {
      String tmp = br.readLine();
      String[] strArray = tmp.split(" ");
      List<Integer> intList = Arrays.asList(strArray).stream().map(s -> Integer.valueOf(s)).collect(Collectors.toList());
      ArrayList<Integer> arr1 = new ArrayList<>();
      ArrayList<Integer> arr2 = new ArrayList<>();

      for (Integer item : intList) {
        if (arr1.isEmpty() || arr1.get(arr1.size() - 1) < item) {
          arr1.add(item);
        } else if (arr2.isEmpty() || arr2.get(arr2.size() - 1) < item) {
          arr2.add(item);
        } else {
          break;
        }
      }

      if (arr1.size() + arr2.size() == intList.size()) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }
}

Measured memory_bytes: 30728
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>
#include<random>



#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
int N, K;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> K;
	COMinit();
	FOR(i, 1, K + 1) {
		int res1, res2;
		if (i == 1) {
			res1 = 1;
			res2 = mult(fac[N - K + i], finv[N - K]);
			res2 = mult(res2, finv[i]);
			int ans = mult(res1, res2);
			print(ans);
		}
		else {
			res1 = 1;
			res1 = ((res1*fac[K - 1] % MOD)*finv[K - i] % MOD)*finv[i - 1] % MOD;
			res1 %= MOD;
			int C = N - K;
			res2 = 1;
			res2 = ((res2*fac[C + 1] % MOD)*finv[C - i + 1] % MOD)*finv[i] % MOD;
			res2 %= MOD;
			//pe(res1)print(res2);
			int ans = res1 * res2%MOD;
			if (C < i - 1) {
				print(0);
				continue;
			}
			print(ans);
		}
	}
}


Measured memory_bytes: 12032
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int N,A[105],ans=100000000;
string str;
bool b;
int main() {
	cin>>str;
	for(int i=0;i<str.size()-1;++i){
		if(str[i]==str[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			b=true;
			break;
		}
		if(i+2<str.size()&&str[i]==str[i+2]){
			cout<<i+1<<" "<<i+3<<endl;
			b=true;
			break;
		}
	}
	if(!b)cout<<"-1 -1"<<endl;
	//cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
(a,b) = input().split()
a = int (a)
a = a + 1
b = int (b)
list_a = set(range(1,a,1))
for i in range(b):
    c = input()
    d = input().split()
    d = set(map(int,d))
    list_a = list_a-d
print(len(list_a))

Measured memory_bytes: 9244
#include <stdio.h>

main(){
  int n, count, temp, data[100], ans, h, t, i;

  while(1){
    scanf("%d", &n);
    if(n==0) break;

    for(i=0;i<n;i++){
      scanf("%d", &data[i]);
    }
    scanf("%d", &ans);

    h=0;
    t=n-1;
    count=0;
    
    while(1){
      count++;
      temp=(t+h)/2;
      if(data[temp]==ans) break;
      if(data[temp]>ans) t=temp-1;
      else if(data[temp]<ans) h=temp+1;
      if(h>t) break;
    }
    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int N;
    string s;
    cin >> N >> s;

    int fst[4] = {1, 1, -1, -1};
    int scd[4] = {1, -1, 1, -1};

    for (int cnt = 0; cnt < 4; cnt++) {
        int ans[N];
        ans[0] = fst[cnt];
        ans[1] = scd[cnt];

        for (int i = 1; i < N-1; i++) {
            if (s[i] == 'o') {
                ans[i+1] = ans[i-1] * ans[i];
            } else {
                ans[i+1] = - ans[i-1] * ans[i];
            }
        }

        bool possible = true;
        if (s[N-1] == 'o') {
            if (ans[N-2] != ans[0] * ans[N-1]) {
                possible = false;
            }
        } else {
            if (ans[N-2] != - ans[0] * ans[N-1]) {
                possible = false;
            }
        }

        if (s[0] == 'o') {
            if (ans[N-1] != ans[1] * ans[0]) {
                possible = false;
            }
        } else {
            if (ans[N-1] != - ans[1] * ans[0]) {
                possible = false;
            }
        }

        if (possible) {
            for (int i = 0; i < N; i++) {
                if (ans[i] == 1) {
                    cout << 'S';
                } else {
                    cout << 'W';
                }
            }
            return 0;
        }
    }

    cout << -1 << "\n";
    return 0;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
	in >> p.first >> p.second;
	return in;
}
template<int64_t MOD>
class ModInt {
	typedef int64_t T;
	T x;

  public:
	ModInt(){
		x=0;
	}

	ModInt(T value) {
		if (value < 0) value = (MOD - (-value) % MOD);
		x = value % MOD;
	}

	ModInt operator-() const {
		return ModInt(-x);
	}

	ModInt& operator+=(const ModInt& p) {
		if ((x += p.get()) >= MOD) x -= MOD;
		return *this;
	}

	ModInt& operator-=(const ModInt& p) {
		if ((x += MOD - p.get()) >= MOD) x -= MOD;
		return *this;
	}

	ModInt& operator*=(const ModInt& p) {
		x = x * p.get() % MOD;
		return *this;
	}

	ModInt& operator/=(const ModInt& p) {
		*this *= p.inverse();
		return *this;
	}

	ModInt& operator+=(const T& p) {
		return *this += ModInt(p);
	}

	ModInt& operator-=(const T& p) {
		return *this -= ModInt(p);
	}

	ModInt& operator*=(const T& p) {
		return *this *= ModInt(p);
	}

	ModInt& operator/=(const T& p) {
		return *this /= ModInt(p);
	}

	ModInt operator+(const ModInt& p) const {
		return ModInt(*this) += p;
	}

	ModInt operator-(const ModInt& p) const {
		return ModInt(*this) -= p;
	}

	ModInt operator*(const ModInt& p) const {
		return ModInt(*this) *= p;
	}

	ModInt operator/(const ModInt& p) const {
		return ModInt(*this) /= p;
	}

	ModInt operator+(const T& p) const {
		return ModInt(*this) += p;
	}

	ModInt operator-(const T& p) const {
		return ModInt(*this) -= p;
	}

	ModInt operator*(const T& p) const {
		return ModInt(*this) *= p;
	}

	ModInt operator/(const T& p) const {
		return ModInt(*this) /= p;
	}

	bool operator==(const ModInt& p) const {
		return x == p.get();
	}

	bool operator!=(const ModInt& p) const {
		return x != p.get();
	}

	bool operator==(const T& p) const {
		return x == ModInt(p);
	}

	bool operator!=(const T& p) const{
		return x != ModInt(p);
	}

	ModInt inverse() const {
		int a = x, b = MOD, u = 1, v = 0;
		while (b) {
			int t = a / b;
			a -= t * b;
			u -= t * v;
			swap(a, b);
			swap(u, v);
		}
		return ModInt(u);
	}

	T get() const{
		return x;
	}

	friend ostream& operator<<(ostream& out,const ModInt& value){
	    out<<value.x;
	    return out;
	}
};
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD = 998244353;
	int n,m,k;
	cin>>n>>m>>k;
	using moi=ModInt<MOD>;
	vector<moi> f(n+1);
	f[0]=1;
	rep(i,1,n+1)f[i]=f[i-1]*i;
	moi ans=0,memo=m;
	rep(i,n){
		if(i>=n-k-1){
			ans+=f[n-1]/(f[n-i-1]*f[i])*memo;
		}
		memo*=(m-1);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4748
# -*- coding:utf-8 -*-
import numpy as np

def solve():
    H, W = list(map(int, input().split()))
    grid = []
    for _ in range(H):
        grid.append(list(input()))
    grid = (np.array(grid) == ".")*1  # ランプが置ける：1, 障害物:0

    L = np.zeros((H,W), dtype=int)
    R = np.zeros((H,W), dtype=int)
    U = np.zeros((H,W), dtype=int)
    D = np.zeros((H,W), dtype=int)

    for i in range(W):
        if i == 0:
            L[:, i] = grid[:, i]
        else:
            L[:, i] = (L[:, i-1] + 1) * grid[:, i]

    for i in range(W-1, -1, -1):
        if i == W-1:
            R[:, i] = grid[:, i]
        else:
            R[:, i] = (R[:, i+1] + 1) * grid[:, i]

    for i in range(H):
        if i == 0:
            U[i, :] = grid[i, :]
        else:
            U[i, :] = (U[i-1, :] + 1) * grid[i, :]
    
    for i in range(H-1, -1, -1):
        if i == H-1:
            D[i, :] = grid[i, :]
        else:
            D[i, :] = (D[i+1, :] + 1) * grid[i, :]
    
    ans = np.max(L+R+U+D-3)
    print(ans)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 266612
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main() {
	int N, u, v, w;
	cin >> N;
	vector<vector<pair<int, int> > > tree(N);
	for (int i = 1;i < N;++ i) {
		cin >> u >> v >> w;
		tree[--u].push_back(make_pair(--v, w & 1));
		tree[v].push_back(make_pair(u, w & 1));
	}
	vector<int> ans(N, -1);
	ans[0] = 0;
	queue<int> que;
	for (que.push(0);!que.empty();que.pop()) {
		int tmp = que.front();
		for (int i = 0;i < tree[tmp].size();++ i) {
			if (ans[tree[tmp][i].first] >= 0) continue; // 既に色を塗った
			ans[tree[tmp][i].first] = ans[tmp] ^ tree[tmp][i].second;
			que.push(tree[tmp][i].first);
		}
	}
	for (int i = 0;i < N;++ i) cout << ans[i] << endl;
	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  if (N % 2 == 0) return Pow(A*A%MOD2, N/2);
  return A*Pow(A*A%MOD2, N/2) % MOD2;
}

ll N, M, K;
ll MM[int(2e5+5)], nCr[int(2e5+5)];

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

  MM[N-1] = M;
  for (int i = N-2; i >= 0; i--){
    MM[i] = MM[i+1] * (M-1) % MOD2;
  }

  nCr[0] = 1;
  for (ll i = 1; i <= K; i++){
    nCr[i] = nCr[i-1] * (N-i) % MOD2;
    nCr[i] *= Pow(i, MOD2 - 2);
    nCr[i] %= MOD2;
  }

  ll ans = 0;
  for (int i = 0; i <= K; i++){
    ll now = MM[i] * nCr[i] % MOD2;
    ans += now; ans %= MOD2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6668
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    int n = s.size();

    rep(i, n / 2)
    {
        if (s.substr(i, 1) != s.substr(n - 1 - i, 1))
            ans++;
    }
    cout << ans << endl;
}

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

int n,m,x;
int best = -1;

vector<vector<int>> A(12, vector<int>(12));
vector<int> C(12);
void bruteForce(int idx, int money, vector<int> &algo) {
    if (idx >= n) {
        bool achieved = true;
        for (int i : algo)
            if (i < x) achieved = false;
        if (achieved) {
            if (best==-1) best = money;
            else best = min(best,money);
        }
        return;
    }

    bruteForce(idx+1,money,algo);
    for (int i=0; i<m; i++)
        algo[i] += A[idx][i];
    bruteForce(idx+1, money+C[idx], algo);
    for (int i=0; i<m; i++)
        algo[i] -= A[idx][i];
}

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

    cin>>n>>m>>x;
    vector<int> algo(m);
    for (int i=0; i<n; i++) {
        cin>>C[i];
        for (int j=0; j<m; j++)
            cin>>A[i][j];
    }
    bruteForce(0,0,algo);
    cout << best << '\n';

    return 0;
}

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

int main() {
  int a[50][50] = {};
  int N = 0;
  char str[100];

  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    scanf("%s", str);
    for (int j = 0, jlim = strlen(str); j < jlim; j++) {
      a[i][str[j] - 'a']++;
    }
  }

  for (char c = 'a'; c <= 'z'; c++) {
    int max = 999;
    for (int i = 0; i < N; i++) {
      if (max > a[i][c - 'a']) max = a[i][c - 'a'];
    }

    for (int i = 0; i < max; i++) {
      printf("%c", c);
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

def cnt2(A):
	i = 0
	while A%2 == 0:
		A //= 2
		i += 1

	return i

ans = 0
for i in range(N):
	ans += cnt2(a[i])

print(ans)

Measured memory_bytes: 6484
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   char a,b;
   cin >> a >> b;
   if(a=='H')
   {
      cout<<b<<endl;
   }
   else
   {
      cout<<((b=='H')?a:'H')<<endl;
   }
   return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = [int(i) for i in input().split()]

if N >= M:
    print(0)
    exit()

s = M - N
t = 0
X.sort()
Y = []

for i in range(0,M-1):
    Y.append(X[i+1]-X[i])

Y.sort()
for i in range(0,s):
    t = t + Y[i]

print(t)

Measured memory_bytes: 56872
import java.util.Scanner;
import java.util.function.Consumer;
import java.util.stream.IntStream;

public class Main{
    
    static void swap(int a[], int l, int r) {
        int tmp = a[l];
        a[l] = a[r];
        a[r] = tmp;
    }

    static void perm(int[] a, int loc, int len, Consumer<int[]> f)
    {
        if(loc + 1 == len) {
            f.accept(a);
            return;
        }
        perm(a, loc+1, len, f);
        for(int i = loc + 1; i < a.length; i++) {
            swap(a, loc, i);
            perm(a, loc+1, len, f);
            swap(a, loc, i);
        }
    }

    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            for(int i = 0; i < n; i++) {
                int[] gates = IntStream.range(0, 9).map(d->sc.nextInt()).toArray();
                int[] jackies = IntStream.range(0, 9).map(d->sc.nextInt()).toArray();
                int[] counts = new int[2];
                perm(gates, 0, 9, (int[] g) -> {
                    int gp = 0, jp = 0;
                    for(int j = 0; j < 9; j++) {
                        if(g[j] > jackies[j]) {
                            gp += (g[j] + jackies[j]);
                        }
                        else {
                            jp += (jackies[j] + g[j]);
                        }
                    }
                    if(gp > jp) {
                        counts[0]++;
                    }
                    else {
                        counts[1]++;
                    }
                });
                double total = counts[0] + counts[1];
                System.out.printf("%.5f %.5f\n", counts[0]/total, counts[1]/total);
            }
        }
    }
}


Measured memory_bytes: 33116
/**
 *    author:  Mohamad Milhem
 *    created: 2020-01-26-19.28.52
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;

int main(){

    FAST;

    int h,n;
    cin >> h >> n;

    long long sum = 0;

    for (int i = 0 ; i < n ; i++){
        int in;
        cin >> in;
        sum+= in;
    }

    if (sum >= h)cout << "Yes" <<endl;
    else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> da(n);
	for (int i = 0;i < n;i++) {
		cin >> da[i];
	}
	for (int i = 0;i < n;i++) {
		cout << "node " << i + 1 << ": ";
		cout << "key = " << da[i] << ", ";
		if (i != 0)
			cout << "parent key = " << da[(i + 1) / 2 - 1] << ", ";
		int le = (i + 1) * 2 - 1, ri = (i + 1) * 2;
		if (le < n)
			cout << "left key = " << da[le] << ", ";
		if (ri < n)
			cout << "right key = " << da[ri] << ", ";
		cout << endl;
	}
}



Measured memory_bytes: 3096
using System;
using System.Linq;

namespace ARC066
{
    class A
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            int[] AA = new int[100010];
            for (int i = 0; i < N; i++)
            {
                AA[A[i]]++;
            }

            if (N % 2 != 0 && AA[0] != 1) { Console.WriteLine(0); return; }

            long current = 0;
            if (N % 2 != 0) { current = 2; }
            else { current = 1; }

            long res = 1;
            while (current < N)
            {
                if (AA[current] == 2) { current += 2; res = (res * 2) % 1000000007; }
                else { Console.WriteLine(0); return; }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 19680
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	rep(i, n) {
		if (s[i] == 'p') ans--;
	}
	ans += n / 2;
	cout << ans << endl;
	return 0;
}

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

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

    if (b > c && d > a) {
        elapse = min(b, d) - max(a, c);
    } else {
        elapse = 0;
    }
    cout << elapse << endl;

    return 0;
}

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

int main() {
    int N,T;
    cin >> N >> T;
    int ans = 10000;
    for(int i = 0; i < N; i++) {
        int c,t;
        cin >> c >> t;
        if(T >= t) {
            ans = min(ans,c);
        }
    }
    if(ans == 10000) {
        cout << "TLE" << endl;
    }
    else {
        cout << ans << endl;
    }
} 


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

int main(){
  using point= pair<int64_t, int64_t>;
  int N,K;
  cin >> N >> K;
  const int Kin= K-2;

  vector<point> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i).first >> data.at(i).second;
  }
  sort(data.begin(), data.end());

  int64_t ans= INT64_MAX;
  for(int j1=0; j1<N; j1++){
    for(int j2=j1+1; j2<N; j2++){
      point p1= data.at(j1);
      point p2= data.at(j2);
      int64_t ymax= max(p1.second, p2.second);
      int64_t ymin= min(p1.second, p2.second);

      if(Kin==0){
        int64_t xmax= max(p1.first, p2.first);
        int64_t xmin= min(p1.first, p2.first);

        ans= min(ans, (xmax- xmin)*(ymax- ymin));
      }
      else{
        vector<int64_t> Xs_in_Yrange;
        for(int i=0; i<N; i++){
          if(i==j1 || i==j2){ continue; }
          else{
            if(ymin <= data.at(i).second && data.at(i).second <= ymax){
              Xs_in_Yrange.emplace_back(data.at(i).first);
            }
          }
        }
        int Nin= Xs_in_Yrange.size();
        if(Nin >= Kin){
          for(int i=0; i+Kin-1 < Nin; i++){
            int64_t xmax= max(Xs_in_Yrange.at(i+Kin-1), max(p1.first, p2.first));
            int64_t xmin= min(Xs_in_Yrange.at(i)      , min(p1.first, p2.first));

            ans= min(ans, (xmax- xmin)*(ymax- ymin));
          }
        }
      }
    }
  }

  cout << ans << endl;
}

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

using namespace std;

int main()
{
    int n, m;
    
    while (scanf("%d %d", &n, &m) && n){
        pair<int, int> P[100000];
        int ans = 0;
        for (int i = 0; i < n; i++){
            int a, b;
            scanf("%d %d", &a, &b);
            ans += a * b;
            P[i] = make_pair(-b, a);
        }
        
        sort(P, P + n);
        
        for (int i = 0; i < n; i++){
            if (P[i].second <= m){
                ans += P[i].first * P[i].second;
                m -= P[i].second;
            }
            else {
                ans += P[i].first * m;
                break;
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 1968
package main

import "fmt"

func main() {
	var S, T string

	fmt.Scan(&S, &T)
	count := 0

	if len(S) == 3 && len(T) == 3 {
		for i := 0; i < 3; i++ {
			if S[i] == T[i] {
				count++
			}
		}
	}
	fmt.Print(count)
}


Measured memory_bytes: 1768
while True:
 H,W = list(map(int, input().split() ))
 if H==0 and W==0:
  break
 for r in range(H):
  if r==0 or r==H-1:
   for c in range(W):
    print("#",end="")
  else:
   for c in range(W):
    if c==0 or c==W-1:
     print("#",end="")
    else:
     print(".",end="")
  print()
 print()




Measured memory_bytes: 7000
N,M=map(int,input().split())
a={int(input()) for _ in range(M)}

l=[0]*(N+1)
l[0]=1

for i in range(N):
    c=l[i]%1000000007
    if i>N-2:
        if i not in a:
            l[i+1]+=c
    elif i not in a:
        l[i+1]+=c
        l[i+2]+=c

print(l[N]%1000000007)


Measured memory_bytes: 11920
#include <iostream>
#include <cmath>
using namespace std;
long long int foo(int D, int N) {
  long long int result;
  if (D == 0 && N == 100) {
    return 101;
  }
  if (D == 1 && N == 100) {
    return 10100;
  }
  if (D == 2 && N == 100) {
    return 1010000;
  }
  result = N * pow(100, D);
  return result;
}
  
  
int main() {
  int D, N;
  cin>>D;
  cin>>N;
  cout<<foo(D, N)<<endl;
  return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
ll dp[11][11];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,t,n,b,c,d,a,l,r;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        x=i;
        y=x%10;
        while(x/10!=0)
            x/=10;
        dp[x][y]++;
    }
    ll ans=0;
    for(i=1; i<=9; i++)
        for(j=1; j<=9; j++)
            ans+=dp[i][j]*dp[j][i];
    cout<<ans<<'\n';
}



Measured memory_bytes: 3604
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"math/big"
	"os"
)

var reader *bufio.Reader
var writer *bufio.Writer

var inputFile = flag.String("input", "", "")

func init() {
	flag.Parse()
	var i io.Reader
	if *inputFile != "" {
		i, _ = os.Open(*inputFile)
	} else {
		i = os.Stdin
	}
	reader = bufio.NewReaderSize(i, 1<<20)
	writer = bufio.NewWriterSize(os.Stdout, 1<<20)
}

func println(a ...interface{}) {
	_, _ = fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	_, _ = fmt.Fprintf(writer, format, a...)
}

func scanf(format string, a ...interface{}) {
	_, _ = fmt.Fscanf(reader, format, a...)
}

func scan(a interface{}) {
	_, _ = fmt.Fscan(reader, a)
}

func NextInt64() int64 {
	var res int64
	scan(&res)
	return res
}

func NextInt() int {
	var res int
	scan(&res)
	return res
}

func NextIntArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextString() string {
	var res string
	scan(&res)
	return res
}

func NextBigInt() *big.Int {
	n := new(big.Int)
	n, _ = n.SetString(NextString(), 10)
	return n
}

func AbsInt64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func MinInt64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func MaxInt64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func MaxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer writer.Flush()

	s := []byte(NextString())
	t := []byte(NextString())
	
	dp := make([][]int, len(s)+1)
	p := make([][]int, len(s)+1)

	for i := 0; i <= len(s); i++ {
		dp[i] = make([]int, len(t)+1)
		p[i] = make([]int, len(t)+1)
	}

	for i := 0; i <= len(s); i++ {
		for j := 0; j <= len(t); j++ {
			if i+1 <= len(s) && dp[i+1][j] <= dp[i][j] {
				dp[i+1][j] = dp[i][j]
				p[i+1][j] = 0
			}
			if j+1 <= len(t) && dp[i][j+1] <= dp[i][j] {
				dp[i][j+1] = dp[i][j]
				p[i][j+1] = 1
			}

			if i < len(s) && j < len(t) && s[i] == t[j] && dp[i+1][j+1] <= dp[i][j]+1 {
				dp[i+1][j+1] = dp[i][j] + 1
				p[i+1][j+1] = 2

			}
		}
	}
	var res []byte
	for i, j := len(s), len(t); i > 0 && j > 0; {
		if p[i][j] == 0 {
			i--
			continue
		}

		if p[i][j] == 1 {
			j--
			continue
		}

		res = append(res, s[i-1])
		i--
		j--
	}

	var answer string
	for i := len(res) - 1; i >= 0; i-- {
		answer = answer + string(res[i])
	}

	println(answer)
}


Measured memory_bytes: 155520