akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;


vector<pair<int,int>> k;
        signed main() {
     string s;
     cin>>s;
     vector<int> hen[s.size()];
     int sc[s.size()+1],b=0;
     map<int,int> m;
     for(int i=0;i<s.size();i++){
             sc[i]=b;
           
             b^=1<<(s[i]-'a');
             
     }
       m[b]=s.size();
     for(int i=s.size()-1;i>=0;i--){
             for(int j=0;j<='z'-'a';j++){
                     auto it=m.find(sc[i]^(1<<j));
                     if(it!=m.end())hen[i].push_back(it->second);
             }
             m[sc[i]]=i;
     }

     queue<int> que,que2;
     int c=0;
     que.push(0);
     while(true){
             if(que.empty()){
                     swap(que,que2);
                     c++;
             }
             if(que.front()==s.size()||sc[que.front()]==b){
                     cout<<max(1ll,c);
                     return 0;
             }
             if(sc[que.front()]==-1){
                     que.pop();
                     continue;
             }
             //cerr<<que.front()<<' '<<c<<endl;
             sc[que.front()]=-1;
             for(int i=0;i<hen[que.front()].size();i++)que2.push(hen[que.front()][i]);
             que.pop();
     }

      
        


      }


        


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

using namespace std;

int main() {
  string S;
  
  cin >> S;
  
  vector<vector<char>> status(2, vector<char>(0, 0));
  
  if (S.length() == 1) {
    cout << 0 << endl;
    
    return 0;
  }
  
  int ans = 0;
  
  for (int i = 0; i < S.length(); i++) {
    status[0].push_back(i % 2 == 0 ? '0' : '1');
    status[1].push_back(i % 2 == 1 ? '0' : '1');
  }
  
  int a = 0, b = 0;
  
  for (int i = 0; i < S.length(); i++) {
    if (S[i] != status[0][i]) {
      a++;
    }
    
    if (S[i] != status[1][i]) {
      b++;
    }
  }
  
  cout << min(a, b) << endl;
  
  return 0;
}

Measured memory_bytes: 640
void main() {
	auto A = ri, B = ri;
	writeln(6-(A+B));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

// べき乗の剰余
lint modpow(lint x, lint y, lint m) {
    if (y == 0) return 1;
    lint res = modpow(x, y / 2, m);
    return res * res % m * (y & 1 ? x : 1) % m;
}

int main(void) {
    int n;
    cin >> n;
    vector<int> x(n + 1);
    repeat(i, n + 1) cin >> x[i];
    
    int twice;
    vector<bool> a(n + 1, false);
    repeat(i, n + 1) {
        if (!a[x[i]]) {
            a[x[i]] = true;
        }
        else {
            twice = x[i];
            break;
        }
    }
    
    int former = 0;
    //int middle = 0;
    int latter = 0;
    bool flg = false;
    repeat(i, n + 1) {
        if (x[i] == twice) {
            if (!flg) {
                former = i;
                flg = true;
            }
            else {
                //middle = i - former - 1;
                latter = n - i;
            }
        }
    }
    
    const int MOD = 1e9 + 7;
    vector<lint> fact(n+2, 0), inv(n+2, 0);
    fact[0] = inv[0] = 0;
    fact[1] = 1;
    repeat_from_to (i, 2, n+1) {
        fact[i] = fact[i-1] * i;
        fact[i] %= MOD;
    }
    repeat_from_to (i, 1, n+1) {
        inv[i] = modpow(fact[i], MOD-2, MOD);
    }
    
    auto comb = [&fact, &inv] (lint x, lint y, lint m) -> lint {
        if (x < y || x < 0 || y < 0) return 0;
        if (x == y || y == 0) return 1;
        lint t = (fact[x] * inv[y]) % m;
        lint ret = (t * inv[x-y]) % m;
        return ret;
    };
    
    repeat_from_to (i, 1, n+1) {
        lint t = comb(n+1, i, MOD) + MOD;
        lint s = comb(former+latter, i-1, MOD);
        cout << (t-s)%MOD << endl;
    }
    return 0;
}   

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define rep(i,n) for((int) (i)=0;(i)<(int)(n);(i)++)
#define mp make_pair
#define pb push_back
using namespace std;
int n;
long long ans=0;
string s;
map<vector<int>,long long> mp2;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		vector<int> v(26);
		for(int j=0;j<10;j++)
		{
			v[s[j]-'a']++;
		}
		mp2[v]++;
	}
	for(map<vector<int>,long long> ::iterator it=mp2.begin();it!=mp2.end();it++)
	{
		if(it->second!=1)
		ans+=(it->second)*(it->second-1)/2;
	}
	cout<<ans;
	return 0;
}


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

int main(){
    int N, M, X;
    cin >>N >> M >> X;
    
    int A[110];
    for(int i = 0; i < M; i++) cin >> A[i];

    int lower = 0;
    int upper = 0;
    for(int i= 0; i < M; i++) {
        if(A[i] < X) lower++;
        else if(A[i] > X) upper++;
    }
    cout << min(lower, upper) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

int main(){
    int a[3][3];
    int n,i,j,k;
    rep(i,3){
        rep(j,3){
            cin>>a[i][j];
        }
    }
    cin>>n;
    vector<int> b(n);
    rep(i,n){
        cin>>b[i];
        rep(j,3){
            rep(k,3){
                if(b[i]==a[j][k]) a[j][k]=-1;
            }
        }
    }
    
    if( (a[0][0]==-1 && a[0][1]==-1 && a[0][2]==-1) || (a[1][0]==-1 && a[1][1]==-1 && a[1][2]==-1) || (a[2][0]==-1 && a[2][1]==-1 && a[2][2]==-1) || (a[0][0]==-1 && a[1][0]==-1 && a[2][0]==-1) || (a[0][1]==-1 && a[1][1]==-1 && a[2][1]==-1) || (a[0][2]==-1 && a[1][2]==-1 && a[2][2]==-1) || (a[0][0]==-1 && a[1][1]==-1 && a[2][2]==-1) || (a[2][0]==-1 && a[1][1]==-1 && a[0][2]==-1)) cout<<"Yes";
    else cout<<"No";
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#define min(a,b) a < b ? a : b
int main() {
  int a[3],min=200,i,j;
  scanf("%d%d%d", &a[0], &a[1], &a[2]);
  for(i=0;i<3;i++){
    for(j=i+1;j<3;j++){
      if((a[i]+a[j])<min){
	min=a[i]+a[j];
      }
    }
  }
  printf("%d\n",min);
  
  return 0;
}


Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <stack>
#include <iostream>
#include <vector>
using namespace std;
int main() {
	//入力
	double x[10];
	string u[10];
	int N, ans =111, t = 0;
	cin >> N;
	//処理
	if (111 < N && N <= 222) ans = 222;
	else if (222 < N && N <= 333) ans = 333;
	else if (333 < N && N <= 444) ans = 444;
	else if (444 < N && N <= 555) ans = 555;
	else if (555 < N && N <= 666) ans = 666;
	else if (666 < N && N <= 777) ans = 777;
	else if (777 < N && N <= 888) ans = 888;
	else if (888 < N && N <= 999) ans = 999;
	//出力
	cout << ans << endl;
}

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

using namespace std;
template<typename T> void in(T &x) { x = 0; bool neg = false; register T c = getchar(); if (c == '-')neg = true, c = getchar(); while ((c < 48) || (c > 57))c = getchar(); for (; c < 48 || c > 57; c = getchar()); for (; c > 47 && c < 58; c = getchar())x = (x << 3) + (x << 1) + (c & 15); if (neg) x *= -1; }
template<typename T> void out(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); }
template<typename T> void outln(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); putchar('\n'); }
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define fastIO ios_base::sync_with_stdio(false); cin.tie(false);
#define ll long long
#define itr(_c) for(auto i=_c.begin();i!=_c.end();i++)
#define itrr(_c)for(auto i=_c.begin();i!=_c.end();i++)
#define f1(_x)for (int i = 0; i < _x; ++i)
#define fr(_x)for (int i = _x; i >0; i--)
#define f2(_x,_y)for (int i = _x; i < _y; ++i)
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi; typedef vector<string> vs; typedef vector<bool> vb; vector<long long>vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;

template<typename T>
T gcd(T __m, T __n)
{
	while (__n != 0)
	{
		T __t = __m % __n;
		__m = __n;
		__n = __t;
	}
	return __m;
}
vi v,vv;
int main() {	
	int n, k, t; in(n); in(k);
	while (n--) { in(t); v.push_back(t); }
	int fac=accumulate(v.begin(), v.end(),*v.begin(), gcd<int>);
	int mxele = (*max_element(v.begin(), v.end()) - k);
	std::cout << (mxele<0?"IMPOSSIBLE":mxele%fac==0?"POSSIBLE":"IMPOSSIBLE");
	
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  cout<<count(ALL(s),'1')<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        }
        catch(Exception e) {}
    }
}

Measured memory_bytes: 65520
N = gets.to_i
A = gets.split(' ').map(&:to_i)

average = A.inject(0){|s, a| s + a }.to_f / N
diff_list = A.map{|a| { value: a, diff: (a-average).abs}}.sort_by{|a| a[:diff] }
warn diff_list
targets = diff_list.find_all{|a| a[:diff] == diff_list[0][:diff ]}.map{|a| a[:value]}
warn targets
puts A.find_index{|a| targets.include?(a)}

Measured memory_bytes: 1788
/*  ex7_3
    hangan2020 */

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int H, W; // Matrix's height and width
    int i, j;
    char **pmatrix;

    scanf("%d %d", &H, &W);

    // Allocate memory for pointer to matrix's rows (one extra row for later use)
    pmatrix = (char**)calloc(H + 1, sizeof(char*));
    if(pmatrix == NULL){
        exit(1);
    }

    // Allocate memory for matrix's elements (through rows with size = width + 1 ; one extra width for later use) 
    for( i = 0; i < H + 1; i++){
        pmatrix[i] = (char*)calloc(W + 1, sizeof(char));
        if(pmatrix[i] == NULL){
            exit(1);
        }
    }

    //Input by loop
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            scanf(" %c", &pmatrix[i][j]);
        }
    }

    // Scanning for '.' only rows
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            if(pmatrix[i][j] != '.'){
                break;
            }
            else if((j == W-1)&&(pmatrix[i][j] == '.')){
                pmatrix[i][W] = 'n';// Mark n(for none) at end of row
            }
        }
    }
    // Scanning for '.' only columns
    for (j = 0; j < W ; j++){
        for(i = 0; i < H ; i++){
            if(pmatrix[i][j] != '.'){
                break;
            }
            else if((i == H-1)&&(pmatrix[i][j] == '.')){
                pmatrix[H][j] = 'n';// Mark n(for none) at end of column
            }
        }
    }

    //Printing out by loop ( except for rows or columns that starts with 'n')
    for (i = 0; i < H ; i++){
        if(pmatrix[i][W] != 'n'){
            for(j = 0; j < W ; j++){
                if(pmatrix[H][j] != 'n'){
                    printf("%c", pmatrix[i][j]);
                }
            }
        printf("\n");
        }
    }

    //Free allocated memories for elements
    for(i = 0; i < H; i++){
        free(pmatrix[i]);
    }
    //Free allocated memoties for row's pointers
    free(pmatrix);

    return 0;
}


Measured memory_bytes: 1632
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
	int X = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
	return w ? -X : X;
}

int dat[100005];
int dp[100005];
int main() 
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>dat[i];
	}
	for(int i=1;i<=100000;i++)
	{
		dp[i]=INF;
	}
	dp[1]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			dp[i+j]=min(dp[i+j],dp[i]+abs(dat[i+j]-dat[i]));
			dp[i+j]=min(dp[i+j],dp[i]+abs(dat[i+j]-dat[i]));
		}
	}
	cout<<dp[n];
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define llint long long
#define pii pair<int, int>
#define UNVISITED -1


int main() {
	ll X, K, D; scanf("%lld %lld %lld", &X, &K, &D);
	X = abs(X);
	ll K0 = X/D;
	ll ans = -1;
	if(K0 > K) {
		ans = X - K*D;
	}
	else {
		X = X - K0*D;
		K -= K0;
		ll v1 = X;
		if(K == 0) ans = v1;
		else {
			ll v2 = abs(X - D);
			if(K%2 == 0) ans = v1;
			else ans = v2;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Segment_Tree{
	private:
	int n;
	vi date;
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]+=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=date[k*2+1]+date[k*2+2];
		}
	}
	int Query(int a,int b){
		a+=n-1;b+=n-1;
		int m=0;
		while(a<b){
			if(a%2==0) m+=date[a++];
			if(b%2==0) m+=date[--b];
			a/=2;b/=2;
		}
		return m;
	}
	int Open(int k){return date[k+n-1];}
};

ll n,a,b;

int main(){
	cin>>n>>a>>b;
	if((b-a)%2==0) cout<<(b-a)/2<<endl;
	else cout<<min(a,n-b+1)+(b-a-1)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  int colors=3;
  for(int i=0;i<N;i++){
    string color;
    cin>>color;
    if(color=="Y"){
      colors++;
      break;
    }
  }
  if(colors==3)cout<<"Three"<<endl;
  else cout<<"Four"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(h + 1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= h; j++) {
            chmin(dp[i + 1][j], dp[i][j]);
            if (j >= a[i]) {
                chmin(dp[i + 1][j], dp[i + 1][j - a[i]] + b[i]);
            }
            if (j + a[i] >= h && j < h) {
                chmin(dp[i + 1][h], dp[i + 1][j] + b[i]);
            }
        }
    }
    cout << dp[n][h] << endl;
}


Measured memory_bytes: 39424
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = inf
count = 0

n=int(input())
A=list(map(int,input().split()))
for num in range(-100,101):
    tmp=0
    for ai in A:
        tmp+=(num-ai)**2
    ans=min(ans,tmp)
print(ans)        


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

int main() {
  int B,R,i,j;
  cin>>B;
  vector<int> count(B,1);
  vector<string> vecB(B);
  for(i=0;i<B;i++)cin>>vecB.at(i);
  cin>>R;
  vector<string> vecR(R);
  for(i=0;i<R;i++)cin>>vecR.at(i);
  
  for(i=1;i<B;i++){
    for(j=0;j<i;j++){
      if(vecB.at(i)==vecB.at(j)){
        count.at(i)+=count.at(j);
        vecB.at(j)="";
        count.at(j)=0;
      }
    }
  }
  for(i=0;i<B;i++){
    for(j=0;j<R;j++){
      if(vecR.at(j)==vecB.at(i)){
        count.at(i)--;
      }
    }
  }
  int n=0;
  for(i=0;i<B;i++){
    if(n<count.at(i))n=count.at(i);
  }
  cout<<n<<endl;
        
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int main()
{
	int a, b;
	cin >> a >> b;
	int sa = b - a, sum = 0;
	for (int i = 1; i <= b - a; i++) {
		sum += i;
	}
	cout << sum - b << endl;
	return 0;
}

Measured memory_bytes: 256
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pb push_back
# define int ll

# define pdd pair < db , db >
int32_t main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static ll s[1 << 20];
    static int t1[1 << 20];
    static int t2[1 << 20];
    int n;
    ll a,b;
    const int mod = 1e9 + 7;
    auto U1 = [&](int i,int v)
    {
        ++i;
        for (;i <= n + 1;i += i&(-i))
            (t1[i] += v) %= mod;
    };
    auto U2 = [&](int i,int v)
    {
        ++i;
        for (;i <= n + 1;i += i&(-i))
            (t2[i] += v) %= mod;
    };
    auto Q1 = [&](int i)
    {
        int ans = 0;
        ++i;
        for (;i;i -= i&(-i))
            (ans += t1[i]) %= mod;
        return ans;
    };
    auto Q2 = [&](int i)
    {
        int ans = 0;
        ++i;
        for (;i;i -= i&(-i))
            (ans += t2[i]) %= mod;
        return ans;
    };
    fi>>n>>a>>b;
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    static int D1[1 << 20];
    static int D2[1 << 20];
    s[0] = -1e18;
    D1[0] = D2[0] = 1;
    int p1 = 0,p2 = 0,p3 = 0,p4 = 0;
    U1(0,1);
    U2(0,1);
    set < int > s1,s2;
    s1.insert(0);
    s2.insert(0);
    for (int i = 1;i <= n;++i)
    {
        int A = 0;
        int B = 0;
        while (s[i] - s[p1 + 1] >= a) ++p1;
        while (s[i] - s[p2 + 1] >= b) ++p2;
        if (min(p2,i - 2) >= 0)
            B = Q1(min(p2,i - 2));
        if (min(p1,i - 2) >= 0)
            A = Q2(min(p1,i - 2));
        if (s[i] - s[i - 1] < a)
            {
                while (!s1.empty() && *s1.begin() < i)
                {
                    int cnt = *s1.begin();
                    U1(cnt,(mod - D1[cnt]) % mod);
                    D1[cnt] = 0;
                    s1.erase(s1.begin());
                }
            }
        if (s[i] - s[i - 1] < b)
            {
                while (!s2.empty() && *s2.begin() < i)
                {
                    int cnt = *s2.begin();
                    U2(cnt,(mod - D2[cnt]) % mod);
                    D2[cnt] = 0;
                    s2.erase(s2.begin());
                }
            }
        D1[i - 1] = (D1[i - 1] + A) % mod;
        D2[i - 1] = (D2[i - 1] + B) % mod;
        s1.insert(i - 1);
        s2.insert(i - 1);
        U1(i - 1,A);
        U2(i - 1,B);
    }
    int ans = 0;
    for (int i = 0;i <= n;++i)
        ans = (ans + D1[i]) % mod,
        ans = (ans + D2[i]) % mod;
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


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

int main(void) {
  int n;
  cin >> n;
  vector<long long> cs(n);

  for (int i = 1; i <= 1000; i++) {
    for (int j = 1; j <= 1000; j++) {
      for (int k = 1; k <= 1000; k++) {
        long long v = (i + j + k) * (i + j + k) - i * j - j * k - k * i;
        if (v > n) break;
        cs[v - 1]++;
      }
    }
  }

  for (const long long &c : cs) cout << c << endl;
  return 0;
}

Measured memory_bytes: 3708
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

dp = [[0] * 3 for _ in range(n+1)]

for i in range(1, n+1):
    dp[i][0] = abc[i-1][0] + max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = abc[i-1][1] + max(dp[i-1][0], dp[i-1][2])
    dp[i][2] = abc[i-1][2] + max(dp[i-1][0], dp[i-1][1])

print(max(dp[n]))


Measured memory_bytes: 47380
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector < vector <int> > vvi;
const int HUGEI = 2147483647;  // (1 << 31) - 1
const ll HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

// int find_l(vector <int> an, int i) {
//     int l = -1;
//     for (int k = 0; k < i; k++) {
//         if (an[k] < an[i]) l = k;
//     }
//     return l;
// }

int find_l(set <int> &visited_i, int i) {
    auto pl = visited_i.upper_bound(i);
    if (pl == visited_i.begin()) return -1;
    pl--;
    return *pl;
}

// int find_r(vector <int> an, int i) {
//     int r = an.size();
//     for (int k = an.size() - 1; k >= i + 1; k--) {
//         if (an[k] < an[i]) r = k;
//     }
//     return r;
// }

int find_r(set <int> &visited_i, int i, int n) {
    auto pr = visited_i.lower_bound(i);
    if (pr == visited_i.end()) return n;
    return *pr;
}

int position[200000];

int main(void) {
    int n;
    vector <int> an;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        an.push_back(a);
        position[a - 1] = i;
    }

    ll res = 0;
    set <int> visited_i;
    for (int a = 1; a <= n; a++) {
        int i = position[a - 1];
        int l = find_l(visited_i, i);
        int r = find_r(visited_i, i, n);
        res += ll(i - l) * ll(r - i) * ll(an[i]);
        visited_i.insert(i);
    }
    cout << res << endl;
    return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

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

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << h2 * 60 + m2 - h1 * 60 - m1 - k << "\n";

    return 0;
}


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


int main() {
  int N,R;
  cin>>N>>R;
  if(N>=10){cout<<R<<endl;}
  else{cout<<100*(10-N)+R<<endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,y;
int main()
{
	cin>>a>>b>>c>>x>>y;
	if(c*2>=a+b)cout<<x*a+y*b<<endl;
	else
	{
		int ans=0;
		if(x==y)cout<<(x+y)*c<<endl;
		else if(x<y)
		{
			ans=(x+x)*c;
			y-=x;
			cout<<ans+min(2*y*c,y*b)<<endl;
		}
		else
		{
			ans=(y+y)*c;
			x-=y;
			cout<<ans+min(2*x*c,x*a)<<endl;
		}
	}
	return 0;
} 

Measured memory_bytes: 256
N, K, Q = [int(i) for i in input().split()]

init_point = K - Q

contestants = [init_point for i in range(N)]

# 計算する
for i in range(Q):
    winner = int(input()) - 1 
    contestants[winner] += 1

# 出力する
for p in contestants:
    if p<= 0:
        print('No')
    else :
        print('Yes')

Measured memory_bytes: 6592
#include "bits/stdc++.h"
using namespace std;
#define debug(var) cout << #var << ": " << var << endl;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
using ll = long long;
using ull = unsigned long long;
using vvint = vector<vector<int>>;
constexpr ll mod = 1e9 + 7;

int main() {

  array<int, 3> arr;
  rep(i, 3)cin >> arr[i];
  sort(arr.begin(), arr.end());
  int ans = 0;
  rep(i, 2) {
	ans += abs(arr[i + 1] - arr[i]);
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
vector<vector<int>> adj;
vector<bool> visited;
vector<int> dist;
int dfs(int index)
{
	dist[index] = 0;
	for (int i = 0; i< adj[index].size(); i++)
	{
		int t =0;
		if(!visited[adj[index][i]])
		{
			t  = 1;
			t += dfs(adj[index][i]);
		}
		else
			t = dist[adj[index][i]]+1; //+1 is done because we are not going in depth of already explored node
		dist[index] = max(dist[index], t);
	}
	visited[index] = true;
	return dist[index];
}
int main(int argc, char*argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int N, M;
	cin >> N>> M;
	adj.reserve(N);
	for (int i=0; i<M;i++)
	{
		int x, y;
		cin >> x>>y;
		adj[x-1].push_back(y-1);
	}
	
	visited.assign(N, false);
	dist.assign(N, 0);
	for (int i =0 ; i< N; i++)
	{
		if(!visited[i])
			dfs(i);
	}
	sort(dist.begin(), dist.end(), greater<int>());
	cout << dist[0];
}

Measured memory_bytes: 9600
#include <cstdio>
#include <set>

using namespace std;

typedef pair<int, int> P;
int X[1100], Y[1100];

int main()
{
	int m;
	set<P> st;
	while (scanf("%d", &m), m != 0){
		/*
		?????§m?????????x,y????????????
		?????§n?????????????????????????????????????????????
		*/
		P k[1001];
		int x[220], y[220];
		for (int i = 0; i < m; i++){
			scanf("%d %d", x + i, y + i);
		}
		for (int i = 1; i < m; i++){
			k[i] = P(x[i] - x[0], y[i] - y[0]);
		}
		
		int n;
		scanf("%d", &n);
		
		for (int i = 0; i < n; i++){
			scanf("%d %d", X + i, Y + i);
			st.insert(P(X[i], Y[i]));
		}
		
		int x_d = 1001001000, y_d = 1001001000;
		
		for (int i = 0; i < n ; i++){
			bool found = true;
			for (int j = 0; j < m; j++){
				if(!st.count(P(X[i] + k[j].first, Y[i] + k[j].second))) {
					found = false;
					break;
				}
			}
			if (found){
				x_d = X[i] - x[0];
				y_d = Y[i] - y[0];
			}
		}
		printf("%d %d\n", x_d, y_d);
	}
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <complex>
#include <map>
#include <cassert>
#include <cstdlib>
using namespace std;

typedef long long ll;
typedef pair<complex<ll>,int> pvalue;
pvalue expression(string &s,int pos=0);
pvalue factor(string &s,int pos=0);
pvalue inner(string &s,int pos=0);

bool overflow;

ll kabs(ll a) {
    return (a>0)?a:-a;
}

pvalue expression(string &s,int pos) {
    pvalue pv = factor(s,pos);
    pos = pv.second;
    while(pos < s.length() && (s[pos] == '+' || s[pos] == '-')) {
        pvalue p2 = factor(s,pos+1);
        if(s[pos] == '+') pv.first += p2.first;
        else pv.first -= p2.first;
        pos = p2.second;
        if(kabs(pv.first.real()) > 10000 || kabs(pv.first.imag()) > 10000)
            overflow = true;
    }
    pv.second = pos;
    return pv;
}

pvalue factor(string &s,int pos) {
    pvalue pv = inner(s,pos);
    pos = pv.second;
    while(pos < s.length() && s[pos] == '*') {
        pvalue p2 = inner(s,pos+1);
        pv.first *= p2.first;
        pos = p2.second;
        if(kabs(pv.first.real()) > 10000 || kabs(pv.first.imag()) > 10000)
            overflow = true;
    }
    pv.second = pos;
    return pv;
}

pvalue inner(string &s,int pos) {
    if(s[pos] == '(') {
        pvalue pv = expression(s,pos+1);
        assert(s[pv.second] == ')');
        return make_pair(pv.first,pv.second+1);
    }

    bool readchar = false;
    complex<int> r(0,0);
    while(isdigit(s[pos])) {
        r *= 10;
        r += s[pos] - '0';
        pos++;
        readchar = true;
        if(kabs(r.real()) > 10000 || kabs(r.imag()) > 10000) {
            overflow = true;
            r = complex<ll>(0,0);
        }
    }
    if(s[pos] == 'i') {
        if(!readchar) r = complex<ll>(1,0);
        r *= complex<ll>(0,1);
        pos++;
    }
    if(kabs(r.real()) > 10000 || kabs(r.imag()) > 10000)
        overflow = true;

    return make_pair(r,pos);
}

int main() {
    string s;
    while(cin>>s) {
        overflow = false;
        pvalue p = expression(s);
        if(overflow) {
            cout<<"overflow"<<endl;
        }else{
            if(p.first.real() != 0) cout<<p.first.real();
            if(p.first.imag() > 0 && p.first.real() != 0) cout<<'+';
            if(p.first.imag() != 0) {
                cout<<p.first.imag();
                cout<<"i";
            }
            if(p.first.real() == 0 && p.first.imag() == 0) cout<<"0";
            cout<<endl;
        }
    }
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n=I()
A=LI()
count=0
for i in range(n):
    if A[i]<0:
        count+=1
B=sorted(list(map(abs,A)))
if count%2==1:
    ans=sum(B)-2*B[0]
else:
    ans=sum(B)
print(ans)

Measured memory_bytes: 15688
// 2020/06/23 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		// 町の総数

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

		for(int k=0; k<m; k++){
			for(int i=0; i<m; i++){
				for(int j=0; j<m; j++){
					T[i][j] = min(T[i][j], T[i][k]+T[k][j]);
				}
			}
		}

		int m_min = -1;
		int s_min = INF;

		for(int i=0; i<m; i++){
			int sum = 0;
			for(int j=0; j<m; j++){
				sum += T[i][j];
			}

			if(sum<s_min){
				m_min = i;
				s_min = sum;
			}
		}

		cout << m_min << ' ' << s_min << endl;
	}

	return 0;
}



Measured memory_bytes: 3088
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for ( v = 0; v < n; v++ ) {
    if ( M[u][v] == 0 ) continue;
    if ( color[v] == WHITE ) {
        dfs_visit(v);
    }
    }
    color[u] = BLACK;
    f[u] = ++tt;
    
}

void dfs() {
    int u;
   
    for ( u = 0; u < n; u++ ) color[u] = WHITE; tt = 0;
    for ( u = 0; u < n; u++ ) {
        if ( color[u] == WHITE ) dfs_visit(u);
    }
    for ( u = 0; u < n; u++ ) {
        printf("%d %d %d\n", u + 1, d[u], f[u]);
    }
    }



int main() {
    int u, v, k, i, j;
    scanf("%d", &n);
    for ( i = 0; i <n; i++){
        for ( j = 0; j<n; j++){
                   M[i][j] = 0;
        }
    }
        for ( i = 0; i < n; i++){
            scanf("%d %d", &u, &k);
            u--;
            for(j=0;j < k; j++){
            scanf("%d", &v);
                v--;
                M[u][v] = 1;
            }
        }
        dfs();
        return 0;
    }


Measured memory_bytes: 2112
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i] + a[i])
for i in range(m):
    b_sum.append(b_sum[i] + b[i])
    
ans, j = 0, m
for i in range(n + 1):
    if a_sum[i] > k:
        break
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main(){
  int t, x; cin >> t >> x;

  cout << fixed << setprecision(10) << (double)t/x << endl;

  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ll flag[3010][3010];
ll dp[3010][3010];
ll a[3010];
ll f(ll l,ll r){
  if(flag[l][r])return dp[l][r];
  flag[l][r]=1;
  if(l==r)return dp[l][r]=a[l-1];
  return dp[l][r]=max(a[l-1]-f(l+1,r),a[r-1]-f(l,r-1));
}
int main(){
  ll n;cin>>n;
  rep(i,n)cin>>a[i];
  cout<<f(1,n)<<endl;
}

Measured memory_bytes: 141696
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    getline(cin,a);
    getline(cin,b);
    sort(a.begin(),a.end());
    sort(b.begin(),b.end(),greater<char>());
    if (a<b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main()
{
    int n,ans=0;
    string s;
    cin >> n >> s;
    rep(i,n){
        map<char,bool> mpr,mpl;
        int cnt=0;
        rep(j,n){
            if(i<j){
                mpr[s.at(j)]=true;
            }else{
                mpl[s.at(j)]=true;
            }
        }
        rep(j,26){
            if(mpr['a'+j]&&mpl['a'+j]){
                cnt++;
            }
        }
        ans=max(ans,cnt);
    }
    cout << ans << endl;    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        for(int i=0;i<s.length();i++){
            if(i%2==0){
                System.out.print(s.charAt(i));
            }
        }
        System.out.println();
    }
}


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

int main() {
	string S;	
	cin>>S;
	int N = S.size();
	string T;
	rep(i,N){
		if(S[i] == 'A'){
			T.push_back('A');
		}
		else if(S[i] == 'B'){
			if(i+1 < N && S[i+1] == 'C'){
				T.push_back('D');
				i++;
			}
			else{
				T.push_back('X');
			}
		}
		else{
			T.push_back('X');
		}
	}
	cerr<<T<<endl;
	ll ans = 0;
	int a = 0;
	int M = T.size();
	rep(i,M){
		if(T[i] == 'A'){
			a++;
		}
		else if(T[i] == 'D'){
			ans += a;
		}
		else{
			a = 0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 776
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	string S;
	scan(S);
	ll ans=1;
	ll MOD=1e+9+7;
	int count[26]={};
	rep(i,N){
		count[S[i]-'a']++;
	}
	rep(i,26){
		ans*=(count[i]+1);
		ans%=MOD;
	}
	prin(ans-1);
	return 0;
}


Measured memory_bytes: 512
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;
use std::cmp::Ordering;

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();
    
    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let M = buf_it.next().unwrap().parse::<usize>().unwrap();

    let mut K = vec![0;N];
    let mut L = vec![Vec::new();N];

    for i in 0..N{
        K[i] = buf_it.next().unwrap().parse::<usize>().unwrap();
        for _ in 0..K[i]{
            let l = buf_it.next().unwrap().parse::<usize>().unwrap()-1;
            L[i].push(l);
        }
    }

    let mut E = vec![Vec::new();N+M];
    for i in 0..N{
        for j in 0..K[i]{
            E[i].push(L[i][j]+N);
            E[L[i][j]+N].push(i);
        }
    }

    let c = dfs_connect(N+M,E,0);

    let mut ans = true;
    for i in 0..N{
        ans &= c[i];
    }

    println!("{}",if ans {"YES"} else {"NO"});
}

fn dfs_connect(N:usize,E:Vec<Vec<usize>>,start:usize) -> Vec<bool>{
    let mut done = vec![false;N];
    let mut q = vec![start];
    while let Some(i) = q.pop(){
        for &j in &E[i]{
            if done[j] {continue;}
            q.push(j);
            done[j] = true;
        }
    }
    done
}

Measured memory_bytes: 18576
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	string ar;
	cin>>ar;
	ll i,j,k,l,n=ar.length();

	k=0;
	ll an=0;
	for(i=0;i<n-1;i++){
		if(ar[i]=='A') k++;
		else {
			if(ar[i]=='B'){
				if(ar[i+1]=='C'){
					an+=k; i++;
				}
				else{
					k=0;
				}
			}
			else{
				k=0;
			}
		}
	}
	cout<<an;
	return 0;
}


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

typedef long long int ll;

ll n;

int main()
{
    cin>>n;

    ll arr[n+1];

    for(ll i=0;i<n;i++)cin>>arr[i];
    ll pre[n+1];
    pre[0] = arr[0];
    for(ll i=0;i<n;i++){
        pre[i+1] = __gcd(pre[i],arr[i]);
    }
    ll suff[n+1];
    suff[n]=arr[n-1];
    for(ll i=n-1;i>=0;i--){
        suff[i] = __gcd(suff[i+1],arr[i]);
    }

    ll ans = 0;

    for(ll i=0;i<n;i++){

        if(i==0){
            ans = max(ans,suff[i+1]);
        }
        else{
        if(i==n-1){
            ans = max(ans,pre[i]);
        }
        else{

            ans = max(ans,__gcd(suff[i+1],pre[i]));

        }
        }


    }
    cout<<ans<<endl;




}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

const int MAX_N = (int)1e5 + 777;
int a[MAX_N], p[MAX_N], n;

/*vector<int> g[MAX_N];
int met[MAX_N], color[MAX_N], mark = 1337;

void dfs(int v, int col) {
	met[v] = mark;
	color[v] = col;

	for(auto& u: g[v]) {
		if(met[u] != mark)
			dfs(u, col);
	}
}*/

int check(int k) {
	if(k > n)
		return 0;

	/*++mark; // clear met

	for(int v = 0; v <= n; ++v) {
		g[v].clear();
	}

	for(int v = 0; v <= n; ++v) {
		for(int u = v + k; u <= n; ++u) {
			g[v].push_back(u);
			g[u].push_back(v);
		}
	}

	for(int v = 0; v <= n; ++v) {
		if(met[v] != mark)
			dfs(v, v);
	}

	for(int pos = 0; pos < n; ++pos) {
		if(p[pos]) {
			if(color[pos] != color[n] && color[pos] != color[0])
				return 0;
		}
	}*/

	for(int pos = 0; pos < n; ++pos) {
		if(p[pos]) {
			int dist = std::max(pos, n - pos);

			if(dist < k)
				return 0;
		}
	}

	return 1;
}

void solve() {
	string str;
	cin >> str;

	n = len(str);

	for(int i = 0; i < n; ++i) {
		a[i] = str[i] - '0';
		p[i] = a[i];

		if(i > 0)
			p[i] ^= a[i - 1];
	}

	int low = 1, high = n + 1;

	while(high - low > 1) {
		int mid = (low + high) / 2;

		if(check(mid))
			low = mid;
		else
			high = mid;
	}

	cout << low << '\n';
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 1232
#include<iostream>
#include<queue>
#include<cstring>
#include<utility>
using namespace std;

/*
説明
二次元格子上の幅優先探索。
点(x,y)への最小のコストはmin_cost[x][y]
startは(sx,sy),cは通れるマスの文字
計算量O(WH)
*/
int h, w;
char grid[500][500];
int min_cost[500][500];

int bfs(int sx, int sy, int gx, int gy) {
	const int vx[] = { 0, 1, 0, -1 }, vy[] = { 1, 0, -1, 0 };
	memset(min_cost, -1, sizeof(min_cost));//min_costの初期化

	queue<pair<int, int>>que;
	que.emplace(sx, sy);
	min_cost[sx][sy] = 0;
	if (grid[sx][sy] == '#')return -1;
	while (!que.empty()) {
		auto p = que.front(); que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.first + vx[i], ny = p.second + vy[i];
			if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
			if (min_cost[nx][ny] != -1) continue;//もう来た
			if (grid[ny][nx] == '#') continue;//進めない
			min_cost[nx][ny] = min_cost[p.first][p.second] + 1;
			que.emplace(nx, ny);
		}
	}
	return min_cost[gx][gy];
}

int main() {
	cin >> h >> w;
	int m = -1;
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++) {
		cin >> grid[i][j];
		if (grid[i][j] == '.')m++;
	}
	int a = bfs(0, 0, w - 1, h - 1);
	if (a == -1)cout << a << endl;
	else cout << m - bfs(0, 0, w - 1, h - 1) << endl;
}

Measured memory_bytes: 1280