akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll INF = (ll)pow(10, 15);

void dfs(vvl dist, vl r, vl &used, ll prev, ll depth, ll cost, ll &ans){
  if(depth == used.size() - 1){
    ans = min(ans, cost);
    return;
  }

  rep(i, used.size()){
    if(used[i] == 1) continue;

    used[i] = 1;
    dfs(dist, r, used, i, depth + 1, cost + dist[prev][r[i]], ans);
    used[i] = 0;
  }
}

int main(){
  ll N, M, R;
  cin >> N >> M >> R;
  vl r(R);
  rep(i, R) cin >> r[i];
  ll A, B, C;
  map<ll, vpll> G;
  rep(i, M){
    cin >> A >> B >> C;

    G[A].push_back({B, C});
    G[B].push_back({A, C});
  }

  vvl dist(R, vl(N + 1, INF));

  rep(i, R){
    dist[i][0] = 0;
    dist[i][r[i]] = 0;
    vl vis(N + 1, 0);
    priority_queue<pll, vpll, greater<pll>> que;
    que.push({0, r[i]});

    while(!que.empty()){
      pll top = que.top();
      que.pop();

      if(vis[top.second] == 1) continue;

      vis[top.second] = 1;
      for(auto x : G[top.second]){
	if(dist[i][x.first] > top.first + x.second)
	  dist[i][x.first] = top.first + x.second;

	que.push({dist[i][x.first], x.first});
      }
    }
  }

  ll ans = INF;
  rep(i, R){
    vl used(R, 0);
    used[i] = 1;
    dfs(dist, r, used, i, 0, 0, ans);
  }

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


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

int main() {
  int N;
  cin >> N;
  int to,from,count;
  
  for (int i = 0; i < N; i++){
    cin >> to >> from;  
    count += from - to + 1;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void solve(){
	int n;
	cin>>n;
	vi v(100002);
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		v[k]++;
		v[k+1]++;
		if(k>0)v[k-1]++;
	}
	cout<<*max_element(v.begin(),v.end());
	return;
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}



Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>a(n+1) , b(n+1) , c(n+1);
    for(int i=1 ; i<=n ; i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    int dp[n+1][4];
    dp[1][1] = a[1];
    dp[1][2] = b[1];
    dp[1][3] = c[1];

    for(int i=2 ; i<=n ; i++)
    {
        for(int j=1 ; j<=3 ; j++)
        {
            if(j==1)
            {
                dp[i][j] = a[i] + max(dp[i-1][2] , dp[i-1][3]);
            }
            else if(j==2)
            {
                dp[i][j] = b[i] + max(dp[i-1][1] , dp[i-1][3]);
            }
            else if(j==3)
            {
                dp[i][j] = c[i] + max(dp[i-1][1] , dp[i-1][2]);
            }
        }
    }
    int ans = max(dp[n][1] , dp[n][2]);
    ans = max(ans , dp[n][3]);
    cout<<ans<<endl;

}


Measured memory_bytes: 5900
import scala.io.StdIn.{readInt, readLine}

object Main extends App {
  val n = readInt
  val A = readLine.split(" ").map(_.toInt)
  val totalCost = calcTotalCost(n, A, A.sorted)
  println(totalCost)

  def calcTotalCost(n: Int, A: Array[Int], B: Array[Int]): Int = {
    val visited = Array.fill[Boolean](n)(false)
    val pos = Array.fill[Int](B.max + 1)(-1)
    B.zipWithIndex.map{ case(e, i) => pos(e) = i }

    val minOfAll = B(0)
    var totalCost = 0
    A.foreach(e => {
      var v = e
      if (!visited(pos(v))) {
        var sum = 0
        var count = 0
        var min = Integer.MAX_VALUE
        while (!visited(pos(v))) {
          visited(pos(v)) = true
          sum += v
          count += 1
          min = Math.min(min, v)
          v = A(pos(v))
        }
        val cost1 = (min * (count - 2)) + sum
        val cost2 = (minOfAll * (count + 1)) + (min * 2) + (sum - min)
        totalCost += Math.min(cost1, cost2)
      }
    })
    totalCost
  }
}



Measured memory_bytes: 44480
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,h;
    cin >> n >> h;
    vi a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(rall(a));
    sort(rall(b));
    int ans = 0;
    rep(i,n) {
        if(b[i] < a[0]) break;
        ans++;
        h -= b[i];
        if(h <= 0) {
            cout << ans << endl;
            return 0;
        }
    }
    ans += (h+a[0]-1)/a[0];
    cout << ans << endl;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
A = list(map(int, input().split()))

A = sorted([a for a in A if a < K])
N = len(A)
S = sum(A)

# あああああああああああああああああああ＼(＾o＾)／
if S < K:
    print(N)
    exit()
elif S - A[0] < N:
    print(0)
    exit()

l, r = -1, N
while r - l > 1:
    m = (l + r) // 2
    B = A[:m] + A[m + 1:]

    if S - A[m] < K - A[m]:
        l = m
        continue

    dp = [False] * (K + 1)
    dp[0] = True
    flg= False

    for i in range(N - 1):
        for j in range(K + 1)[::-1]:
            if B[i] > j:
                continue
            else:
                dp[j] = dp[j - B[i]]

            if dp[j] and K-A[m] <= j < K:
                r = m
                flg = True
                break
        if flg:
            flg = False
            break
    else:
        l = m

print(r)


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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> up, down, flat, v;
  while (n--) {
    string s;
    cin >> s;
    int l = 0, r = 0;
    for (auto c : s) {
      if (c == '(') {
        l++;
      } else if (c == ')') {
        if (l > 0) {
          l--;
        } else {
          r++;
        }
      }
    }
    if (l > r) {
      up.push_back({l, r});
    } else if (l < r) {
      down.push_back({l, r});
    } else {
      flat.push_back({l, r});
    }
  }
  sort(up.begin(), up.end(), [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; });
  sort(down.begin(), down.end(), [](pair<int, int> a, pair<int, int> b) { return a.first > b.first; });
  for (auto e : up) v.push_back(e);
  for (auto e : flat) v.push_back(e);
  for (auto e : down) v.push_back(e);

  bool valid = true;
  int l = 0;
  for (auto e : v) {
    // cerr << e.first << ' ' << e.second << endl;
    if (l < e.second) {
      valid = false;
      break;
    }
    l -= e.second;
    l += e.first;
  }
  if (l != 0) valid = false;
  cout << (valid ? "Yes" : "No") << endl;
}


Measured memory_bytes: 22040
package main

import (
	"fmt"
)

func main() {
  var k, s int
  fmt.Scanf("%d %d", &k, &s)

  ans := 0
  for x := 0; x <= k; x++ {
    for y := 0; y <= k; y++ {
      z := s - (x + y)
      if 0 <= z && z <= k {
        ans++
      }
    }
  }
  
  fmt.Printf("%d\n", ans)
}

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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int)1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = ["; __print(x);


int main()
{
    i64 n, m;
    scanf("%lld%lld", &n, &m);
    priority_queue<i64> p;
    for(int i = 0; i < n; i++) {
        i64 x;
        scanf("%lld", &x);
        p.push(x);
    }
    while(m--) {
        i64 x = p.top();
        p.pop();
        p.push(x/2);
    }
    i64 sum = 0;
    while(p.size()) {
        sum += p.top();
        p.pop();
    }
    printf("%lld\n", sum);
}


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

typedef long long int lli;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	lli x, y, a, b, c, i, z, n, cnt = 0, j;
	cin >> x >> y >> a >> b >> c;
	vector<lli> p;
	vector<lli> q;
	vector<lli> r;
	z = a;
    while(z--){
        cin >> n;
        p.push_back(n);
    }
    z = b;
    while(z--){
        cin >> n;
        q.push_back(n);
    }
    z = c;
    while(z--){
        cin >> n;
        r.push_back(n);
    }
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	z = x;
	i = a - 1;
	while(z--){
        r.push_back(p[i]);
        i--;
	}
	z = y;
	i = b - 1;
	while(z--){
	    r.push_back(q[i]);
        i--;
	}
	sort(r.rbegin(), r.rend());
	for(i=0; i<x+y; i++){
        cnt += r[i];
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 7920
n = int(input())
s = input()
cnt = 0

for i in range(1000):
    c = [i // 100, (i // 10) % 10, i % 10]
    f = 0
    for j in range(n):
        if s[j] == str(c[f]): f+=1
        if f == 3: break
    if f == 3: cnt += 1
print(cnt)

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

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

  ll a, b, k;
  cin >> a >> b >> k;

  ll ka = max(k - a, 0LL);

  a = max(a - k, 0LL);

  b = max(b - ka, 0LL);

  cout << a << " " << b << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int S, W;
    cin >> S >> W;
    if(S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}


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

#define NUM 100

int main(void){
  int brac[NUM+1],now,i,flg;
  char str[NUM+2];
  while(fgets(str,sizeof(str),stdin) && strcmp(str,".\n")){
    memset(brac,0,sizeof(brac));
    flg=0;
    now=0;
    for(i=0;i<strlen(str)-1;i++){
      if(str[i]=='('){
	brac[now]=1;
	now++;
      }else if(str[i]=='['){
	brac[now]=2;
	now++;
      }else if(str[i]==')'){
	if(now==0 || brac[now-1]!=1){
	  flg=1;
	  break;
	}
	now--;
      }else if(str[i]==']'){
	if(now==0 || brac[now-1]!=2){
	  flg=1;
	  break;
	}
	now--;
      }
    }
    if(now!=0) flg=1;
    if(flg==0) puts("yes");
    else puts("no");
  }
  return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void)
{
	int a,c,d,e;
	char b;

	scanf("%d", &a);

		c = a / 100;

		d = (a - c * 100) / 10;

		e = a - (c * 100 + d * 10);

		if (c == 1)c = 9;
		else if (c == 9)c = 1;

		if (d == 1)d = 9;
		else if (d == 9)d = 1;

		if (e == 1)e = 9;
		else if (e == 9)e = 1;

		printf("%d%d%d",c, d, e);
	return 0;
}

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

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

llong merge (int A[], int n, int left, int mid, int right){
  int i, j, k;
  llong cnt = 0;
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; ++i) L[i] = A[left +i];
  for (int i = 0; i < n2; ++i) R[i] = A[mid +i];
  L[n1] = R[n2] = SENTINEL;
  i = j = 0;
  for (int k = left; k < right; ++k)
   {
     if(L[i] <= R[j]){
      A[k] = L[i++];
     }else{
      A[k] =R[j++];
      cnt += n1 - i ; 
     }
   } 

return cnt;


}

llong mergeSort(int A[],int n, int left, int right){

  int mid;
  llong v1, v2, v3;
  if( left + 1 < right ){
    mid =(left +right)/2;
    v1 =mergeSort(A,n,left,mid);
    v2 =mergeSort(A,n,mid,right);
    v3 =merge(A,n,left,mid, right);
    return v1 +v2 +v3;
  }else return 0;

}

int main(){
  int A[MAX], n, i;

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

  llong ans = mergeSort(A,n,0,n);
  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 2716
#include<iostream>
using namespace std;
int main(){
char a,b,c[128],d[128];
int n,i;
while(cin>>n){
if(n==0)break;
for(i=0;i<128;i++)c[i]=d[i]=i;
for(i=0;i<n;i++){cin>>a>>b;c[a]=d[b];}
cin>>n;
for(i=0;i<n;i++){cin>>a;cout<<c[a];}
cout<<endl;
}
return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MX 2000000
long long pw[2][1000005],fact[MX+5],inv[MX+5];
long long pow_log(long long x,int y)
{
	if (!y)
	return 1;
	long long ret=pow_log(x,y/2);
	ret=(ret*ret)%mod;
	if (y%2)
	ret=(ret*x)%mod;
	return ret;
}
long long ncr(int n,int r)
{
	return ((fact[n]*inv[r])%mod*inv[n-r])%mod;
}
int main()
{
	fact[0]=1;
	inv[0]=1;
	for (int i=1;i<=MX;i++)
	fact[i]=(i*fact[i-1])%mod;
	inv[MX]=pow_log(fact[MX],mod-2);
	for (int i=MX-1;i>=0;i--)
	inv[i]=(i+1)*inv[i+1]%mod;
	int k,ans=0;
	string s;
	cin >> k >> s;
	int n=s.size();
	pw[0][0]=1;
	pw[1][0]=1;
	for (int i=1;i<=k;i++)
	{
		for (int j=0;j<2;j++)
		pw[j][i]=((25LL+j)*pw[j][i-1])%mod;
	}
	for (int i=0;i<=k;i++)
	ans=(ans+pw[1][i]*pw[0][k-i]%mod*ncr(n+k-i-1,n-1))%mod;
	cout << ans;
}

Measured memory_bytes: 51316
# A - Colorful Subsequence
import numpy as np

N,S = int(input()),input()
count = np.zeros(26)

for i in range(N):
    count[ord(S[i])-ord('a')] += 1

ans = 1
D =10**9+7

for i in range(26):
    ans = int((ans*(count[i]+1))%D)

print(ans-1)

Measured memory_bytes: 12628
N, M = map(int,(input().split()))
table = [input().split() for l in range(M)]
ans = 0
array1 = []
array2 = []
array3 = []
keta1 = -1
keta2 = -1
keta3 = -1
s1 = 0
s2 = 0
s3 = 0
for k in range(M):
    for j in range(2):
        table[k][j] = int(table[k][j])

for k in range(M):
    if table[k][0] == 1:
        if (N != 1 and table[k][1] == 0) or (not(table[k][1] in array1) and s1 == 1):
            keta1 = -1
        else:
            keta1 = table[k][1]
        s1 = 1
        array1.append(table[k][1])

    elif table[k][0] == 2:
        if not(table[k][1] in array2) and s2 == 1:
            keta2 = -1
        else:
            keta2 = table[k][1]
        s2 = 1
        array2.append(table[k][1])
    else:
        if not(table[k][1] in array3) and s3 == 1:
            keta3 = -1
        else:
            keta3 = table[k][1]
        s3 = 1
        array3.append(table[k][1])

if s1 != 1:
    keta1 = 1
if s2 != 1 or M == 0:
    keta2 = 0
if s3 != 1 or M == 0:
    keta3 = 0
if N == 1 and M == 0:
    keta1 = 0

if keta1 == -1 or keta2 == -1 or keta3 == -1:
    ans = -1
elif N == 3:
    ans = keta1 * 100 + keta2 * 10 + keta3
elif N == 2:
    ans = keta1 * 10 + keta2
else:
    ans = keta1
    
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define debug(x) cerr<<#x<<":"<<(x)<<endl;

int f(int n){
  if (n<=0) return 0;
  int res = 0;

  for(int digit=1;digit<50;++digit){
    int base = (1LL<<digit);
    int cnt = (n/base) * (base/2);
    cnt += max(0LL, (n%base) - (base/2) + 1);

    if (cnt%2 == 1) {
      res += (1LL << (digit-1));
    }
    debug(digit);
    debug(cnt);
    debug(res);
  }
  
  return res;
}

signed main() {
  int a,b;cin>>a>>b;
  int ans = f(b)^f(a-1);
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import heapq

N = int(input())
dic = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
  a,b,c = map(int, input().split())
  dic[a].append([b,c])
  dic[b].append([a,c])

Q, K = map(int, input().split())
memo = [float('inf')]*(N+1)
memo[K] = 0
h = [(0,K)]
while h:
  t = heapq.heappop(h)
  if t[0] > memo[t[1]]:
    continue
  for k in dic[t[1]]:
    if memo[k[0]] > t[0] + k[1]:
      memo[k[0]] = t[0] + k[1]
      heapq.heappush(h, (memo[k[0]], k[0]))
      
for _ in range(Q):
  x, y = map(int, input().split())
  print(memo[x]+memo[y])

Measured memory_bytes: 117116
n = int(input())
ls = []
for i in range(n):
    x,l = map(int,input().split())
    ls.append([x-l,l+x])
    
ls = sorted(ls, key=lambda x: x[1])
ans = n

for i in range(1,n):
    if ls[i][0] < ls[i-1][1]:
      ls[i][1] = ls[i-1][1]
      ans -=1
        
print(ans)

Measured memory_bytes: 26288
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a,const void *b){
  return *(int *)a - *(int *)b;
}
int main(){
  int n,m,i,j;
  int d[200010]={};
  int t[200010]={};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
  }
  qsort(d,n,sizeof(int),comp);
  scanf("%d",&m);
  if(m>n){
    printf("NO");
    return 0;
  }
  for(i=0;i<m;i++){
    scanf("%d",&t[i]);
  }
  qsort(t,m,sizeof(int),comp);
  for(i=0,j=0;i+j<n;i++){
    for(;d[i+j]!=t[i]&&i+j<=n;j++);
    if(i+j>n){
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}

Measured memory_bytes: 2556
import math
import fractions

A, B, C, D = map(int, input().split())

def lcm(a, b):
  return (a * b) // fractions.gcd(a, b)

# CとDの最小公倍数で割り切れる数
lcm = lcm(C, D)

ans = B-A+1 - (B//C-(A-1)//C) - (B//D-(A-1)//D) + (B//(lcm)-(A-1)//(lcm))

print(ans)

Measured memory_bytes: 5048
#include<vector>
#include<iostream>
#include<list>
#include<algorithm>
#include<chrono>
#include<map>
#include<set>
#include<string>
#include<unordered_map>

using namespace std;


int main()
{
    int n,k;
    cin >> n >>k;
    vector<int> p(n);
    for(int i = 0; i < n; i++)
      cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    for(int i = 0; i < k; i++) ans += p[i];
    cout << ans;
}

Measured memory_bytes: 3124
M = 10**9 + 7
L = 200000
 
Fm = {}
inverseFm = {}
x = 1
for i in range(L):
    Fm[i] = x
    x = x * (i + 1) % M
 
def inverseFm(x):
    result = pow(Fm[x], M - 2, M)
    return result
 
def C(n, r):
    result = Fm[n] * inverseFm(r) * inverseFm(n - r) % M
    return result
 
def solve(H, W, A, B):
    result = 0
    for i in range(B + 1, W + 1):
        result += C(i + H - A - 1 - 1, i - 1) * C(W - i + A - 1, W - i)
    return result % M
 
H, W, A, B = [int(_) for _ in input().split()]
 
print(solve(H, W, A, B))


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

//素数かどうか判定する関数
bool judge( int x )
{

    for( int i = 2; i <= sqrt(x); i++ )       //与えられた数が10なら
    {                                         //
        if( x % i == 0)
            return false;
    }

    return true;
}

int main()
{
    int n;

    while( cin >> n )                           
    {
        bool PN[n+1];                           //PrimeNumber
        int count = 0;                          //countは素数の数


        PN[0] = false;                          //0は素数ではない。
        PN[1] = false;                          //1は素数ではない。

        for( int i = 2; i <= n; i++)            //0,1以外の全ては素数候補。ここから篩にかける。 
        {
            PN[i] = true;                       //ex.100の場合、2~100を素数候補とする
            count++;
        }

        for( int i = 2; i <= sqrt(n); i++)            
        {
            for( int j = 2; j <= n / i; j++ )
            {
                if( PN[i*j] == true )
                {
                    PN[i*j] = false;
                    count--;
                }

            }
        }
        cout << count << endl;
    }

    return 0;
}


Measured memory_bytes: 4060
n,m,k=[int(j) for j in input().split()]
par=[-1 for i in range(n)]    #par<0なら自身が親で要素の個数、>0なら子で親の位置示す

def root(a):
    if par[a]<0:
        return a
    else:
        return root(par[a])

def size(a):
    return -par[root(a)]

def connect(a,b):
    a=root(a)
    b=root(b)
    if a==b:
        return False
    if size(a)<size(b):
        a,b=b,a
    par[a]+=par[b]
    par[b]=a
    return True


f=set(tuple(int(j)-1 for j in input().split()) for _ in range(m))
b=set(tuple(int(j)-1 for j in input().split()) for _ in range(k))

for a in f:
    if root(a[0])!=root(a[1]):
        connect(a[0],a[1])

ans=[]
for i in range(n):
    ans.append(-par[root(i)]-1)

for i,j in f:
    if root(i)==root(j):
        ans[i]-=1
        ans[j]-=1
for i,j in b:
    if root(i)==root(j):
        ans[i]-=1
        ans[j]-=1

print(*ans)



Measured memory_bytes: 43952
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
	int n,k,x = 1;
	scanf("%d %d",&n,&k);
	for(int i = 0;i<n;++i){
		if(2*x < x+k) x *= 2;
		else x += k;
	}
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 128
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  readln.chomp.split.map!(x=>x[0]).writeln;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdlib>
using namespace std;
string S,T;
int main(){
	cin >> S;
	int count = 0;
	while(cin >> T && T != "END_OF_TEXT"){
		for(int i=0;i<T.size();i++){
			T[i] = tolower(T[i]);
		}
		if(T == S) count++;
	}
	cout << count << endl;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

struct UnionFind {
    vector<int> par; //親の番号

    //コンストラクタ
    UnionFind(int N) : par(N) {
        for (int i = 0; i < N; ++i) {
            par[i] = i; //初期化
        }
    }

    //木の根を求める
    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]); //経路圧縮
        }
    }

    //xとyの属する木を併合
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);

        if (rx == ry) {
            //xとyの根が同じならそのまま
            return;
        }

        par[rx] = ry;
    }

    //xとyが同じ集合に属するかどうか
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);

        return rx == ry;
    }
};

int main() {

    int n, m; cin >> n >> m;

    vector<int> a(m);
    vector<int> b(m);

    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }

    int ans = 0;

    for (int i = 0; i < m; ++i) {
        UnionFind tree(n);

        for (int j = 0; j < m; ++j) {
            if (j != i) {
                tree.unite(a[j], b[j]);
            }
        }

        if (!tree.same(a[i], b[i])) {
            ++ans;
        }
    }

    cout << ans << endl;
}

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

template <typename T>
struct RMQ {
    const T INF = INT_MAX;
    int n;
    vector<T> dat;
    RMQ(int n_) : n(), dat(n_ * 4, INF) {
      int x = 1;
      while(n_ > x) {
        x *= 2;
      }
      n = x;
    }

    void update(int i, T x) {
      i += n - 1;
      dat[i] = x;
      while(i > 0) {
        i = (i - 1) / 2; //parent
        dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
      }
    }

    T query(int a, int b) {return query_sub(a, b, 0, 0, n); }
    T query_sub(int a, int b, int k, int l, int r) {
      // [a, b) と [l, r)が交差していない
      if(r <= a || b <= l) return INF;

      // [a, b) が [l, r)を完全に含んでいれば、その節点の値
      if(a <= l && r <= b) return dat[k];
      else {
        //そうでなければ、2つの子の最小値
        T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
      }
    }
};

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

  RMQ<int> segtree(n);

  while(q--) {
    int t, x, y;
    cin >> t >> x >> y;

    if(t == 0) {
      segtree.update(x, y);
    }
    if(t == 1) {
      cout << segtree.query(x, y + 1) << '\n';
    }
  }

}



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

const string YES = "Yes";
const string NO = "No";
int main(){
  string S; cin >> S;
  if (S[0] == S[1] && S[1] == S[2]) cout << NO << endl;
  else cout << YES << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 

int32_t main(){
    int n,p;
    cin>>n>>p;
    string str;
    cin>>str;
    int ans=0;
    if(p==2 || p==5){
        for(int i=0;i<n;i++){
            if((str[i]-'0')%p==0) ans+=i+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    reverse(str.begin(),str.end());
    int arr[n];
    int val=1;
    for(int i=0;i<n;i++){
        arr[n-i-1]=((str[i]-'0')*val)%p;
        val=(val*10)%p;
    }
    
    unordered_map<int,int> cnt;
    int curr_sum=0;
    for(int i=0;i<n;i++){
        curr_sum=curr_sum+arr[i];
        cnt[curr_sum%p]++;
    }
    int res=0;
    for(int i=0;i<p;i++){
        res+=(cnt[i]*(cnt[i]-1))/2;
    }
    res+=cnt[0];
    cout<<res<<endl;

    
}

Measured memory_bytes: 2436
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#include "string"

int32_t main() {
	boost;
	int n;
	cin >> n ;
	int f[n + 1] = {0} , p[n + 1] = {0} , s[n + 1] = {0}, cnt[n + 1] = {0};
	for(int i = 0, x; i < n; i++) {
		cin >> x;
		f[x]++;
	}
	for(int i = 1; i <= n; i++)
		cnt[f[i]]++;
	for(int i = 1; i <= n; i++)
		p[i] = p[i - 1] + i * cnt[i];
	s[n] = cnt[n];
	for(int i = n - 1; i > 0; i--)
		s[i] = cnt[i] + s[i + 1];
	int ans[n + 1] = {0};
	for(int i = 1; i <= n; i++) {
		int curk = s[i];
		curk += p[i - 1] / i;
		ans[curk] = max(ans[curk] , i);
	}
	for(int i = n - 1; i > 0; i--)
		ans[i] = max(ans[i] , ans[i + 1]);
	for(int i = 1; i <= n; i++)
		cout << ans[i] << endl;
}


Measured memory_bytes: 15308
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int a,b; cin>>a>>b;
  if(b%2==0 && 2*a<=b && b<=4*a) co("Yes");
  else co("No");
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

int n, a[MAXN], res[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    res[n] = 0;
    FORE(i,n-1,1)
        if (a[i] >= a[i+1]) res[i] = res[i+1] + 1;
        else res[i] = 0;
    int Max = 0;
    FOR(i,1,n) Max = max(Max, res[i]);
    cout << Max;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include <numeric>
using namespace std;

int main()
{	
	long long int N;
	long long int P;
	scanf("%lld %lld", &N, &P);

	long long int soin[1000000][2];
	for(long long int i=0;i<1000000;i++){
		soin[i][0]=0;
		soin[i][1]=0;
	}
///	if(N!=1){
	long long int p=2;
	long long int counter=0;
	while(p<=1000000){
		if(P%p==0)
		{	
			P=P/p;
			soin[counter][0]=p;
			soin[counter][1]++;
		}
		else
		{
			if(soin[counter][0]!=0){counter++;}
			p++;
		}
	}
	if(soin[0][0]==0){
		soin[0][0]=P;
		soin[0][1]=1;
	}
		
		
	long long int ans=1;
	for(long long int i=0;i<1000000;i++){
		
			if((soin[i][1])/N!=0)
			{		
					for(long long int j=0;j<(soin[i][1])/N;j++){
						ans=ans*soin[i][0];
					}
			}
		
	}
	if(N==1){ans=ans*P;}
	printf("%lld", ans);
///	}
///	else{
///		printf("%lld", P);
///		}
}


Measured memory_bytes: 15744
import math
import sys
import collections
n,k = map(int, input().split())
A = list(map(int, input().split()))
count=len(A)
Adel=list(set(A))
ans=len(Adel)-k
#print(Adel)
if ans<0:
    ans=0
    print(ans)
    sys.exit()
newA=collections.Counter(A)
count=list(newA.values())
count.sort()
#print(count)
ans=sum(count[:-k])
print(ans)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;

int N, A, B;
char S[MAXN];

int main() {
// #ifndef ONLINE_JUDGE
//   freopen("inp.txt", "r", stdin);
//   freopen("out.txt", "w", stdout);
// #endif
 	scanf("%d%d%d%s", &N, &A, &B, S);
 	int AB = A + B;
 	for (int i = 0; i < N; ++i) {
 		if (S[i] == 'c') printf("No\n");
 		else if (S[i] == 'a') {
 			if (AB > 0) {
 				--AB;
 				printf("Yes\n");
 			} else printf("No\n");
 		} else if (S[i] == 'b') {
 			if (AB > 0 && B > 0) {
 				--AB;
 				--B;
 				printf("Yes\n");
 			} else printf("No\n");
 		}
 	} 
 	return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		int n = sc.nextInt();
		for(int i =0 ;i < n; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			
			
			if(a*a+b*b==c*c || a*a+c*c == b*b || a*a == b*b+c*c){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
			
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
		
	}
}

Measured memory_bytes: 12000
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [X, t] = input[0].map(Number);

  return Math.max(0, X - t);
};

console.log(main(read()));


Measured memory_bytes: 29728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  int n,m; cin>>n>>m;
  vec WA(n);
  int AC=0;
  int p; string s;
  vector<bool> solve(n+1);
  rep(i,n) solve[i]=false;
  
  rep(i,m){
    cin>>p>>s;
    if(solve[p]){ //p問目を解いていたら
      continue; //何もしない
    }
    else{//p問目を解いていなかったら
      if(s=="AC"){
        AC++; solve[p]=true;
      }
      else{
        WA[p]++;
      }
    }  
  }
  
  int ansWA; ansWA=0;
  for(int i=1;i<n+1;i++){
    if(solve[i]){
      ansWA+=WA[i];
    }  
  }
  cout<<AC<<" "<<ansWA;  
}


Measured memory_bytes: 640
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int main(){
	int n; cin >> n;
	string s; cin >> s;
	map<string, ll> mp;
	for(int i = 0;i < (1<<n); i++){
		int k = 0;
		string t = "", u = "";
		for(int j = 0;j < n; j++){
			if(1&(i >> j)){
				t += s[j];
				k++;
			}
			else{
				u += s[j];
			}
		}
		reverse(all(u));
		t += u + to_string(k);
		if(mp.count(t)) mp[t] += 1;
		else mp[t] = 1;
	}
	s = s.substr(n, n*2);
	reverse(all(s));
	ll ans = 0;
	for(int i = 0;i < (1<<n); i++){
		int k = 0;
		string t = "", u = "";
		for(int j = 0;j < n; j++){
			if(1&(i >> j)){
				t += s[j];
				k++;
			}
			else{
				u += s[j];
			}
		}
		reverse(all(u));
		t += u + to_string(k);
		if(mp.count(t)) {
			ans += mp[t];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 35456
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
typedef long long LL;
const int N=1000005,mod=1000000007;
int n,h,d;
LL flv[N],f[N];

int main()
{
	scanf("%d%d%d",&n,&h,&d);
	flv[0]=1;
	rep(i,1,n) flv[i]=flv[i-1]*i%mod;
	f[0]=flv[n];
	LL sum=flv[n],tot=0;
	rep(i,1,n) tot=(tot+flv[i])%mod;
	rep(i,1,h-1)
	{
		f[i]=sum*tot%mod;
		sum=(sum+f[i])%mod;
		if(i-d>=0) sum=(sum-f[i-d]+mod)%mod;
	}
	printf("%lld\n",sum);
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  bool flag=0;
  for(int i=0;i<s.size();i++){
    if(i&1){
      if(s[i]=='R'){
        flag=1;
        break;
      }
    }
    else{
      if(s[i]=='L'){
        flag=1;
        break;
      }
    }
  }
  if(flag==1)
    cout<<"No\n";
  else
    cout<<"Yes\n";
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

using namespace std;
using ll = long long;

int W, H;
bool sea_map[50][50];
bool is_reached[50][50];

void dfs(int s_wi, int s_hi) {
    if(s_wi < 0 || W <= s_wi ||
       s_hi < 0 || H <= s_hi ||
       !sea_map[s_hi][s_wi]  ||
       is_reached[s_hi][s_wi]) {
        return;
    }

    is_reached[s_hi][s_wi] = true;

    dfs(s_wi + 1, s_hi + 1);
    dfs(s_wi + 1, s_hi    );
    dfs(s_wi + 1, s_hi - 1);
    dfs(s_wi    , s_hi - 1);
    dfs(s_wi - 1, s_hi - 1);
    dfs(s_wi - 1, s_hi    );
    dfs(s_wi - 1, s_hi + 1);
    dfs(s_wi    , s_hi + 1);
}

bool search_start_point(int& s_wi, int& s_hi) {
    REP(hi, H) {
        REP(wi, W) {
            if(sea_map[hi][wi] && !is_reached[hi][wi]) {
                s_wi = wi;
                s_hi = hi;
                return true;
            }
        }
    }
    return false;
}

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

    while(true) {
        std::cin >> W >> H;
        if(W == 0 && H == 0) {
            break;
        }

        REP(hi, H) {
            REP(wi, W) {
                std::cin >> sea_map[hi][wi];
                is_reached[hi][wi] = false;
            }
        }

        int ans = 0;
        while(true) {
            int s_wi, s_hi;
            if(!search_start_point(s_wi, s_hi)) {
                break;
            }
            else {
                dfs(s_wi, s_hi);
                ans++;
            }
        }

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

    return 0;
}



Measured memory_bytes: 3224
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

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

}



int main() {
	ll N;
	cin >> N;

	vector<string> s(N);
	rep(i, N)
		cin >> s[i];

	rep(i, N)
		sort(s[i].begin(), s[i].end());

	sort(s.begin(), s.end());

	ll num = 0;
	int i = 0;

	while (i < N - 1) {
		ll num2 = 0;
		while (s[i] == s[i + 1]) {

			i++;
			num2 += 1;
			if (i == N - 1)
				break;
		}


		num += (num2 + 1) * (num2) / 2;
		i += 1;
	}

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include <cstdio>
#include<queue>
using namespace std;

int V, E, R, S[500010], T[500010],D[500010];
int C[100010];
const int Inf = 10000*100000+100;
vector< pair<int,int> >G[500010];

int main()
{
    scanf("%d %d %d",&V, &E, &R);
    for(int i=0;i<E;i++)
    {
        scanf("%d %d %d",&S[i], &T[i], &D[i]);
        G[S[i]].push_back(make_pair(T[i],D[i]));
    }
    for(int i=0;i<V;i++)
    {
        if(i==R)
          C[R]=0;
        else
          C[i]=Inf;
    }
    priority_queue< pair<int,int> > Q;
    pair<int,int> a;
    a.first=0;
    a.second=R;
    Q.push(a);
    int s,t,d;
    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        s=a.second;
        if(C[s]< 0-a.first)
           continue;
        C[s]=0-a.first;
        int l=G[s].size();
        for(int i=0;i<l;i++)
        {
            t=G[s][i].first;
            d=G[s][i].second;
            if(C[t]>0-(C[s]+d))
              Q.push(make_pair(0-(C[s]+d),t));
        }
    }
    for(int i=0;i<V;i++)
    {
        if(C[i]==Inf)
          printf("INF\n");
        else
          printf("%d\n",C[i]);
    }
}


Measured memory_bytes: 29248
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N;
    cin >> N;
    int A[N];
    int num_max=0;
    int ans=0;
    for(int i=0;i<N;++i){
        cin >> A[i];
    }
    
    for(int i=0;i<N;++i){
        if(num_max<=A[i]){
            ++ans;
        }
        num_max=max(num_max,A[i]);
    }
    cout << ans << endl;
    }

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    
    string s, t;

    cin >> s >> t;

    if (t.substr(0,t.length()-1) == s){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

string S;

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> S;
    for (int i = 0; i < (int)S.size(); i++) {
        bool ans = true;
        if (i % 2 == 0) {
            ans = (S[i] == 'h');
        } else {
            ans = (S[i] == 'i');
        }
        if ((int)S.size() % 2 != 0) {
            ans = false;
        }
        if (!ans) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    solve();
    return 0;
}


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

int main(void)
{
    int n;
    cin >> n;
    int data[4][3][10] = {0};
    for(int i = 0; i < n ;i++)
    {
        int b,f,r,v;
        cin >> b >> f >> r >> v;
        data[b-1][f-1][r-1] += v;
    }
    
    for(int i = 0; i < 4 ;i++)
    {
        for(int j = 0; j < 3 ; j++)
        {
            for(int k = 0; k < 10 ;k++)
            {
                cout << " " << data[i][j][k] ;
            }
            cout << endl;
        }
        if(i != 3)
        {
            for(int l = 0; l < 20 ; l++)cout << "#";
            cout << endl;
        }
    }
    
    return 0;
}


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

int gcd(int a, int b);

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a.at(i);
	vector<int> l(n + 1), r(n + 1);
	l.at(0) = 0;
	r.at(n) = 0;
	for (int i = 0; i < n; i++)
	{
		l.at(i + 1) = gcd(l.at(i), a.at(i));
		r.at(n - i - 1) = gcd(r.at(n - i), a.at(n - i - 1));
	}
	int ans = 0;
	vector<int> m(n);
	for (int i = 0; i < n; i++)
	{
		int t = gcd(l.at(i), r.at(i + 1));
		if (t > ans)
			ans = t;
	}
	cout << ans << endl;
}
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	else if (a == 0)
		return b;
	else
		return gcd(b, a % b);
}

Measured memory_bytes: 1792