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

public class Main {
static class UnionFind {
    List<Integer> Parent;
    UnionFind(int N) {
        Parent = new ArrayList<Integer>();
        Integer[] values = new Integer[N];
        Arrays.fill(values, -1);
        Parent.addAll(Arrays.asList(values));
    }
    int root(int A) {
        if (Parent.get(A) < 0)
            return A;
        int root = root(Parent.get(A));
        Parent.set(A, root);
        return root;
    }
    int size(int A) {
        return -Parent.get(root(A));
    }

    boolean connect(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) {
            return false;
        }

        if (size(A) < size(B)) {
            int temp = A;
            A = B;
            B = temp;
        }

        Parent.set(A, Parent.get(A) + Parent.get(B));
        Parent.set(B, A);

        return true;
    }
}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[][] A = new int[N][N];
        long ans = 0L;
        ArrayList<int[]> edge = new ArrayList<int[]>();
        Comparator<int[]> comparator = new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Integer.compare(o1[2], o2[2]);
            }
        };
        for (int i=0;i<N;i++) {
            for (int j=0;j<N;j++) {
                A[i][j] = Integer.parseInt(sc.next());
                int[] add = {i, j, A[i][j]};
                edge.add(add);
                ans += A[i][j];
            }
        }
        int[][] B = new int[N][N];
        for (int i=0;i<N;i++) {
            for (int j=0;j<N;j++) {
                B[i][j] = A[i][j];
            }
        }
        for (int k=0;k<N;k++) {
            for (int i=0;i<N;i++) {
                for (int j=0;j<N;j++) {
                    A[i][j] = Math.min(A[i][j], A[i][k]+A[k][j]);
                }
            }
        }
        for (int i=0;i<N;i++) {
            for (int j=0;j<N;j++) {
                if (A[i][j]!=B[i][j]) {
                    System.out.println(-1);
                    return;
                }
            }
        }
        Collections.sort(edge, comparator);
        UnionFind uf = new UnionFind(N);
        int[][] dp = new int[N][N];
        int INF = 2_000_000_001;
        for (int i=0;i<N;i++) {
            for (int j=0;j<N;j++) {
                if (i!=j) {
                    dp[i][j]=INF;
                }
            }
        }
        for (int i=0;i<edge.size();i++) {
            int x = edge.get(i)[0];
            int y = edge.get(i)[1];
            int dist = edge.get(i)[2];

            for (int j=0;j<N;j++) {
                if (x!=j && j!=y && (A[x][j]+A[j][y]<=A[x][y])) {
                    ans -= dist;
                    break;
                }
            }
        }
        System.out.println(ans/2);
    }
}

Measured memory_bytes: 49668
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n, p; vector<int>a, b;
int solve(vector<int>x, int Y, int C) {
	int L = Y, R = Y;
	while (true) {
		if (L == R)
		{
			int a1 = 0;
			for (int i = L - 1; i >= 0; i--) {
				if (x[i] != C) { a1 = i + 1; break; }
			}
			int a2 = x.size() - 1;
			for (int i = R + 1; i < x.size(); i++) {
				if (x[i] != C) { a2 = i - 1; break; }
			}
			if (a2 - a1 <= 2) { return x.size(); }
			L = a1; R = a2;
		}
		else {
			if (L == 0 || R == x.size() - 1 || x[L - 1] != x[R + 1]) { return x.size() - (R - L + 1); }
			int a1 = 0;
			C = x[L - 1];
			for (int i = L - 1; i >= 0; i--) {
				if (x[i] != C) { a1 = i + 1; break; }
			}
			int a2 = x.size() - 1;
			for (int i = R + 1; i < x.size(); i++) {
				if (x[i] != C) { a2 = i - 1; break; }
			}
			if ((a2 - a1) - (R - L) <= 3) { return x.size() - (R - L + 1); }
			L = a1; R = a2;
		}
	}
}
int main() {
	while(true) {
		cin >> n; if (n == 0)break;
		a.clear(); b.clear();
		for (int i = 0; i < n; i++) { cin >> p; a.push_back(p); }
		int maxn = n; b = a;
		for (int i = 0; i < n; i++) {
			for (int j = 1; j <= 3; j++) {
				a[i] = j;
				maxn = min(maxn, solve(a, i, j));
				a[i] = b[i];
			}
		}
		cout << maxn << endl;
	}
	return 0;
}

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

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

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int f(int n)
{
    return ((n & 1) ? 3 * n + 1 : n / 2);
}

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

    cout <<((a&1 && b&1)?"Yes":"No") << '\n';
    return 0;
}


Measured memory_bytes: 3500
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#define int long long
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0,-1 }; // x軸方向への変位
int dy[4] = { 1, 0,-1, 0 }; // y軸方向への変位





signed main() {
	int X;
	cin >> X;
	int ans = -1;
	for (int b = 0; b < 1000; b++) {
		for (int p = 2; p < 10; p++) {
			int res = (int)std::pow(b, p);
			//cout << res << "\n";
			if (res <= X && res > ans) ans = res;
		}
	}
	cout << ans << "\n";

	return 0;




}

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

int main(){
  int a, b, c, k;

  cin>>a>>b>>c>>k;

  if(a >= b && a >= c){
    for(int i=0;i<k;i++){
      a = a * 2;
    }
  }

  else if(b > a && b >= c){
    for(int i=0;i<k;i++){
      b = b * 2;
    }
  }

  else if(c > a && c > b){
    for(int i=0;i<k;i++){
      c = c * 2;
    }
  }

  cout<<a + b + c<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
	ll n,sum=0,pr;
	cin>>n;
	ll brr[n-1];
	for(ll i=0;i<n-1;i++)
	{
		cin>>brr[i];
	}
	sum=sum+2*brr[0];
	pr=brr[0];
	for(ll i=1;i<n-1;i++)
	{
		sum=sum+brr[i];
		if(brr[i]<pr)
		{
			sum=sum-(pr-brr[i]);
		}
        
		pr=brr[i];
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC167
{
    class MainClass
    {

        static int[] s;
        static int x;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            int n = s[0];
            int m = s[1];
            x = s[2];

            var calist = new Dictionary<int, List<int>>();

            for (int i = 0; i < n; i++)
            {
                var ca = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse).ToList();
                calist.Add(i, ca);
            }

            int minval = int.MaxValue;

            var ca0 = calist[0];
            var idx0 = new List<int>() { 0 };
            idx0.AddRange(ca0);

            var q = new Queue<List<int>>();
            q.Enqueue(idx0);

            if (IsAblOk(idx0))
            {
                minval = idx0[1];
            }

            var ca0no = new int[m + 2].ToList();
            q.Enqueue(ca0no);

            if(n==1){
                if(minval==int.MaxValue){
                    WriteLine(-1);
                }else{
                    WriteLine(minval);
                }
                return;
            }

            while (q.Any())
            {
                var item = q.Dequeue();
                if (IsAblOk(item))
                {
                    minval = Min(minval, item[1]);
                }

                var nextitem = calist[item[0] + 1];
                var nextidx = new List<int>() { item[0] + 1 };
                nextidx.AddRange(nextitem);

                var itemplus = new int[m + 2].ToList();
                itemplus[0] = item[0] + 1;

                for (int i = 1; i < m + 2; i++)
                {
                    itemplus[i] = item[i] + nextidx[i];
                }
                if (IsAblOk(itemplus))
                {
                    minval = Min(minval, itemplus[1]);
                }
                item[0]++;
                if (item[0] + 1 < n)
                {
                    q.Enqueue(item);
                    q.Enqueue(itemplus);
                }
            }
            if (minval != int.MaxValue)
            {
                WriteLine(minval);
            }
            else
            {
                WriteLine(-1);
            }
        }

        public static bool IsAblOk(List<int> l)
        {
            for (int i = 2; i < l.Count; i++)
            {
                if (l[i] < x)
                {
                    return false;
                }
            }
            return true;
        }

    }
}


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

int main() {
  int N, A;
  cin >> N;
  A = 0;

  for (int i = 0; i < N; i ++){
    int l,r;
    cin >> l >> r;
    A += (r-l+1);
  }
  cout << A << endl;
}


Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#ifdef ONLINE_JUDGE
#define debug(x)
#define debug2(x, y)
#define debug3(x, y, z)
#define dbg(v)
#else
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
#endif

// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);

    string s;
    cin >> s;

    if (s[s.size() - 1] == 's') print(s + "es");
    else print(s + "s");

    return 0;
}

/*
  __ _   ___ _ __  _ __
 / _` | / __| '_ \| '_ \
| (_| || (__| |_) | |_) |
 \__,_(_)___| .__/| .__/
            |_|   |_|
*/


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int N,M,ans(0);
vector <int> connect[8];
int passed[8]={0},node(0);

int dfs(int n){
  passed[n]=1;
  node++;
  if (node==N) ans+=1;
  for (int i(0);i<connect[n].size();i++){
    if (passed[connect[n][i]]==0) dfs(connect[n][i]); // is not still path
  }
  passed[n]=0;
  node--;
  return 0;
}

int check(int n){
  passed[n]=1;
  node++;
  if(node==N){
    ans++;
  }
  for(int i=0;i<connect[n].size();i++){
    if(passed[connect[n][i]]==0){
      check(connect[n][i]);
    }
  }
  passed[n]=0;
  node--;
  return 0;
}

// int main() {
// 	cin>>N>>M;
// 	for (int i(0);i<N;i++) {
//     int a,b;
//     cin>>a>>b;
//     connect[b-1].push_back(a-1);
//     connect[a-1].push_back(b-1);
//   }
//   // dfs(0);
//   check(0);
//   cout<<ans<<endl;
//   return 0;
// }
int main(){
  
  cin>>N>>M;
  vector<int> a(M),b(M);
  for(int i=0;i<M;i++){
    cin>>a[i]>>b[i];
    connect[a[i]-1].push_back(b[i]-1);
    connect[b[i]-1].push_back(a[i]-1);
  }
  dfs(0);
  cout<<ans<<endl;
  
 
  return 0;
}


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

int main()
{
    ll h, w;
    cin >> h >> w;
    if(w==1 || h==1){
        cout << 1 << endl;

    }
    else{
        cout << (1ll + h * w) / 2ll << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
N,M,X,Y = map(int,input().split())
x =  list(map(int,input().split()))
y =  list(map(int,input().split()))

for Z in range(X+1,Y+1):
    if max(x) < Z and Z <= min(y):
        print("No War")
        sys.exit()
print('War')

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    int A, B;
    cin >> A >> B;
    cout << A*B << endl;
    return 0;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Linq.Expressions;

static class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private string S;
    const string Target = "CODEFESTIVAL2016";
    private void Scan()
    {
        S = Console.ReadLine();
    }

    public void Solve()
    {
        Scan();
        int cnt = 0;
        for (int i = 0; i < S.Length; i++)
        {
            if (S[i] != Target[i])
            {
                cnt++;
            }
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

using namespace std;

string bord[110];
int x[110],y[110];

int main() {
   int h,w;
   cin >> h >> w;
   rep(i,h)
   cin >> bord[i];
   
   rep(i,h){
      rep(j,w){
         if(bord[i][j]=='#'){
         x[i]=1; y[j]=1;
         }
      }
   }

   rep(i,h){
      if(x[i]){
         rep(j,w){
            if(y[j])
            cout << bord[i][j];
         }
         cout << endl;
      }
   }
}

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

using namespace std;

#ifdef LOCAL_DEFINE
  #include "../../library/DEBUG.hpp"
#else
  #define debug(...) 0
#endif

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s1, s2;
  cin >> s1 >> s2;
  int ans = 0;
  for (int i = 0; i < (int) s1.size(); i++) {
    if (s1[i] != s2[i]) {
      ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
cout<<fixed<<setprecision(10);
int N,K;
string S;
  cin >>N>>K;
  
  cin>>S;
  S.at(K-1)=S.at(K-1)+32;
  cout <<S<<endl;
	
}

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

int main(int argc, char const *argv[])
{
	string s; cin >> s;
	vector<int> ans(s.size() + 1, 0);

	{ // R
		int x = 0, y = 0;
		rep(i, s.size()) {
			if (s[i] == 'R') {
				x++;
				swap(x, y);
			} else {
				ans[i] += x;
				ans[i - 1] += y;
				x = y = 0;
			}
		}
	}

	{ // L
		int x = 0, y = 0;
		for (int i = s.size() - 1; i >= 0 ; --i) {
			if (s[i] == 'L') {
				x++;
				swap(x, y);
			} else {
				ans[i] += x;
				ans[i + 1] += y;
				x = y = 0;
			}
		}
	}

	rep(i, s.size()) cout << ans[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#pragma GCC optimise("Ofast");
using namespace std;
int main()
{
long long n,c;
cin>>n>>c;
vector< long long > weight(n);
vector< long long > value(n);
for(int i=0;i<n;i++) cin>>weight[i]>>value[i];
long long dp[n+1][c+1];
for(int i=0;i<=n;i++)
{
for(int j=0;j<=c;j++)
{
if(i==0 || j==0) 
{
dp[i][j]=0;
}
else 
{
if( j >= weight[i-1] )
{
dp[i][j]=max(value[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]);
}
else
{
dp[i][j]=dp[i-1][j];
}
}
}
}
cout<<dp[n][c]<<endl;
return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int main(){
    string N;
    cin>>N;
    int K;
    cin>>K;
    vector<int>n;
    for(int i=0;i<N.size();i++){
        n.push_back(N[i]-'0');
    }
    int ns=n.size();
    int dp[ns][K+2][2]={};//dp[i][j][k]:i桁目まで見て、0以外がj個で、次に10方向遷移が｛k=0:出来る、k=1:出来ない｝ものの数
    dp[0][1][0]=n[0]-1;
    dp[0][1][1]=1;
    dp[0][0][0]=1;
    for(int i=0;i<ns-1;i++){
        for(int j=0;j<=K;j++){
            dp[i+1][j][0]+=dp[i][j][0];//0
            dp[i+1][j+1][0]+=dp[i][j][0]*=9;//1～9
            if(n[i+1]==0)dp[i+1][j][1]+=dp[i][j][1];//0(のみ)
            else{
                dp[i+1][j][0]+=dp[i][j][1];//0
                dp[i+1][j+1][0]+=dp[i][j][1]*(n[i+1]-1);//1～n[i+1]-1
                dp[i+1][j+1][1]+=dp[i][j][1];//n[i]
            }
        }
    }
    cout<<dp[ns-1][K][0]+dp[ns-1][K][1]<<endl;
    return 0;
}

Measured memory_bytes: 256
X = str(input())
ans = []
for x in X:
    if x == 'S':
        ans.append(x)
    else:
        if len(ans) != 0:
            if ans[-1] == 'S':
                ans.pop()
            else:
                ans.append(x)
        else:
            ans.append(x)
print(len(ans))


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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}
using pdd = pair<double,double>;
constexpr double PI = acos(-1);
double rad_to_deg(double r){
  return r*180.0/PI;
}
double Atan2(pdd v){
  return atan2(v.first,v.second);
}
pdd dif(pdd a,pdd b){
  return { b.first-a.first,b.second-a.second };
}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n;
  cin>>n;
  vector<pdd> a(n);
  rep(i,n)cin>>a[i].first>>a[i].second;

  sort(a.begin(),a.end());
  double ans=(double)INF;
  do{
    double tmp=0.0;
    pdd pos(0,0);
    pdd vec1(1,0);
    a.emplace_back(0,0);
    rep(i,n+1){
      pdd vec2=dif(pos,a[i]);
      auto s=rad_to_deg(Atan2(vec1));
      auto t=rad_to_deg(Atan2(vec2));
      auto d=abs(s-t);
      d=min(d,360.0-d);
      tmp+=d;
      pos=a[i];
      vec1=vec2;
    }
    a.pop_back();
    ans=min(ans,tmp);
  }while(next_permutation(a.begin(),a.end()));
  cout<<(ans)<<endl;

}



Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout<<fixed;
  cout<<setprecision(10);
  double x,t;
  cin>>x>>t;
  cout<<x/t<<endl;
  return 0;
}


Measured memory_bytes: 768
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
F = int(input())
X = []
X.append(A)
X.append(B)
X.append(C)
X.append(D)
X.remove(min(X))
Y = []
Y.append(E)
Y.append(F)
Y.remove(min(Y))
Z = X + Y
W = sum(Z)
print(W)


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

void solve(){
    int x;
    cin>>x;
    vector<long long >v(x);
    map<long long,long long >mp;
    for(int i=0;i<x;i++){
        cin>>v[i];
        mp[v[i]]++;
    }
    long long res=0;
    for(auto f:mp)
        res+=((f.second*(f.second-1))/2);
    
    for(int i=0;i<x;i++){
        cout<<max(0LL,(res-mp[v[i]]+1))<<"\n";
    }

}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    solve();
    return 0;
}

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

#define N_MAX   2*10*10*10*10*10


int main(void)
{
    int n = 0;
    int tmp = 0;
    int a[N_MAX];
    int i = 0;
    
    memset(a, 0x00, sizeof(a));
    
    scanf("%d", &n);
    
    for(i = 0; i < n -1; i++)
    {
        scanf("%d", &tmp);
        a[tmp-1]++;
    }
    
    for(i = 0; i < n; i++)
    {
        printf("%d\n", a[i]);
    }
    
}


Measured memory_bytes: 2512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;

// struct edge{int to;int cost;};
vector<bool> memo(200001,0);
vector<ll> ans(200001,0);
vector<int> g[200001];

void dfs(int t,ll c){
  memo[t]=1;
  ans[t]=c+ans[t];
  int i;
  for(i=0;i<g[t].size();i++){
    int nt=g[t][i];
    if(memo[nt]==1) continue;
    else{
      ll nc=ans[t];
      // cout<<"t "<<t<<" ans "<<ans[]
      dfs(nt,nc);
    }
  }
}

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

  int i;
  for(i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for(i=0;i<q;i++){
    int p,x;
    cin>>p>>x;
    p--;
    ans[p]+=x;
  }
  dfs(0,0);
  for(i=0;i<n;i++)
  cout<<ans[i]<<(i==n-1?"\n":" ");

}


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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

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

void Main() {
  int n;
  cin >> n;
  vector<vector<int>> G(n);
  vector<P> vp;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(a, b);
  }

  int k = 0;
  map<P, int> I;
  vector<int> cs(n, 0);

  vector<int> used(n, 0);
  queue<int> que;
  used[0] = 1;
  que.emplace(0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    if (k < (int)G[v].size()) k = G[v].size();
    int cur = 1;
    for (int u : G[v]) {
      if (used[u]) continue;
      if (cur == cs[v]) cur++;
      cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
      que.emplace(u);
      used[u] = 1;
    }
  }

  cout << k << endl;
  for (auto p : vp) {
    cout << I[p] << endl;
  }
}

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


Measured memory_bytes: 20088
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;

int n;

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    read(n);
    for (R int i = 1; i <= n; ++i)
        if (i * 1.08 >= n && i * 1.08 < n + 1)
            return printf("%d\n", i), 0;
    printf(":(\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    cout << (b - a == c - b ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll n;cin >> n;
    set<ll> s;
    rep(i,n){
        ll a;cin >> a;
        s.insert(a);
    }
    ll x=n-s.size();
    if(x%2==0)cout << s.size() <<endl;
    else cout << s.size()-1 <<endl;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<long long> a(n+1,0);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)a[i]+=a[i-1];
    vector<long long> v;
    for(int i=0;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            v.push_back(a[j]-a[i]);
        }
    }
    long long res=0;
    for(int bit=45;bit>=0;bit--){
        int cnt=0;
        int m=v.size();
        for(int i=0;i<m;i++){
            if(v[i]&(1ll<<bit))cnt++;
        }
        if(cnt>=k){
            res+=(1ll<<bit);
            vector<long long> vv;
            for(int i=0;i<m;i++){
                if(v[i]&(1ll<<bit))vv.push_back(v[i]);
            }
            v=vv;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 6128
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)*}
    };
}

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

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

fn combi(mut n: usize) -> usize  {
    let mut c = 1;
    if n==1 {
        c = 0;
    } else {
        for _ in 0..2{
            c *= n;
            n -= 1;
        }
    }
    c / 2
}

fn main(){

    input!{
        n: usize,
        s: [chars;n],
    }

    let mut s_tmp: Vec<Vec<char>> = Vec::new();
    for i in s {
        let mut p: Vec<char> = i;
        p.sort();
        s_tmp.push(p);
    }

    s_tmp.sort();

    // for i in &s_tmp {
    //     let ss:String = i.into_iter().collect();
    //     println!("{}", ss);
    // }

    let mut tmp = "".to_string();
    let mut ok: bool = false;
    let mut cnt = 1;
    let mut ans = 0;
    for i in &s_tmp {
        let ss:String = i.iter().cloned().collect();
        if ss==tmp {
            ok = true;
            cnt += 1;
        } else {
            if ok==true{
                ans += combi(cnt);
            }
            cnt = 1;
            ok = false;
        }
        tmp = ss;
    }
    ans += combi(cnt);
    println!("{}", ans);
}

Measured memory_bytes: 19960
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mini(vec) return *std::min_element(vec.begin(), vec.end());
#define maxi(vec) return *std::max_element(vec.begin(), vec.end());

int main() {
    int a;
    cin>>a;
    vector<int> vec(a);
    rep(i,a){
        cin>>vec.at(i);
    }
    int max=*std::max_element(vec.begin(), vec.end());
    bool flag=true;
    int sum=0;
    rep(i,a){
        if(vec.at(i)==max&&flag==true){
            sum+=vec.at(i)/2;
            flag=false;
        }
        else
        {
            sum+=vec.at(i);
        }
    }
    cout<<sum<<endl;
    
}



Measured memory_bytes: 256
S = list(input())

flag = False

reverseS = list(reversed(S))
N = len(S)
firstN = (N - 1) // 2
laterN = (N + 3) // 2 - 1
first = S[0:firstN]
later = S[laterN: N + 1]
reverseFirst = list(reversed(first))
reverseLater = list(reversed(later))

if S == reverseS and reverseFirst == first and reverseLater == later:
    flag = True
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38452
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <algorithm>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=20010;
int n,cup;
int x[N],lst[N];
namespace G{
	const int N=20010*4,E=(N<<3)+N*40;//todo
	int to[E],bro[E],head[N],e,n;
	int dfn[N],low[N],bln[N],tim;
	inline int nn(){
		return ++n;
	}
	inline void init(){
		memset(head+1,-1,n<<2);
		memset(dfn+1,0,n<<2);
		e=tim=0;
	}
	inline void ae(int u,int v){
		to[e]=v,bro[e]=head[u],head[u]=e++;
	}
	int stk[N],ss=0;
	bool instk[N];
	void tarjan(int x){
		dfn[x]=low[x]=++tim;
		stk[ss++]=x,instk[x]=true;
		for(int i=head[x],v;~i;i=bro[i]){
			if(dfn[v=to[i]]){
				if(instk[v]){
					apmin(low[x],dfn[v]);
				}
			}else{
				tarjan(v);
				apmin(low[x],low[v]);
			}
		}
		if(dfn[x]==low[x]){
			int v;
			do{
				v=stk[--ss];
				instk[v]=false;
				bln[v]=x;
			}while(v!=x);
		}
	}
}
namespace seg{
	struct Node;
	typedef Node* node;
	struct Node{
		int l,m,r;
		node lson,rson;
		int p[2];
	}*rt;
	node build(int l,int r){
		static node n=new Node[N<<1];
		node x=n++;
		x->l=l,x->m=(l+r)>>1,x->r=r;
		if(l==r){
			x->p[0]=lst[l],x->p[1]=cup-lst[l];
		}else{
			x->p[0]=G::nn(),x->p[1]=G::nn();
			x->lson=build(l,x->m);
			x->rson=build(x->m+1,r);
		}
		return x;
	}
	void putedge(node x){
		if(x->l!=x->r){
			G::ae(x->p[1],x->lson->p[1]);
			G::ae(x->lson->p[0],x->p[0]);
			G::ae(x->p[1],x->rson->p[1]);
			G::ae(x->rson->p[0],x->p[0]);
			putedge(x->lson);
			putedge(x->rson);
		}
	}
	void ae(node x,int p,int l,int r){
		if(x->l==l&&x->r==r){
			G::ae(p,x->p[1]);
			G::ae(x->p[0],cup-p);
		}else if(r<=x->m){
			ae(x->lson,p,l,r);
		}else if(x->m<l){
			ae(x->rson,p,l,r);
		}else{
			ae(x->lson,p,l,x->m);
			ae(x->rson,p,x->m+1,r);
		}
	}
}
inline bool judge(int d){
	G::init();
	seg::putedge(seg::rt);
	for(int i=1,j=i;i<cup;i++){
		for(;x[lst[i]]-x[lst[j]]>=d;j++);
		if(j<i){
			seg::ae(seg::rt,lst[i],j,i-1);
		}
	}
	for(int i=1;i<=G::n;i++){
		if(G::dfn[i]==0){
			G::tarjan(i);
		}
	}
	for(int i=1;i<cup;i++){
		if(G::bln[i]==G::bln[cup-i])return false;
	}
	for(int i=cup;i<=G::n;i+=2){
		if(G::bln[i]==G::bln[i+1])return false;
	}
	return true;
}
inline bool lcmp(int a,int b){
	return x[a]<x[b];
}
inline int Main(){
	n=ni,cup=(n<<1)+1;
	for(int i=1;i<=n;i++){
		x[i]=ni,x[cup-i]=ni;
	}
	for(int i=1;i<cup;i++){
		lst[i]=i;
	}
	sort(lst+1,lst+cup,lcmp);
	G::n=n<<1;
	seg::rt=seg::build(1,n<<1);
	int l=0,r=x[lst[cup-1]]-x[lst[1]];
	while(l<r){
		int m=((l+r)>>1)+1;
		if(judge(m)){
			l=m;
		}else{
			r=m-1;
		}
	}
	return l;
}
int main(){
	printf("%d\n",Main());
	return 0;
}

Measured memory_bytes: 13568
#include<stdio.h>

int main(){
 int a,b;
 char e,f;
 scanf("%d %c %d",&a,&e,&b);
 while(!(e == '?')){
  if(e == '+'){
   printf("%d\n",a+b);}
  if(e == '-'){
   printf("%d\n",a-b);}
  if(e == '*'){
   printf("%d\n",a*b);}
  if(e == '/'){
   printf("%d\n",a/b);}
  scanf("%d %c %d",&a,&e,&b);}
 return 0;}

Measured memory_bytes: 600
#bit全探索を使う。今回は, 2 ** n通り調べることになる
N, M, X = map(int, input().split())

C = []
A = []
for i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])
ans = -1
for i in range(1 << N): # i は 0 ~ 2 ** n - 1 ; iが買う本の組み合わせを表すbit列となる
    experience = [0] * M
    cost = 0
    #~それぞれの本の組み合わせについて、値段、最終的な経験値が Xを超えているか調べるブロック~
    for j in range(N):
        if (i >> j) & 1 == 0: #(i >> j) & 1 は 、i を右に jビットシフトし、1がj番目に含まれているかを調べる操作 (j は 0 から N まで動かす、つまり、長さNのbit列に1が何個あるかを数えている)
            continue 
        cost += C[j] #bit列のj番目に1があった場合, それはj番目の本を選んでいるわけだから,その本の値段を加算する
        for k in range(M):   
            experience[k] += A[j][k]
        if all(x >= X for x in experience): #すべてが X以上であれば
            if ans == -1:
                ans = cost
            else:
                ans = min(ans, cost) # より安いものを得る
print(ans)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+1;
const int M=1e9+7;
const int N1=1e18+1;
typedef pair<int, int> pi;
typedef pair<pair<int, int> , int> pii;
#define F first
#define S second
#define pb push_back
#define endl "\n"


int32_t main(){

  	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  
    
    // int t;cin>>t;
    // while(t--){

    // }

  	int x,y;cin>>x>>y;
  	y-=2*x;
  	if(y<0){
  		cout<<"No"<<endl;
  	}
  	else{
  		if(y%2==0){
  			if((y/2)<=x){
  				cout<<"Yes"<<endl;
  			}
  			else{
  				cout<<"No"<<endl;
  			}
  		}
  		else{
  			cout<<"No"<<endl;
  		}
  	}

  return 0;
}



Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

const int MxN=1e3+5;
const int MOD=1e9+7;
ve<ull> primes;

void sieve(int n) {
    ve<bool> a(n+1, 1);
    for(int i=2;i*i<=n;i++)
        if(a[i])
            for(int j=i*2;j<=n;j+=i)
                a[j]=0;
    for(int i=2;i<=n;i++)
        if(a[i]) primes.push_back(i);
}

int main() {
    int n;cin>>n;
    sieve(n);
    ull res=1;
    rep(i,0,primes.size()) {
        // current divisor
        ull p=primes[i];
        // highest power of current prime that divides n
        ull e=0;
        // legendre's formula
        while(p<=n) {
            e+=(n/p);
            p*=primes[i];
            p%=MOD;
        }
        res*=e+1;
        res%=MOD;
    }
    cout<<res%MOD<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h> 
int main()
{ 
	int a,b,c,d;
	scanf("%d%d%d",&a,&b,&c); 
	for(a;a<b+1;a++)
	 	{	
			if(c%a==0)d++;
	  	} 
	printf("%d\n",d);
 	return 0;
} 


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

int main(void)
{
    int N;
    std::cin >> N;
    
    std::vector<int> d(N);
    for (int i = 0; i < N; i++) {
        std::cin >> d[i];
    }

    std::sort(d.begin(), d.end());

    int center = N / 2;
    int ans = d[center] - d[center - 1];

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define foe(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
L S,xa,ya,xb,yb,x,y;
int ju(L x){
	return x>=0&&x<=1e9;
}
int chk(){
	if(ju(x)&&ju(y)&&ju(xa+x)&&ju(xb+x)&&ju(ya+y)&&ju(yb+y)){
		printf("%lld %lld %lld %lld %lld %lld\n",x,y,xa+x,ya+y,xb+x,yb+y);
		exit(0);
	}
	return 1;
}
const int n=1e9;
int main(){
	
	cin>>S;
	x=y=0;
	xa=1;
	yb=(n-S%n)%n;
	xb=n;
	ya=(S+n-1)/n;
	chk();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int m = (n+1)/2;
  int ans = 0;
  rep(i,m) if(s[i]=='p') --ans;
  rep(i,n-m) if(s[m+i]=='g') ++ans;
  cout << ans << endl;
}

Measured memory_bytes: 3752
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <iostream>
#define maxn 1000009
using namespace std;
const int MOD = 1e9 + 7;
long long f[maxn], sum[maxn];
int main(){
	long long n;
	scanf("%lld", &n);
	f[0] = 1;
	f[1] = n;
	sum[0] = 1;
	sum[1] = n + 1;
	
	for(int i = 2; i <= n; i++){
		f[i] = f[i - 1];
		f[i] = (f[i] + (n - 1) * (n - 1)) % MOD;
		if(i >= 3)
			f[i] += sum[i - 3];
		f[i] += (n - i + 1);
		f[i] %= MOD;
		sum[i] = sum[i - 1] + f[i];
		sum[i] %= MOD;
	}
	cout << f[n] << endl;
	return 0;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s          second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep0(a,n)  for(int i=0;i<n;i++)cin>>a[i]
#define si(x)       cin>>x
#define sii(x,y)    cin>>x>>y
#define siii(x,y,z) cin>>x>>y>>z
#define ahell   998244353
#define hell 1000000007
#define N1 100001
#define fl 1.0000000000
//#define mod 998244353
#define cntbit(a) __builtin_popcountll(a)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;


mi compress;

    int N;
    vector<int> st[2];
    vector<bool> cLazy;
    vector<int> lazy;

    void init(int n)
    {
        N = n;
        for(int i=0;i<2;i++)
        st[i].resize(4 * N + 5);
        cLazy.assign(4 * N + 5, false);
        lazy.assign(4 * N + 5, 0);
    }

    //Write reqd merge functions
    void merge(int &cur, int &l, int &r)
    {
        cur= min(l, r);
    }

    //Handle lazy propagation appriopriately
    void build(int node, int L, int R)
    {
        if(L==R)
        {
            st[0][node] = 6*1e9;
            st[1][node] = 6*1e9;
            return;
        }
        int M=(L + R)/2;
        build(node*2, L, M);
        build(node*2 + 1, M + 1, R);
        for(int i=0;i<2;i++)
        merge(st[i][node], st[i][node*2], st[i][node*2+1]);
    }

    int Query(int node, int L, int R, int i, int j,int id)
    {

        if(j<L || i>R)
            return 2*1e9;
        if(i<=L && R<=j)
            return st[id][node];
        int M = (L + R)/2;
        int left=Query(node*2, L, M, i, j,id);
        int right=Query(node*2 + 1, M + 1, R, i, j,id);
        int cur;
        merge(cur, left, right);
        return cur;
    }
    void pUpdate(int node, int L, int R, int pos, int val,int id)
    {
        if(L == R)
        {
            //if(st[id][node].mn>val)

            st[id][node]=min(st[id][node],val);
            return;
        }
        int M = (L + R)/2;
        if(pos <= M)
            pUpdate(node*2, L, M, pos, val,id);
        else
            pUpdate(node*2 + 1, M + 1, R, pos, val,id);
        for(int i=0;i<2;i++)
        merge(st[i][node], st[i][node*2], st[i][node*2 + 1]);
    }




main()
{
  ios

//si(test);
int test=1,i,j,k,l;
int n,m;
//si(test);
//sieve();
while(test--)
{
  // sii(n,k);
 si(n);
 vii v1;
 set<int>s1;
 for(i=0;i<n;i++)
 {
    int x,y;
    cin>>x>>y;
    v1.pb({x,y});
    //s1.insert(x);
    s1.insert(y);
 }
k=2;
for(auto x:s1)
{
    compress[x]=k;
    k++;
}
init(k+2);
sort(all(v1));
int ans=0;
build(1,1,k+1);
for(auto x:v1)
{
    int x1=x.f,y1=x.s;
    int p1=Query(1,1,k+1,1,compress[y1],0);
    int p2=Query(1,1,k+1,compress[y1],k+1,1);
    ans=max(ans,x1+y1-(p1));
    ans=max(ans,x1-y1-p2);
    pUpdate(1,1,k+1,compress[y1],x1+y1,0);
    pUpdate(1,1,k+1,compress[y1],x1-y1,1);
}
cout<<ans;
 }
}


Measured memory_bytes: 47120
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;
const double EPS=1e-8;
const ll mod = 1000000007;

int64_t gcd(int64_t a,int64_t b){//calc gcd
	if(a==0){
		return b;
	}else if(b==0){
		return a;
	}else if(a>b){
		return gcd(a%b,b);
	}else{
		return gcd(b%a,a);
	}
}

int main(){
	ll k;
	cin>>k;
	ll ans=0;
	for(ll i1=1;i1<=k;i1++){
		for(ll i2=1;i2<=k;i2++){
			for(ll i3=1;i3<=k;i3++){
				ans += gcd(gcd(i1,i2),i3);
			}
		}
	}
	cout<<ans<<endl;
}


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

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> cnt(M);
  for (int x : a) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (int i = x; i < M; i += x) cnt[i]++;
  }
  int ans = 0;
  for (int x : a) {
    if (cnt[x] == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8012
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int n, t, s, a[3003], b[3003];
int dp[3003][3003];
void dpru(int lower, int upper)
{
	for (int i = 0; i < n; ++i)
	{
		for (int j = lower; j <= upper; ++j)
		{
			max_swap(dp[i + 1][j], dp[i][j]);
			if (j - b[i] >= lower)
				max_swap(dp[i + 1][j], dp[i][j - b[i]] + a[i]);
		}
	}
}
int main()
{
	scanf("%d%d%d", &n, &t, &s);
	for (int i = 0; i < n; ++i)
		scanf("%d%d", a + i, b + i);

	dpru(0, s);
	for (int i = 0; i <= n; ++i)
		dp[i][s] = *max_element(dp[i], dp[i] + (s + 1));

	dpru(s, t);

	printf("%d\n", *max_element(dp[n], dp[n] + (t + 1)));
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 400100
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,double> pdd;
inline int mod(int n, int m){int ret = n%m; if(ret < 0) ret += m; return ret;}
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }    else return mod(k*k,m);
}

int32_t main(){
	fastio;
	int n;
	string s;
	cin>>n;
	cin>>s;
	string t1="",t2="";
	if(n&1)return cout<<"No"<<endl,0;
	
	for(int i=0;i<n/2;i++)t1+=s[i];
	for(int i=n/2;i<n;i++)t2+=s[i];
	if(t1==t2){
		cout<<"Yes"<<endl;
	}else cout<<"No"<<endl;
	
	
}

Measured memory_bytes: 256