akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class DSU {
	private int n;
	private int[] parentOrSize;

	public DSU(int n) {
		this.n = n;
		this.parentOrSize = new int[n];
		java.util.Arrays.fill(parentOrSize, -1);
	}

	int merge(int a, int b) {
		if (!(0 <= a && a < n))
			throw new IndexOutOfBoundsException("a=" + a);
		if (!(0 <= b && b < n))
			throw new IndexOutOfBoundsException("b=" + b);

		int x = leader(a);
		int y = leader(b);
		if (x == y) return x;
		if (-parentOrSize[x] < -parentOrSize[y]) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		parentOrSize[x] += parentOrSize[y];
		parentOrSize[y] = x;
		return x;
	}

	boolean same(int a, int b) {
		if (!(0 <= a && a < n))
			throw new IndexOutOfBoundsException("a=" + a);
		if (!(0 <= b && b < n))
			throw new IndexOutOfBoundsException("b=" + b);
		return leader(a) == leader(b);
	}

	int leader(int a) {
		if (parentOrSize[a] < 0) {
			return a;
		} else {
			parentOrSize[a] = leader(parentOrSize[a]);
			return parentOrSize[a];
		}
	}

	int size(int a) {
		if (!(0 <= a && a < n))
			throw new IndexOutOfBoundsException("" + a);
		return -parentOrSize[leader(a)];
	}

	java.util.ArrayList<java.util.ArrayList<Integer>> groups() {
		int[] leaderBuf = new int[n];
		int[] groupSize = new int[n];
		for (int i = 0; i < n; i++) {
			leaderBuf[i] = leader(i);
			groupSize[leaderBuf[i]]++;
		}
		java.util.ArrayList<java.util.ArrayList<Integer>> result = new java.util.ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			result.add(new java.util.ArrayList<>(groupSize[i]));
		}
		for (int i = 0; i < n; i++) {
			result.get(leaderBuf[i]).add(i);
		}
		result.removeIf(java.util.ArrayList::isEmpty);
		return result;
	}
}


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

        DSU uf = new DSU(N);
        for(int m=0; m<M; m++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            uf.merge(a,b);
        }
        System.out.println(uf.groups().size()-1);
    }
}

Measured memory_bytes: 61708
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (unsigned)!((int)0)
#define pb push_back
#define popb pop_back
#define elif else if
typedef long long ll;
typedef unsigned long long int ull;
int main()
{
    int a,b,m[10001],s=0;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>m[i];
    }
    sort(m,m+a);
    for(int i=0;i<b;i++)
    {
        s=s+m[i];
    }
    cout<<s<<endl;
}


Measured memory_bytes: 3648
N = int(input())
as_dict = {}
for i in range(1,N+1):
    a_i = int(input())
    as_dict[i] = a_i

n = 1
for i in range(N):
    n = as_dict[n]
    if n == 2:
        print(i+1)
        exit()
print(-1)


Measured memory_bytes: 17892
n, a, b = gets.split.map(&:to_i)

if a > b
  p 0
  exit
end

if n == 1 && b != a
  p 0
  exit
end

if n == 1 && b == a
  p 1
  exit
end


p b*(n-2) - a*(n-2) + 1

# 5 0 0 1


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	if(s=="ABC") cout<<"ARC"<<endl;
	else cout<<"ABC"<<endl;
	return 0;
}


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

int main() {
	int h,n;
	cin >> h >> n;
	vector<int> a(n,0);
	for(int i;i < n;i++)
	{
		cin >> a.at(i);
	}
	int sm = 0;
	for(int i = 0;i < n;i++)
	{
		sm += a.at(i);
	}
	string k = "Yes";
	if(h > sm)
	{
		k = "No";
	}
	cout << k <<endl;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstddef>

bool dead[400][400];

int main() {
  size_t N, M;
  std::scanf(" %zu %zu", &N, &M);
  while (M--) {
    size_t u, v;
    std::scanf(" %zu %zu", &u, &v);
    --u; --v;
    if (!dead[u][v]) {
      dead[u][v] = dead[v][u] = true;
      for (size_t w = 0; w < N; ++w) {
        if (dead[u][w]) {
          dead[v][w] = dead[w][v] = true;
        }
      }
      for (size_t w = 0; w < N; ++w) {
        if (dead[v][w]) {
          dead[u][w] = dead[w][u] = true;
        }
      }
    }
    else {
      for (size_t w = 0; w < N; ++w) {
        dead[u][w] = dead[w][u] = dead[v][w] = dead[w][v] = true;
      }
    }
  }
  size_t ans = 0;
  for (size_t u = 0; u < N; ++u) {
    for (size_t v = 0; v < u; ++v) {
      if (!dead[u][v]) {
        ++ans;
      }
    }
  }
  std::printf("%zu\n", ans);
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    int A, B;
    cin >> A >> B;
    if (A % 2 == 0 || B % 2 == 0)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<a.length;i++) {
			a[i]=sc.nextInt();
		}
		int[] b =new int[n];
		for(int j=0;j<a.length;j++) {
			b[j]=a[n-1-j];
			System.out.printf("%d",b[j]);
			if(j!=a.length-1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
		sc.close();
	}

}



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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int cnt = 1;
  
  for(int i = 1; i < S.size(); i++) {
    if(S.at(i) != S.at(i - 1)) cnt++;
  }
  
  cout << cnt << endl;
    
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
int main()
{
	long long int a,b,i,n,flag=1,m,d,j,count=0;
	cin>>a>>b;
	for(i=a;i<=b;i++)
	{

	n=i;
	ostringstream str1;
	str1<<n;
	string s=str1.str();
	m=s.length();
	d=m/2;
	for(j=0;j<d;j++)
	{
		if(s[j]!=s[m-1-j])
		{
			flag=0;
			break;
		}
	}
	if(flag==1)
	{
		count++;
	}
	flag=1;
}
cout<<count;
	
}

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

int main()
{   
    string s;
    cin>>s;
    int a_n=0;
    int z_n=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
        a_n=i;
        break;
        }
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='Z'){
        z_n=i;
        }
    }
    
    cout<<z_n-a_n+1<<endl;
    
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int euclid(int x, int y){
	if(y == 0){
		return x;
	}
	else{
		return euclid(y, x%y);
	}
}

int main(){
	int x, y;
	cin >> x >> y;
	int gcd = euclid(x, y);
	int ratiox = x / gcd, ratioy = y / gcd;
	int ans = (x+1) + (y+1) - gcd - 1;
	cout << ans << "\n";
}



Measured memory_bytes: 3116
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int N, M, R;
int MAX = 210;
vector<vector<ll>> dist(MAX, vector<ll>(MAX));

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

    cin >> N >> M >> R;
    vector<ll> r(R);
    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }

    dist.assign(N + 5, vector<ll>(N + 5, INF));
    rep(i, N + 5) { dist[i][i] = 0; }

    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    // ワーシャルフロイド
    rep(k, N) {
        rep(i, N) {
            rep(j, N) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); }
        }
    }

    sort(all(r));

    ll ans = INF;
    do {
        ll temp = 0;
        for (int i = 1; i < R; i++) {
            temp += dist[r[i]][r[i - 1]];
        }

        ans = min(ans, temp);
    } while (next_permutation(all(r)));

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
 int  n ;
 cin >> n ;
vector<int> A(n) ;
vector<int> B(n) ;
vector<int> C(n) ;
rep(i,n) cin>> A[i] ;
rep(i,n) cin >> B[i] ;
rep(i,n) cin >>C[i] ;
sort(A.begin(),A.end()) ;
sort(C.begin(),C.end()) ;
ll ans=0 ;
rep(i,n){
auto p= lower_bound(ALL(A),B[i])-A.begin() ;
auto q= upper_bound(ALL(C),B[i])-C.begin() ;
ans+= p*(n-q) ;
}
 
 cout <<ans<<endl ;
     return 0;
}

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

int main() {
  string s;
  cin >> s;
  int K;
  scanf("%d", &K);

  vector<string> ans;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= min((int)s.length() - i, K); j++) {
      ans.push_back(s.substr(i, j));
    }
  }

  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());

  printf("%s", ans.at(K - 1).c_str());
  return 0;
}


Measured memory_bytes: 1660
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int h, w;
	while(scanf("%d%d", &w, &h), w){
		int ys, xs, yg, xg;
		scanf("%d%d%d%d", &xs, &ys, &xg, &yg);
		--ys; --xs; --yg; --xg;
		
		vvi field(h, vi(w, 0));
		int n;
		scanf("%d", &n);
		rep(i, n){
			int c, d, x, y;
			scanf("%d%d%d%d", &c, &d, &x, &y);
			--x; --y;
			rep(j, d?4:2){
				rep(k, d?2:4){
					field[y+j][x+k] = c;
				}
			}
		}
		
		int road = field[ys][xs];
		if(!road)
			puts("NG");
		else{
			vector<vector<bool> > visited(h, vector<bool>(w, false));
			queue<pii> Q;
			Q.push(pii(ys, xs));
			bool ok = false;
			while(!Q.empty()){
				pii pos = Q.front();
				Q.pop();
				if(visited[pos.first][pos.second])
					continue;
				visited[pos.first][pos.second] = true;
				if(pii(yg, xg) == pos){
					ok = true;
					break;
				}
				
				const int dy[] = {-1, 0, 0, 1};
				const int dx[] = {0, -1, 1, 0};
				rep(i, 4){
					int py = pos.first + dy[i];
					int px = pos.second + dx[i];
					if(py<0 || h<=py || px<0 || w<=px || field[py][px]!=road)
						continue;
					Q.push(pii(py, px));
				}
			}
			puts(ok ? "OK" : "NG");
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;
int main()
{
    stat();
ll n;cin>>n;
cout<<n*(n-1)/2<<endl;
    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


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

typedef long long ll;

using namespace std;

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

	tuple<string,int,int> p[100];

	int A, T; cin >> A;
	string S;
	for (int i = 0; i < A; i++) {
		cin >> S >> T;
		p[i] = make_tuple(S, -T, i);
	}
	sort(p, p + A);
	for (int i = 0; i < A; i++) {
		int a = get<2>(p[i]);
		cout << a + 1 << endl;
	}
}

Measured memory_bytes: 256
// finish date: 2018/07/03
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <functional>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<long double> vd;
typedef vector<vector<long double>> vvd;
typedef vector<vector<vector<long double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
const int bigmod = 1000000007;
const int INF = 1050000000;


int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    vl acc(N, 0);
    rep(i, N) {
        acc[i] = A[i];
        if (i > 0) acc[i] += acc[i - 1];
    }
    ll ans = LONG_LONG_MAX;

    FOR(k, 1, N - 2) {
        auto itr1 = upper_bound(acc.begin(), acc.end(), acc[k] / 2.0);
        ll sumB = *itr1;
        if (distance(acc.begin(), itr1 - 1) >= 0) {
            if (abs(acc[k] / 2.0 - *itr1) > abs(acc[k] / 2.0 - *(itr1 - 1))) {
                sumB = *(itr1 - 1);
            }
        }
        ll sumC = acc[k] - sumB;

        auto itr2 = upper_bound(acc.begin(), acc.end(), acc[k] + (acc[N - 1] - acc[k]) / 2.0);
        ll sumD = *itr2 - acc[k];
        if (distance(acc.begin(), itr2 - 1) > k) {
            if (abs(acc[k] + (acc[N - 1] - acc[k]) / 2.0 - *itr2) >
                abs(acc[k] + (acc[N - 1] - acc[k]) / 2.0 - *(itr2 - 1))) {
                sumD = *(itr2 - 1) - acc[k];
            }
        }
        ll sumE = acc[N - 1] - sumD - acc[k];


        ans = min(ans, max({sumB, sumC, sumD, sumE}) - min({sumB, sumC, sumD, sumE}));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>

int main()
{

    while(1) {
        int judgeNum = 0;
        int pointSum = 0;
        int maximumPoint = 0;
        int minimumPoint = 1000;

        std::cin >> judgeNum;
        if (judgeNum == 0) {
            break;
        }

        for(int i = 0; i < judgeNum; i++) {
            int point;
            std::cin >> point;
            if(point > maximumPoint) {
                maximumPoint = point;
            }

            if (point < minimumPoint) {
                minimumPoint = point;
            }
            pointSum += point;
        }

        int answerSum = pointSum - maximumPoint - minimumPoint;

        std::cout << answerSum / (judgeNum - 2) << std::endl;
    }
    return 0;
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

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

    // input
    ll N, A, B;
    cin >> N >> A >> B;

    ll ans = min(N*A, B);
    p(ans);
    
    return 0;
}

Measured memory_bytes: 256
def solve(N):
    for h in range(1, 3501):
        for n in range(1, 3501):
            d = 4*h*n - N*h - N*n
            if d == 0: continue
            w = N*h*n / d
            if 0 < w and w == int(w):
                print(h, n, int(w))
                return

N = int(input())

solve(N)


Measured memory_bytes: 39536
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 100001

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	ll A, B, K; cin >> A >> B >> K;
	bool flag = true;
	while (K--)
	{
		if (flag && A % 2 == 1)
			A -= 1;
		if (!flag && B % 2 == 1)
			B -= 1;
		if (flag)
		{
			A /= 2;
			B += A;
			flag = false;
		}
		else
		{
			B /= 2;
			A += B;
			flag = true;
		}

	}
	cout << A << " " << B;

	return 0;
}

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>x>>a;
    if(x>=a) cout<<10<<endl;
    else cout<<0;
    return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    string s; cin >> s;
    ll p_cnt, g_cnt, win_cnt, lose_cnt;
    p_cnt = 0;
    g_cnt = 0;
    win_cnt = 0;
    lose_cnt = 0;
    rep(i, 0, s.length()){
        bool goo = true; 
        if(s[i] == 'g'){
            if(p_cnt < g_cnt) {
                win_cnt++;
                goo = false;
            }
        } else {
           if(p_cnt < g_cnt){
               goo = false;
           } else {
               lose_cnt++;
           }
        }
        if(goo) g_cnt++;
        else p_cnt++;
    }
    cout << win_cnt - lose_cnt << endl;
    return 0;
}




Measured memory_bytes: 512
/* Simplicity and Goodness */
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


void solve()
{   
    string s, t;
    cin >> s >> t;

    int c = 0;

    rep(i, 0, s.size())
    c += s[i] != t[i];

    cout << c;
}

int main()
{
    int t = 1;
    // scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3860
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;

int main()
{
  string s;
  int count = 0;
  const int value = 700;
  cin >> s;

  for (int i = 0; i < 3; i++)
  {
    if (s[i] == 'o')
    {
      count++;
    }
  }
  cout << value + count * 100 << endl;

  return 0;
}


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

int main() {

    int H ,W;
    cin >> H >> W ;

    vector<vector<char>> s(H ,vector<char>(W));

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            
            cin >> s.at(i).at(j);
        }
    }

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

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            
            int count = 0;
            if (s.at(i).at(j) == '.') {
                
                for (int k = 0; k < 8; k++) {
                    
                    if (i+dx[k] >= 0 &&i+dx[k] < H && j+dy[k] >= 0 && j+dy[k] < W ) {
                        
                        if (s.at(i+dx[k]).at(j+dy[k])== '#') {
                            
                            count++;
                        }   
                    }
                }

                s.at(i).at(j) = '0' + count;
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {

            cout << s.at(i).at(j);
        }
        cout << endl;
    }
    

    return 0;
    

}

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

int main()
{
  int n, k;
  cin >> n >> k;
  std::vector<int> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  sort(begin(a), end(a));
  int judge = a.at(0);
  int count = 0;
  std::vector<pair<int, int>> data;
  for(int i = 0; i < n; i++)
  {
    if(judge != a.at(i))
    {
      data.push_back( make_pair(count, judge) );
      count = 1;
      judge = a.at(i);
    }
    else
    {
      count++;
    }

    if(i == n - 1)
    {
      data.push_back( make_pair(count, judge));
      break;
    }
  }
  sort(begin(data), end(data));

  /*for(auto x : data)
  {
    int a, b;
    tie(a, b) = x;
    cout << a << " " << b << endl;
  }*/
  int answer = 0;
  if(data.size() <= k)
  {
    cout << 0 << endl;
  }
  else
  {
    for(int i = 0; i < data.size() - k; i++)
    {
      int x, y;
      tie(x, y) = data.at(i) ;
      answer += x;
    }
    cout << answer << endl;
  }
  
}


Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int a[10];

bool dfs(int i, int left, int right){
	//cout << left << " " << right << " " << i << endl;
	if(i == 10) return true;
	bool answer = false;
	if(left < a[i]){
		answer = dfs(i+1, a[i], right);
	}
	if(right < a[i]){
		answer = dfs(i+1, left, a[i]);
	}

	return answer;
}


int main(){
	int N;
	cin >> N;
	for(int i = 0;i < N;i++){
		for(int j = 0; j < 10;j++){
			cin >> a[j];
		}
		if(dfs(0,0,0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n, m;
  cin >> n;
  map<string, int> blue, red;
  REP(i, 0, n) {
    string a;
    cin >> a;
    ++blue[a];
  }
  cin >> m;
  REP(i, 0, m) {
    string a;
    cin >> a;
    ++red[a];
  }
  int point = 0;
  for (auto v : blue) {
    point = max(point, v.second - red[v.first]);
  }
  cout<<point<<endl;

  return 0;
}


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

using namespace std;

int n;
vector<int> a;
vector<vector<long long>> DP;
vector <vector<long long>> DP2;
const long long inf = 10000000000007;

int main()
{
	cin >> n;
	a.resize(n + 1);
	for (int i = 1; i < n + 1; i++)
		cin >> a[i];

	// 2D DP array DP[i][j], taro's move (try to maximize)
	// 2D DP array DP2[i][j], jiro's move (try to minimize)
	// i is the one end of the deque, j is the other end
	// i, 1...n; j, 1...n
	DP.resize(n + 1); DP2.resize(n + 1);
	for (int i = 1; i < n + 1; i++)
	{
		DP[i].resize(n + 1, 0);
		DP2[i].resize(n + 1, 0);
	}

	for (int i = n; i >= 1; i--)
	{
		for (int j = 1; j < n + 1; j++)
		{
			if (i == j) //last element
			{
				DP[i][j] += a[i];
				DP2[i][j] -= a[i];
			}
			else if (i == j - 1) // last 2 elements
			{
				DP[i][j] += abs(a[i] - a[j]);
				DP2[i][j] -= abs(a[i] - a[j]);
			}
			else if (i > j)
			{
				DP[i][j] = 0;
				DP2[i][j] = 0;
			}
			else // other i<j-1
			{
				// DP[i][j]
				// 1 - i, DP2[i+1][j]
				// 2 - j, DP2[i][j-1]
				// DP[i][j] = max(max(DP[i + 2][j] + a[i] - a[i + 1], DP[i + 1][j - 1] + a[i] - a[j]),max(DP[i + 1][j - 1] + a[j] - a[i], DP[i][j - 2] + a[j] - a[j - 1]));
				DP[i][j] = max(DP2[i + 1][j] + a[i], DP2[i][j - 1] + a[j]);
				DP2[i][j] = min(DP[i + 1][j] - a[i], DP[i][j - 1] - a[j]);
			}
		}
	}
	cout << DP[1][n] << endl;

}

Measured memory_bytes: 144460
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define PD(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define PC(x) printf("%c",x)
#define PS(x) printf("%s",x)
#define PF(x) printf("%f",x)
#define SP printf(" ")
#define BR printf("\n")
#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int32 n;
	cin >> n;
	uint64 a1,a2;
	a1 = 2;
	a2 = 1;
	if (n == 0) {
		cout << 2 << endl;
		return 0;
	}
	else if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	else {
		rep(i, 1, n) {
			uint64 temp;
			temp = a1 + a2;
			a1 = a2;
			a2 = temp;
		}
	}
	cout << a2 << endl;
	return 0;
}

Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
import math
from functools import reduce

#### START
S=input()

if len(set(S))==len(S):
  print("yes")
else:
  print("no")

Measured memory_bytes: 3572
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn solve(xvs: &[(i64, i64)], c: i64) -> i64 {
    let n = xvs.len();

    let mut dp = vec![0; n];
    {
        let mut sum = 0;
        for i in (0..n).rev() {
            let (x, v) = xvs[i];
            sum += v;
            sum -= c-x;
            if i < n-1 {
                sum += c-xvs[i+1].0;
                dp[i] = max(dp[i+1], sum);
            } else {
                dp[i] = max(0, sum);
            }
        }
    }

    let mut ans = 0;
    let mut sum = 0;
    for i in 0..n {
        let (x, v) = xvs[i];
        sum += v;
        sum -= x;
        if i > 0 {
            sum += xvs[i-1].0;
        }
        ans = max(ans, sum);

        if i < n-1 {
            let sum2 = sum - x + dp[i+1];
            ans = max(ans, sum2);
        }
    }
    ans
}


fn main() {
    input!{
      n: usize,
      c: i64,
      xvs: [(i64, i64); n],
    }
    let mut ans = solve(&xvs, c);
    let mut xvs: Vec<(i64, i64)> = xvs.into_iter().map(|(x, v)| ((c-x), v)).collect();
    xvs.reverse();
    ans = max(solve(&xvs, c), ans);
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

const ll INF = 1000000000000000000;

void Main() {
    int n;
    cin >> n;
    vll a(n);

    rep(i, n) {
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return;
        }
    }
    
    ll ans = 1;

    rep(i, n){
        if(ans * a[i] < ans || ans * a[i] < a[i] || ans * a[i] > INF){
            cout << -1 << endl;
            return;
        }
        ans *= a[i];
    }
    
    cout << ans << endl;
	return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    ll a[n+1], b[n];
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 0;
    rep(i,n){
        ll c;
        c = min(a[i],b[i]);
        ans += c;
        a[i] -= c;
        b[i] -= c;
        c = min(a[i+1],b[i]);
        ans += c;
        a[i+1] -= c;
        b[i] -= c;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
import collections

sys.setrecursionlimit(int(1e7))

def dfs(node, parent, distance):
    depth[node] = distance
    for next_node, cost in Tree[node]:
        if next_node != parent:
            dfs(next_node, node, distance + cost)

N = int(input())

Tree = collections.defaultdict(list)

for i in range(N - 1):
    a, b, c = map(int, input().split())
    Tree[a].append((b, c))
    Tree[b].append((a, c))

q, k = map(int, input().split())

depth = {}
dfs(k, -1, 0)

for i in range(q):
    x, y = map(int, input().split())
    print(depth[x] + depth[y])


Measured memory_bytes: 143920
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    if(n == 2)
    {
        cout<<1;
        return 0;
    }
    if(n == 1)
    {
        cout<<1;
        return 0;
    }
    ll ans = 2;
    set<ll>s;
    s.insert(n);
    s.insert(n-1);
    //cout<<sqrt(n)<<endl;
    for(ll i=2;i<=sqrt(n);i++)
    {
        ll m = n;
        while(m%i == 0)
            m /= i;
        if((m == 1) || ((m-1)%i == 0))
        {
            //out<<i<<endl;
            if(s.find(i) == s.end())
                ans++;
            s.insert(i);
        }
        ll j=n/i;
        m = n;
        while(m%j == 0)
            m /= j;
        if((m == 1) || ((m-1)%j == 0))
        {
           // cout<<j<<endl;
           if(s.find(j) == s.end())
                ans++;
            s.insert(j);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
pair<int,int> seg[400000];
int input[400000];
int befo[400000];
pair<int,int> getQuery[400000];
int n, m;
vector<int> vt;
pair<int,int> update(int pos, int val, int node, int x, int y) {
	if (pos < x || y < pos)return seg[node];
	if (x == y)return seg[node] = { val ,x};
	int mid = (x + y) / 2;
	pair<int, int> leftValue = update(pos, val, node * 2, x, mid);
	pair<int, int> rightValue = update(pos, val, node * 2 + 1, mid + 1, y);
	if (leftValue.first > rightValue.first)
		seg[node] = rightValue;
	else
		seg[node] = leftValue;
	return seg[node];
}
pair<int,int> query(int lo, int hi, int node, int x, int y) {
	if (hi < x || y < lo)return { 1234567890 ,1234567890};
	if (lo <= x && y <= hi)return seg[node];
	int mid = (x + y) / 2;
	pair<int, int> returnValue;
	pair<int, int> leftValue = query(lo, hi, node * 2, x, mid);
	pair<int, int> rightValue = query(lo, hi, node * 2 + 1, mid + 1, y);
	if (leftValue.first > rightValue.first) 
		returnValue = rightValue;
	else
		returnValue = leftValue;
	return returnValue;
}
int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i <= n; i++)
		scanf("%1d", &input[i]);
	for (int i = 1; i <= n; i++) {
		if (input[i])
			update(i, 1234567890, 1, 0, n);
		else {
			int leftIdx = max(i - m, 0);
			int rightIdx = i - 1;
			getQuery[i] = query(leftIdx, rightIdx, 1, 0, n);
			update(i, getQuery[i].first+1, 1, 0, n);
			befo[i] = getQuery[i].second;
		}
	}
	if (getQuery[n].first >= 1234567890)
		puts("-1");
	else {
		int changeIdx = n;
		while (changeIdx) {
			vt.push_back(changeIdx - befo[changeIdx]);
			changeIdx = befo[changeIdx];
		}
	}
	for (int i = vt.size() - 1; i >= 0; i--) {
		printf("%d ", vt[i]);
	}
}

Measured memory_bytes: 7932
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>
const double pi = 3.14159265358979323846264;
const int mod=1000000007;

//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

void factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

void cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}


int main(){
	int n,k;
    cin>>n>>k;
    LL ans=0;
    LL l=0,r=0;
    FOR(i,0,k){
        l+=i;
    }
    FOR(i,0,k){
        r+=n-i;
    }
    cerr<<l<<" "<<r<<endl;
    FOR(i,k,n+2){
        ans=add(ans,r-l+1);
        l+=i;
        r+=n-i;
    }
    cout<<ans<<endl;
}


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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int maxD = 0;
    for (int i = 0; i < n; i++) {
        maxD = max(maxD, (a[i] - a[(i+n-1)%n] + k) % k);
    }
    cout << k - maxD << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    for(int i=0;i<=s.size();i++){
        if(i%2==1){
            if(s[i]=='R'){
                cout << "No" << endl;
                return 0;
            }
        } else if(i%2==0){
            if(s[i]=='L'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
   
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int m,f,r,t;
while(1){
  cin>>m>>f>>r;
  t=m+f;
  if(m==-1&&f==-1&&r==-1)break;
  if(m==-1||f==-1||30>t)cout<<"F"<<endl;
  else if(t>=80)cout<<"A"<<endl;
  else if(65<=t&&t<80)cout<<"B"<<endl;
  else if(50<=t&&t<65)cout<<"C"<<endl;
  else if(30<=t&&t<50){
    if(r>=50)cout<<"C"<<endl;
    else{cout<<"D"<<endl;}
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void trans (i32 a, i32 *dp, i32 n) {
  for (i32 i = a; i <= n; ++i) {
    dp[i] += dp[i - a];
  }
}

void run (void) {
  i32 a, b, c, n;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32 "%" SCNi32, &a, &b, &c, &n);
  i32 *dp = (i32 *) calloc (n + 1, sizeof (i32));
  dp[0] = 1;
  trans (a, dp, n);
  trans (b, dp, n);
  trans (c, dp, n);
  printf ("%" PRIi32 "\n", dp[n]);
}

int main (void) {
  run();
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
int main(void){
    int n, k;
    ll m=0, x=0;
    P p[100000];
    set<int> s;
    priority_queue<int, vector<int>, greater<int> > q;

    cin>>n>>k;
    for(int i=0;i<n;i++){
        int t, d;
        cin>>t>>d;
        p[i]=P(d, t);
    }
    sort(p, p+n, greater<P>());
    for(int i=0;i<n;i++){
        int d=p[i].first, t=p[i].second;
        if(i<k){
            if(s.find(t)==s.end()){
                s.insert(t);
            }else{
                q.push(d);
            }
            x+=d;
        }else if(s.find(t)==s.end()&&!q.empty()){
            s.insert(t);
            int w=q.top();
            q.pop();
            x+=d-w;
            // cout<<d<<" "<<w<<endl;
        }
        if(i>=k-1){
            ll w=s.size();
            m=max(m, x+w*w);
        }
    }
    cout<<m<<endl;
}


Measured memory_bytes: 4864
// 要復習
// 長方形の分割

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG

int main()
{
    int64_t H, W;
    cin >> H >> W;
    if (H % 3 == 0 || W % 3 == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        int64_t ans = H * W;
        for (int i = 0; i < 2; i++)
        {
            for (int64_t j = 1; j < W; j++)
            {
                int64_t s1 = j * H;
                int64_t s2 = (H / 2) * (W - j);
                int64_t s3 = ((H + 1) / 2) * (W - j);
                int64_t mx = max({s1, s2, s3});
                int64_t mn = min({s1, s2, s3});
                ans = min(ans, mx - mn);

                s2 = (W - j) / 2 * H;
                s3 = (W - j + 1) / 2 * H;
                mx = max({s1, s2, s3});
                mn = min({s1, s2, s3});
                ans = min(ans, mx - mn);
            }
            swap(H, W);
        }
        cout << ans << endl;
    }
}


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

int main(){
	string s; cin>>s;
	set<char> c;
	for(int i=0; i<s.size(); ++i){
		if(c.find(s[i])==c.end()){
			c.insert(s[i]);
		}
		else{
			puts("no");
			return 0;
		}
	}
	puts("yes");
}

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

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

  ll k;
  string s;
  cin >> k >> s;

  if (s.length() <= k) cout << s;
  else cout << s.substr(0, k)  << "..." << endl;

  return 0;
}

Measured memory_bytes: 3644