akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e18+7;

int main() {
    ios::sync_with_stdio(false);   
    Int n, z, w;
    cin >> n >> z >> w;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) cin >> a[i];
    if (n == 1) {
        dump(abs(w - a[0]));
    }
    else {
        dump(max(abs(a[n - 1] - a[n - 2]), abs(w - a[n - 1])));
    }
    return 0;
}

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

struct iostream_init_struct
{ 
	iostream_init_struct()
	{
		std::cin.tie(0);
		std::cin.sync_with_stdio(false);
	}
} iostream_init;

const int INF = 1e8;
int a[1000];
int b[1000];
int c[1000];
int d[100][100];


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

	fill((int*)d, (int*)end(d), INF);
	for (int i = 0; i < N; ++i)
	{
		d[i][i] = 0;
	}
	for (int i = 0; i < M; ++i)
	{
		int a_, b_, c_;
		cin >> a_ >> b_ >> c_;
		d[a_ - 1][b_ - 1] = c_;
		d[b_ - 1][a_ - 1] = c_;
		a[i] = a_ - 1;
		b[i] = b_ - 1;
		c[i] = c_;
	}

	for (int k = 0; k < N; ++k)
	{
		for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j < N; ++j)
			{
				if (d[i][j] > d[i][k] + d[k][j])
				{
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}

	int used_edge_count = 0;
	for (int i = 0; i < M; ++i)
	{
		int a_ = a[i];
		int b_ = b[i];
		int c_ = c[i];
		for (int j = 0; j < N; ++j)
		{
			if (d[j][a_] + c_ == d[j][b_])
			{
				used_edge_count++;
				break;
			}
		}
	}
	cout << M - used_edge_count << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i=0; i<N; i++)
  {
    cin >> A[i];
  }
  
  int ans = A[0];
  for(int i=0; i<A.size(); i++)
  {
    ans = gcd(ans, A[i]);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 640
s = int(input())

if s == 10**18:
    print(0,0,10**9,0,0,10**9)
    exit()
x1 = 10**9
if s%x1 == 0:
    y2 = s//x1
else:
    y2 = s//x1 + 1
r = x1*y2-s

x2 = 1
y1 = r
print(0,0,x1,y1,x2,y2)

Measured memory_bytes: 38256
#include <stdio.h>

int search(int A[], int n, int key) {
    int i = 0;
    A[n] = key;
    while ( A[i] != key ) i++;
    return i != n;
}

int main() {
    int i, n, A[10000+1], q, key, sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &key);
        if ( search(A, n, key) ) sum++;
    }
    printf("%d\n", sum);
}


Measured memory_bytes: 2784
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	ll n, k;
	cin >> n >> k;
	vlli dp(k + 1, -1);
	dp[0] = 0;
	fr(i, 0, n)
	{
		ll w, v;
		cin >> w >> v;
		for (ll j = k - w; j >= 0; --j)
		{
			if (dp[j] != -1)
				dp[j + w] = max(dp[j + w], dp[j] + v);
		}

	}
	ll ans = 0;
	fr (i, 0, k + 1)
	{
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;


}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin >> t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] In = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int n = In[0];
            int k = In[1];
            int[] H = new int[n];
            for(int i = 0; i < n; i++)
            {
                H[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(H);
            int min = 1001001001;
            for(int i = 0; i < n-k+1; i++)
            {
                int tmp = H[i + k - 1] - H[i];
                min = (int)Math.Min(min, tmp);
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 32920
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  for(int i=1;i<101;i++){
    int q=b*i+c;
    if(q%a==0 && q>=a){cout << "YES" << endl;
              return 0;}
  }
  cout << "NO" << endl; 
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	double a_d,b_d;
	scanf("%d %d",&a,&b);
	a_d = static_cast<double>(a);
	b_d = static_cast<double>(b);
	printf("%d %d %.5f\n",a/b,a%b,a_d/b_d);
}


Measured memory_bytes: 2760
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    final int R = sc.nextInt();
    final int S = sc.nextInt();
    final int P = sc.nextInt();
    final String T = sc.next();
    sc.close();
    StringBuilder byK = new StringBuilder();
    int point = 0;
    for(int i=0;i<K;i++) {
    	switch(T.charAt(i)) {
		case 'r' :
			point += P;
			byK.append("r");
			break;
		case 's' :
			point += R;
			byK.append("s");
			break;
		case 'p' :
			point += S;
			byK.append("p");
			break;
		}
    }
    for(int i=K;i<N;i++) {
    	if(byK.charAt(i-K) == T.charAt(i)) {
    		point += 0;
    		if(byK.length()<i+1) {
    			byK.append("c");
    		}
    		byK.setCharAt(i-K, 'c');

    	}else {
    		switch(T.charAt(i)) {
    		case 'r' :
    			point += P;
    			byK.append("r");
    			break;
    		case 's' :
    			point += R;
    			byK.append("s");
    			break;
    		case 'p' :
    			point += S;
    			byK.append("p");
    			break;
    		}
    	}
    }
    System.out.println(point);
  }
}

Measured memory_bytes: 27476
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  int num;
  cin >> num;

  cout << num << ":";
  int left_num = num;
  double num_sqrt = sqrt(num);
  for(int i = 2; i <= num_sqrt; i++) {
    while(left_num % i == 0) {
      cout << ' ' << i;
      left_num /= i;
    }
  }
  if(left_num > 1) {
    cout << ' ' << left_num;
  }

  cout << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
ll inf = 1e10;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  string ans = "UNRESTORABLE";
  for(int i = 0; i < s.size()-t.size()+1; ++i){
    bool can = true;
    for(int j = 0; j < t.size(); ++j){
      if(s[i+j] == t[j] || s[i+j] == '?') continue;
      else{can = false; break;}
    }
    if(can){
      string cop = s;
      rep(k, t.size()) cop[i+k] = t[k];
      rep(k, cop.size()) if(cop[k] == '?') cop[k] = 'a';
      if(ans == "UNRESTORABLE") ans = cop;
      else ans = min(ans, cop);
    }
  }
  cout << ans << "\n";
}  

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

int main(){
   int a,b,c,d;
   cin >> a >> b >> c >> d;
   for(int i=0; ; i++){
       int ahp = c - b*i;
       if(ahp <= 0) {
           cout << "Yes" << endl;
           return 0;
       }
           int thp = a - d*i;
           if(thp <= 0){
               cout << "No" << endl;
               return 0;
           }
       }
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long x, t;
    cin >> x >> t;
    if(x>t) {
        cout << x-t << endl;
    } else {
        cout << 0 << endl;
    }
}

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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};
using namespace std;

void solve(){
   string s,d;
   cin>>s>>d;
   string t = d+d;  
  if(t.find(s) != string::npos)cout<<"Yes";
  else cout<<"No"; 
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
int N;
std::vector<int> A;
int M;
int ans;
int main() {
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		A.push_back(tmp);
	}
	std::sort(A.begin(), A.end());
	for (int i = 0; i < N - 1; i++) {
		int tmp = A[i];
		if (A[i] > A[N - 1] / 2) {
			tmp = A[N - 1] - A[i];
		}
		if (tmp > M) {
			M = tmp;
			ans = A[i];
		}
	}
	std::cout << A[N - 1] << " " << ans << std::endl;
	return 0;
}

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


int main(){
    while(1){
        int n; cin >> n;
        if(n == 0) break;
        vector<int> S(n), T(n);
        vector<int> table(3600*24, 0);
        for(int i=0; i<n; i++){
            for(int j=0; j<2; j++){
                string time; cin >> time;
                int hh, mm, ss;
                hh=10*(time[0]-'0')+(time[1]-'0');
                mm=10*(time[3]-'0')+(time[4]-'0');
                ss=10*(time[6]-'0')+(time[7]-'0');
                if(j == 0) S[i]=3600*hh+60*mm+ss;
                else T[i]=3600*hh+60*mm+ss;
            }
            table[S[i]]++;
            table[T[i]]--;
        }
        for(int i=1; i<3600*24; i++){
            table[i]+=table[i-1];
        }
        int res=0;
        for(int i=0; i<3600*24; i++){
            res=max(res, table[i]);
        }
        cout << res << endl;
    }
    return 0;
}


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

using namespace std;

using ll = long long;

int Solve(const int n, const vector<int> &d) {
    set<int> seq;

    const int size = min(4, n);
    for (int len = 1; len <= size; ++len) {
        for (int i = 0; i + len <= n; ++i) {
            int num = 0;
            for (int j = i; j < i + len; ++j) {
                num *= 10;
                num += d[j];
            }
            seq.insert(num);
        }
    }

    if (*seq.begin() != 0) return 0;

    int bf = 0;
    for (const auto &x : seq) {
        if (1 < x - bf) {
            ++bf;
            break;
        }
        bf = x;
    }

    return bf;
}

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

    int n;

    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; ++i) cin >> d[i];

    cout << Solve(n, d) << endl;

    return 0;
}

Measured memory_bytes: 3300
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <utility>
typedef long long lint;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define INF 1e18


bool solve(int N, vector<int> L) {
	// 一番長い辺　< 他の合計 --> true
	sort(L.begin(),L.end());
	int maxl = L.back();
	int SUM = 0;
	rep(i,N) SUM += L[i];

	if (SUM - 2 * maxl > 0) return true;
	else return false;
}


signed main(){
	int N;
	cin >> N;
	vector<int> L(N);
	rep(i,N) cin >> L[i];

	bool r = solve(N,L);
	if (r) cout << "Yes" << endl;
	else cout << "No" << endl;




	return 0;
}

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

using namespace std;

#define pb push_back
#define sz(x) ((ll)x.size())
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ul;

const int mn = 1e5 + 5;
const int mod = 1e9 + 7;

string s;
int n, k;

ll cnt(string &s) {
	int c = 0;
	for (int i = 1; i < sz(s); i++) {
		if (s[i] == s[i - 1]) {
			c++;
			s[i] = 0;
		}
	}
	return c;
}

int main() {
	//cin.sync_with_stdio(0);
#ifdef LOCAL
	freopen("../1.txt", "r", stdin);
	//freopen("my.out", "w", stdout);
	size_t bg = clock();
#endif

	cin >> s >> k;
	string t = s + s;
	string tt = s + s + s;
	ll a = cnt(s);
	ll b = cnt(t);
	ll c = cnt(tt);

	ll ans = b * (k / 2) + a * (k % 2);
	if (c - b == b - a) ans = a + (c - b) * (k - 1);

	printf("%lld\n", ans);

#ifdef LOCAL
	size_t ed = clock();
	printf("time: %f\n", (double) (ed - bg) / CLOCKS_PER_SEC);
#endif
	return 0;
}

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

int main(){
  int N, i;
  scanf("%d", &N);
  long a[5]={0};
  char name[10];
  
  for(i=0;i<N;i++){
    scanf("%s", name);
    if(name[0]=='M')a[0]++;
    if(name[0]=='A')a[1]++;
    if(name[0]=='R')a[2]++;
    if(name[0]=='C')a[3]++;
    if(name[0]=='H')a[4]++;
  }
  
  long num=0;
  num+=a[0]*a[1]*a[2];
  num+=a[0]*a[1]*a[3];
  num+=a[0]*a[1]*a[4];
  num+=a[0]*a[2]*a[3];
  num+=a[0]*a[2]*a[4];
  num+=a[0]*a[3]*a[4];
  num+=a[1]*a[2]*a[3];
  num+=a[1]*a[2]*a[4];
  num+=a[1]*a[3]*a[4];
  num+=a[2]*a[3]*a[4];
  
  printf("%ld\n", num);
  
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int rome(char g) {
	switch (g) {
	case 'I':return 1;
	case 'V':return 5;
	case 'X':return 10;
	case 'L':return 50;
	case 'C':return 100;
	case 'D':return 500;
	case 'M':return 1000;
	default:return -1;
	}
}
int main() {
	string s;
	while (cin >> s) {
		int sum = 0;
		int i;
		for (i = 0; i < s.length() -1; i++) {
			if (rome(s[i]) < rome(s[i + 1])) {
				sum += rome(s[i + 1]) - rome(s[i]);
				i++;
				//cout << "sum += " << rome(s[i + 1]) - rome(s[i]) << "  ";
			}
			else {
				sum += rome(s[i]);
				//cout << "sum += " << rome(s[i]) << "  ";
			}
			//cout << "sum is " << sum << endl;
		}
		if (i == s.length() - 1)sum += rome(s[i]);
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 2996
def main():
    import sys
    input=sys.stdin.readline
    from collections import deque
    #class ctmp():
    #    def __init__(self,ij,dis):
    #        self.ij=ij
    #        self.dis=dis
    H,W=map(int,input().split())
    ls=["#"*(W+2)]#
    for i in range(H):
        ls.append("#"+input()+"#")
    ls.append("#"*(W+2))#
    q=deque([])
    #qd=deque([])
    #tmp=ctmp((1,1),0)
    q.append((1,1))
    #qd.append(0)
    #df={}
    lf=[[float("inf") for _ in range(W+2)] for _ in range(H+2)]#
    #これでfとdの両方の役割をこなす
    lf[1][1]=0
    while q:
        tmpij=q.popleft()
        #tmpd=qd.popleft()
        #df[tmpij]=1
        if tmpij==(H,W):
            break
        lind=[(-1,0),(1,0),(0,-1),(0,1)]#
        for i in range(4):
            #ntmpij=(tmpij[0]+(i<2)*(2*i-1),tmpij[1]+(i>1)*(2*i-5))
            ntmpij=(tmpij[0]+lind[i][0],tmpij[1]+lind[i][1])
            #print(ntmpij)
            #if ntmpij not in df and ls[ntmpij[0]][ntmpij[1]]==".":
            if lf[ntmpij[0]][ntmpij[1]]==float("inf") and ls[ntmpij[0]][ntmpij[1]]==".":
                #c_tmp=ctmp(ntmpij,tmp.dis+1)
                #q.append(c_tmp)
                q.append(ntmpij)
                #qd.append(tmpd+1)
                lf[ntmpij[0]][ntmpij[1]]=lf[tmpij[0]][tmpij[1]]+1
                #dは訪れる前に書き込んでしまう
    if tmpij==(H,W):
        nw=0
        for i in range(1,H+1):
            #for j in range(1,W+1):
             #   if ls[i][j]==".":
              #      nw+=1
            nw+=ls[i].count(".")
        #print(nw-tmpd-1)
        print(nw-lf[H][W]-1)
    else:
        print(-1)

if __name__=='__main__':
    main()


Measured memory_bytes: 3436
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 40) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> G(n);
    vector<int> in(n);
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
        in[a]++;
        in[b]++;
    }
    set<P> st;
    for(int i = 0; i < n; i++) {
        st.insert(P(in[i], i));
    }
    vector<int> vis(n);
    ll ans = 0;
    vector<ll> c(n);
    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }
    sort(all(c));
    vector<ll> res(n);
    for(int i = 0; i < n; i++) {
        auto it = st.begin();
        ans += c[i] * (*it).first;
        vis[(*it).second] = 1;
        res[(*it).second] = c[i];
        st.erase(it);
        for(auto& e : G[(*it).second]) {
            if(vis[e]) {
                continue;
            }
            st.erase(st.find(P(in[e], e)));
            in[e]--;
            st.insert(P(in[e], e));
        }
    }
    cout << ans << endl;
    cout << res;
}


Measured memory_bytes: 1792
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(lambda x:int(x)*-1,input().split())))
q=sorted(list(map(lambda x:int(x)*-1,input().split())))
r=sorted(list(map(lambda x:int(x)*-1,input().split())))
import heapq
v=p[:x]+q[:y]+r
heapq.heapify(v)
ans=0
for i in range(x+y):
  ans+=heapq.heappop(v)
print(-ans)

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

long long  count(long long  V){
    long long attack = 2;
    while(V >= attack){
        attack*=2;
    }
    return attack - 1;
}

int main () {
    long long H;
    cin >> H;
    cout << count(H) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
//#include<sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (int i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
/*

     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝

*/

int main()
{
    FastRead;
    string s;
    cin >> s;
    ll cnt = 0,cnt1=0;
    for (auto a:s)
    {
        if(a=='B')
        {
            cnt++;
        }
        else
        {
            cnt1+=cnt;
        }
    }
    cout<<cnt1<<endl;
    return 0;
}

Measured memory_bytes: 3788
#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
    cin >> s;
    const int n = s.size();
    long long ans = 0, formulasum, subsetsum, ten;
    bool b;
    for(int i = 0; i < (1 << n); i+=2){
        formulasum = 0, subsetsum = 0, ten = 1;
        b = 0;
        for(int j = 0; j < n; j++){
            if(b == ((i >> j) & 1)){
                subsetsum += (s[n-1 - j] - '0') * ten;
                ten *= 10;
            }
            else{
                formulasum += subsetsum;
                subsetsum = (s[n-1 - j] - '0');
                ten = 10;
                b = !b;
            }
        }
        formulasum += subsetsum;
        ans += formulasum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s.length()>26)
		cout<<"no\n";
	else
	{	
	bool c[26];
	for( int i=0;i<26;i++)
		c[i]=false;
	int i;
	for( i=0;i<s.length();i++)
	{
		if(c[s[i]-'a']==false)
			c[s[i]-'a']=true;
		else
			break;		
	}
	if(i==s.length())
		cout<<"yes\n";
	else
		cout<<"no\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <tuple>
#include <queue>

int main(int /*argc*/, char** /*argv*/)
{
	int N, M;
	std::cin >> N >> M;
	typedef std::multimap<int, int> MAP;
	MAP R;
	std::vector<int> num(N, 0);
	for (int i = 0; i < M; ++i) {
		int A, B;
		std::cin >> A >> B;
		R.insert(MAP::value_type(A-1,B-1));
		R.insert(MAP::value_type(B - 1, A - 1));
	}
	std::vector<int> rel(N, 0);
	std::queue<int> queue;
	int gr = 0;
	for (int i = 0; i < N; ++i) {
		if (rel[i] == 0) {
			++gr;
			rel[i] = gr;
			queue.push(i);
			while (!queue.empty()) {
				const int t = queue.front();
				queue.pop();
				auto range = R.equal_range(t);
				for (auto itr = range.first; itr != range.second; ++itr) {
					if (rel[itr->second] == 0) {
						rel[itr->second] = gr;
						queue.push(itr->second);
					}
				}
			}
		}
	}

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

	int val = -1;
	int count = 0;
	int max_count = 0;
	for (int i = 0; i < N; ++i) {
		if (rel[i] == val) {
			++count;
		}
		else {
			if (count > max_count) {
				max_count = count;
			}
			val = -1;
			count = 0;
			if (rel[i] > 0) {
				val = rel[i];
				count = 1;
			}
		}
	}
	if (count > max_count) {
		max_count = count;
	}

	std::cout << std::max<int>(max_count, 1) << std::endl;

	return 0;
}


Measured memory_bytes: 23656
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int x, a, b, n;
	cin >> x >> a >> b >> n;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if (s == "nobiro") {
			x = max(0, x + a);
		}
		else if (s == "tidime") {
			x = max(0, x + b);
		}
		else
		{
			x = 0;
		}
	}
	cout << x << endl;




	return 0;
}



Measured memory_bytes: 3224
a, b, c, d, e, f = map(int, input().split())

result = [0, 0]
noude = 0
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                water = a * 100 * i + b * 100 * j
                sugar = c * k + d * l
                if water == 0 or water + sugar > f:
                    break
                if (water / 100) * e >= sugar and noude < (100 * sugar) / (water + sugar):
                    noude = (100 * sugar) / (water + sugar)
                    result = [water + sugar, sugar]

if result[1] == 0:
    print(a * 100, 0)
else:
    print(result[0], result[1])


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define SIZE 100005

using namespace std;
typedef long long ll;

int main() {
	int n, k;
	ll ans = INF, x[SIZE];
	cin >> n >> k;

	REP(i, n) { cin >> x[i]; }

	int count = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (x[i] <= 0) {
			count++;
		}
		if (count >= k) {
			ans = min(ans, abs(x[i]));
		}
	}
	//debug(ans)

		count = 0;
	REP(i, n) {
		if (x[i] >= 0) {
			count++;
		}
		if (count >= k) {
			ans = min(ans, x[i]);
		}
	}
	//debug(ans)

		int l = 0,
			r = k - 1;
	while (1) {
		if (x[l] <= 0 && x[r] >= 0) {
			ans = min(ans, 2 * abs(x[l]) + abs(x[r]));
			ans = min(ans, 2 * abs(x[r]) + abs(x[l]));
			//debug(ans)
		}
		l++;
		r++;
		if (r >= n) break;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
import Data.List

concat' :: [String] -> String
concat' (x:[]) = x
concat' (x0:x1:xs) = concat' ((x0++"\n"++x1):xs)

ans' x =
  let w = map words x
      s = map (\(n:w:l:d:_) -> (n, 3*read(w)+1*read(d)) ) w
      z = zip [1..] s
      a = sortBy (\(z0,(n0,s0)) (z1,(n1,s1)) -> let c = compare s1 s0
                                                in if c == EQ
                                                   then compare z0 z1
                                                   else c ) z
  in
    unlines $ map (\(_,(n,s)) -> n++","++show(s)) a

ans (n:x) =
  let n' = read n :: Int
      d  = take n' x
      r  = drop n' x
  in
    if n' == 0
    then []
    else (ans' d):(ans r)

main = do
  c <- getContents
  let i = lines c
      o = ans i
  putStr $ concat' o

Measured memory_bytes: 4096
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
ll x,k,d;
int main() {
  cin>>x>>k>>d;
  if (x<0) x=-x;
  if (x/k>=d) return cout<<x-k*d<<endl,0;
  ll net=x%d,xp=k-x/d;
  if (xp&1) cout<<d-net<<endl;
  else cout<<net<<endl;
}

Measured memory_bytes: 3632
import math

num = int(input())
co = []

for i in range(num):
    co.append(list(map(int, input().split())))

#print(co)
pat = math.factorial(num)
#print(pat)
num -= 1
dis = 0

for i in range(num):
    for j in range(num):
        dis += math.sqrt((co[i][0]-co[j+i+1][0])**2 + (co[i][1]-co[j+i+1][1])**2)
        if num == j+i+1: break

dis *= 2/(num+1)

print(dis)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		
		Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        
        int i = Integer.parseInt(str);
        
        if (1 <= i && i <= 1000000) {
        	if (i % 2 == 0) {
        		i = i / 2 - 1;
        	} else {
        		i = (i - 1) / 2;
        	}
        	System.out.println(i);
        }
        return;
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n;
  std::cin >> n;

  vector<int> a(n);
  for(int i=0; i<n; i++){
    std::cin >> a[i];
  }

  int ans = 0;
  for(int i=0; i<n; i+=2){
    if(a[i] % 2 == 1){
      ans += 1;
    }
  }

  std::cout << ans << '\n';
  return 0;
}


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

void toarr(int in,int len,vector<int> &v)
{
    for(int i=(int)pow(10,len-1);i>0;i/=10){
    	v.push_back(in/i);
    	in=in-in/i*i;
    }
}

int fromarr(vector<int> v)
{
    int num=1,sum=0;
    for(int i=0; i<v.size(); i++) {
        sum+=v[i]*num;
        num*=10;
    }
    return sum;
}

int main()
{
    for(;;) {
        int a,l;
        cin>>a>>l;
        if(l==0&&a==0)break;

        vector<int> ai;
        ai.push_back(a);

        bool end=false;
        //int count=1;
        while(!end) {
            vector<int> v;
            int min_num,max_num;
            toarr(a,l,v);
            sort(v.begin(),v.end());
            max_num=fromarr(v);
            sort(v.begin(),v.end(),greater<int>());
            min_num=fromarr(v);
            a=max_num-min_num;
            //cout<<"a["<<count<<"]: "<<a<<endl;
            //count++;

            for(int i=0; i<ai.size(); i++) {
                if(a==ai[i]) {
                    end=true;
                    cout<<i<<" "<<a<<" "<<ai.size()-i<<endl;
                    break;
                }
            }
            ai.push_back(a);
        }

        
    }
    return 0;
}

Measured memory_bytes: 1264
S = input()
ans = [0] * len(S)
t = [0, 0]
for i, s in zip(range(len(S)), S):
  if s == "R":
    t[i%2] += 1
  else:
    ans[i] += t[i%2]
    ans[i-1] += t[1-i%2]
    t = [0, 0]
for i, s in zip(range(len(S)-1, -1, -1), S[::-1]):
  if s == "L":
    t[i%2] += 1
  else:
    ans[i+1] += t[1-i%2]
    ans[i] += t[i%2]
    t = [0, 0]
print(*ans)

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
int n,ans,maxx;   
int a[100005],shu[100005];   
int main(){
    cin >> n;  
    for(int i = 1;i <= n;i++){
        cin >> a[i]; 
        shu[a[i]]++; 
        if(a[i] > maxx) maxx = a[i];  
    }
    for(int i = 1;i <= maxx;i++)
        if(shu[i] > 1)   
    ans += shu[i] - 1; 
    if(ans % 2 == 1) ans++;   
    cout << n - ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    long n, d;
    cin >> n >> d;
    long ans = 0;
    for (long i = 0; i < n; i++) {
        long x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d) {
            ans += 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n;
ll pref[N],v[N];
int main(){
  scanf("%d",&n);
  for(int i = 0 ; i < n ;++i)
    cin>>v[i];
  ll sum = 0;
  ll ans = 0;
  map<ll,int> see;
  for(int i = 0 ; i < n ;++i){
    sum+=v[i];
    if(sum ==0)++ans;
    ans+=see[sum];
    see[sum]++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 14336
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
int main()
{
    fast;
    int a[]={1,3,5,7,8,10,12};
    int b[]={4,6,9,11};
    int c[]={2};
    int x,y;
    cin>>x>>y;
    if(x==2||y==2)
    {
        pr(0);
        return 0;
    }
    int cn=0;
    for(int i=0;i<7;i++)
    {
        if(a[i]==x) cn++;
        if(a[i]==y) cn++;
    }
    if(cn==2)
    {
        pr(1);
        return 0;
    }
    cn=0;
    for(int i=0;i<4;i++)
    {
        if(b[i]==x)cn++;
        if(b[i]==y) cn++;
     }
     if(cn==2) pr(1);
     else pr(0);
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int parent,left,right;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u, int d){
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right, d+1);
}

int setHeight(int u) {
  int h1=0,h2=0;
  if(T[u].left != NIL) h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  int deg = 0;
  printf("node %d: " ,u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  }
  else if(T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root=0,i;
  scanf("%d" ,&n);

  for(i=0 ; i<n ; i++) T[i].parent = NIL;

  for(i=0 ; i<n ; i++) {
    scanf("%d %d %d" ,&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(i=0 ; i<n ; i++)
    if(T[i].parent == NIL)
      root = i;

  setDepth(root, 0);
  setHeight(root);

  for(i=0 ; i<n ; i++) print(i);

  return 0;
}
  



Measured memory_bytes: 2048
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

struct uf
{
    // abc157
    int n;
    vector<int> par, tree_size;

    uf(int size) : n(size), par(), tree_size(size, 1)
    {
        par.reserve(size);
        rep(i, size)
        {
            par.push_back(i);
        }
    }

    int root(int u)
    {
        if (u == par[u])
        {
            return u;
        }
        return par[u] = root(par[u]);
    }

    void unite(int u, int v)
    {
        u = root(u);
        v = root(v);
        if (u == v)
        {
            return;
        }
        par[v] = u;
        tree_size[u] += tree_size[v];
    }

    bool same(int u, int v)
    {
        return root(u) == root(v);
    }

    int component_size(int u)
    {
        u = root(u);
        return tree_size[u];
    }
};

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

    int n, m;
    cin >> n >> m;
    uf g(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g.unite(a,b);
    }
    int ans = 0;
    rep(i, n)
    {
        chmax(ans, g.component_size(i));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4948
N = gets.to_i
a = gets.split.map(&:to_i)
sum = 0
h = Hash.new(0)
h[0] += 1
a.each do |ai|
  sum += ai
  h[sum] += 1
end
ans = 0
h.each do |i, cnt|
  next if cnt < 2
  ans += (cnt * (cnt - 1)) / 2
end

p ans


Measured memory_bytes: 29060
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define INF 1000000000
typedef long long ll;
ll memo[25];

ll dfs(int n) {
    if (memo[n] > 0) return memo[n];
    if (n == 0 || n == 1) return 1;
    else return memo[n] = n * dfs(n-1);
}

int main(void) {
    int n;
    cin >> n;
    cout << dfs(n) << endl;
    return 0;
}

Measured memory_bytes: 1156
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}
	sort.Ints(h)

	ans := 0
	for i := n - 1; i >= 0; i-- {
		if k > 0 {
			k--
			continue
		}
		ans += h[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7424
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int [] a=new int [26];
		while(sc.hasNextLine()) {
String str=sc.nextLine();
if(str.equals(""))break;
String str1=str.toLowerCase();
char [] ch=str1.toCharArray();
for(int i=0;i<ch.length;i++) {
	for(int j='a';j<='z';j++) {
		if(j==ch[i]) {
			a[j-97]+=1;
		}
	}
}
		}
for(int k='a';k<='z';k++) {
	char c=(char)k;
	System.out.println(c+" : "+a[k-97]);
}
		sc.close();
	}
}


Measured memory_bytes: 26160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String s = in.next();
        int c[] = new int[n];

        int count = 0;
        c[0] = count;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                count++;
            }
            c[i] = count;
        }

        for (int i = 0; i < q; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;
            System.out.println(c[r] - c[l]);
        }
    }
}

Measured memory_bytes: 65224
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200005];
	scanf("%s",s);
	int i;
	double ans=0;
	double x=0;
	for(i=0;i<strlen(s);i++)
	{
		if(s[i]=='W')
		   ans+=x;
		else
		   x++;
	}
	printf("%.0lf\n",ans);
	return 0;
}

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

bool dp[2001];

int main()
{
    memset(dp, false, 2001);
    dp[0] = true;
    int n = 0;
    cin >> n;
    for (int i = 0; i != n; ++i){
        int a = 0;
        cin >> a;
        for (int j = 2000; j - a >= 0; --j){
            if (dp[j - a]) dp[j] = true;
        }
    }
    
    int q = 0;
    cin >> q;
    for (int i = 0; i != q; ++i){
        int m = 0;
        cin >> m;
        if (dp[m]){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    int arr[n];
    for (int i=0;i<n;i++)
    cin>>arr[i];

    int f[n];
    for (int i=0;i<min(n,k);i++)
    f[i]=abs(arr[i]-arr[0]);
    for (int i=k;i<n;i++)
    {
        int val = 1000000000;
        for (int j=i-1,l=0;l<k;j--,l++)
        {
            val = min(val,abs(arr[j]-arr[i])+f[j]);
        }
        f[i]=val;
    }
    cout<<f[n-1];
    return 0;
}

Measured memory_bytes: 4416
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		double[] v = new double[n];
		for (int i = 0; i < v.length; i++) {
			v[i] = sc.nextDouble();
		}
		Arrays.sort(v);

		double ans = (v[0] + v[1]) / 2;
		if(n >= 3) {
			for (int i = 2; i < n; i++) {
				ans = (ans + v[i]) / 2;
			}
		}

		System.out.printf("%.6f", ans);
	}
}

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

using namespace  std;

const int N = 1e5 + 4;

bool visited[N] , visited2[N];



int main() {
    int n , m;
    int ac = 0 , pen;
    cin>>n>>m;
    vector<pair<int , string> >vs;
    set<int>vc;
    for(int i = 0 ; i < m ; ++i){
        int x;
        string sub; cin>>x>>sub;
        if(!visited[x] && sub == "AC"){
            ac++;
            visited[x] = 1;
            vc.insert(x);
        }
        vs.emplace_back(x , sub);
    }
    for(auto i : vs){
        if(i.second != "AC" && !visited2[i.first] && visited[i.first]){
            pen++;
        }
        if(i.second == "AC" && !visited2[i.first]){
            visited2[i.first] = 1;
        }
    }
    for(auto i : vs){
    }
    cout<<ac<<" "<<pen<<"\n";
}

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k;
    cin >> k;
    ll ans=0;
    ll tmp;
    for(ll i = 1; i <= k; i++) {
    for(ll j = 1; j <= k; j++) {
    for(ll l = 1; l <= k; l++) {
        tmp=__gcd(i,__gcd(j,l));
        ans+=tmp;
    }
    }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main()
{
  int n,m;
  cin >> n >> m;
  long pos=0;
  if(n>1)
  {
    pos+=(n*(n-1)/2);
  }
  if(m>1)
  {
    pos+=m*(m-1)/2;
  }
  cout << pos << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define se second
#define fi first
using namespace std;
const int maxn = 1e3 + 4, mod = 1e9 + 7;
typedef pair<int,int> ii;
typedef pair<long long, long long> ll;
vector<int> ans;

void _accepted_by_one_hit_()
{
    #ifdef NTMA
        freopen("abc.inp", "r", stdin);
        freopen("abc.out", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

bool ok(string s)
{
      string t = s;
      reverse(s.begin(), s.end());
      return (s == t);
}

int main()
{
      _accepted_by_one_hit_();

      string s; 
      cin >> s;
      if (ok(s)) {
            int n = s.size();
            string t = "";
            for(int i=0; i<(n-1)/2; ++i) t += s[i];
            if (ok(t)) {
                  string c = "";
                  for(int i=(n+3)/2-1; i<n;++i) c += s[i];
                  if (ok(c)) {
                        cout << "Yes";
                        return 0;
                  }
            }
      }
      cout << "No\n";
      return 0;
      
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

def euclid(a, b):
    c,d = sorted([a, b])
    r = 1
    while (r > 0):
        r = d % c
        c,d = r,c
    return d

for i in range(n-1):
    if i == 0:
        ans = a[0]
    ans = euclid(ans, a[i+1])
print(ans)

Measured memory_bytes: 14252
{-# LANGUAGE ScopedTypeVariables #-}

import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad

-- Union-Find
type Parent = VUM.IOVector Int

makeUF :: Int -> IO Parent
makeUF n = do
    par <- VU.unsafeThaw $ VU.generate n id
    return par

root :: Int -> Parent -> IO Int
root x par = do
    r <- VUM.read par x
    if x == r
        then return x
        else do
            newr <- root r par
            VUM.write par x newr
            return newr

same :: Int -> Int -> Parent -> IO Bool
same x y par = do
    rx <- root x par
    ry <- root y par
    return $ rx == ry

unite :: Int -> Int -> Parent -> IO ()
unite x y par = do
    x' <- root x par
    y' <- root y par
    when (x' /= y') $ VUM.write par x' y'

main = do
    [n,m,k] <- map read . words <$> getLine :: IO [Int]
    uf <- makeUF (n+1)
    (fre :: VUM.IOVector Int) <- VUM.replicate (n+1) 0
    (blo :: VUM.IOVector Int) <- VUM.replicate (n+1) 0
    (rt:: VUM.IOVector Int) <- VUM.replicate (n+1) 0
    replicateM_ m $ do
        [a,b] <- map read . words <$> getLine :: IO [Int]
        unite a b uf
        VUM.modify fre (+1) a
        VUM.modify fre (+1) b
    replicateM_ k $ do
        [c,d] <- map read . words <$> getLine :: IO [Int]
        branch <- same c d uf
        when branch $ do
            VUM.modify blo (+1) c
            VUM.modify blo (+1) d
    forM_ [1..n] $ \i -> do
        r <- root i uf
        VUM.modify rt (+1) r
    forM_ [1..n] $ \i -> do
        r <- root i uf
        vs <- VUM.read rt r
        f <- VUM.read fre i
        b <- VUM.read blo i
        putStr $ show (vs - f - b - 1)
        putStr " "
    putStrLn ""


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int MOD = 1e9 + 7;
#define INF ((1<<30)-1)
#define LINF (1LL<<30)

int n,m;
vector<vector<int> > G;

int dp[100100];
int rec(int v) {
    if (dp[v] != -1) return dp[v];
    int res = 0;
    for (int nv : G[v]) {
        res = max(res,rec(nv)+1);
    }
    return dp[v] = res;
}
int main() {
    cin >> n >> m;
    G.assign(n,vector<int>());
    for (int i = 0; i < m; i++) {
        int x,y;
        cin >>x >> y;
        x--;y--;
        G[x].push_back(y);
    }
    rep(i,n) dp[i] = -1;
    int res = 0;
    rep(v,n) res = max(res,rec(v));
    cout << res << endl;
    
}

Measured memory_bytes: 8192