akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static int count;

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		for(int i = 0;i < n; i++){
			int num = Integer.parseInt(br.readLine());
			solve(num);
		}

		System.out.println(count);

	}

	public static void solve(int num){
		if(num == 1){
			return;
		}
		else if(num == 2){
			count++;
			return;
		}
		else if(num % 2 == 0){
			return;
		}
		else{
			for(int i = 3;i <= Math.sqrt(num); i +=2){
				if(num % i == 0){
					return;
				}
			}
		}
		count++;
	}

}

Measured memory_bytes: 30676
import java.util.Scanner;

// ABC092 at 2018/**/**

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

    private void solveA() {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.nextLine());
        int B = Integer.parseInt(sc.nextLine());
        int C = Integer.parseInt(sc.nextLine());
        int D = Integer.parseInt(sc.nextLine());
        int result = 0;

        if (A < B) {
            result += A;
        } else {
            result += B;
        }
        if (C < D) {
            result += C;
        } else {
            result += D;
        }

        System.out.println(result);
    }

    private void solveB() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveC() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveD() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveE() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveF() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

}

Measured memory_bytes: 25172
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

class ASecurity {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s;
        in>>s;
        rep(i,3){
            if(s.at(i)==s.at(i+1)) {
                out<<"Bad";
                return;
            }
        }
        out<<"Good";
	}
};


int main() {
	ASecurity solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll gcd(ll a, ll b)
{
    if (a < b)
        swap(a, b);
    ll c = a % b;
    if (c == 0)
        return b;
    return gcd(b, c);
}

int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll S = B - A + 1;
    //! (A,B)のうち、Cで割り切れるもの
    ll c = B / C - (A - 1) / C;
    //! Dでわりきれるもの
    ll d = B / D - (A - 1) / D;
    //! CでもDでもわりきれるもの
    ll g = C * D / gcd(C, D);
    ll cd = B / g - (A - 1) / g;
    cout << S - (c + d) + cd << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderRegularContest069
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(program1(new String[] { Console.ReadLine(), Console.ReadLine() }));
        }

        public static string program1(string[] args)
        {
            var n = int.Parse(args[0]);
            var s = args[1].ToCharArray();
            var animalPattern = new List<char>[] { new List<char>() { 'S', 'S' }, new List<char> { 'S', 'W' }, new List<char> { 'W', 'W' }, new List<char> { 'W', 'S' } };

            return string.Join("", animalPattern.Select(animals => {
                s.Skip(1).Aggregate(animals.First(), (ani, ans) =>
                {
                    var current = animals.Last();
                    animals.Add(isXor(current, ans) ? not(ani) : ani);
                    return current;
                });
                return animals;
            }).Where(animals => animals.First() == animals.Last())
            .Select(animals => animals.Take(n))
            .FirstOrDefault(animals => animals.ElementAt(1) == (isXor(animals.First(), s.First()) ? not(animals.Last()) : animals.Last())) ?? new List<char>() { '-', '1' }) ;
        }

        public static bool isXor(char animal, char ans) => animal == 'S' && ans == 'x' || animal == 'W' && ans == 'o';

        public static char not(char animal) => animal == 'S' ? 'W' : 'S';
    }
}


Measured memory_bytes: 17120
INF = int(1e18)

def merge(A, left, mid, right):
    L = A[left:mid]
    n1 = len(L)
    R = A[mid:right]
    L.append(INF)
    R.append(INF)
    i, j, count = 0, 0, 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            # Lで超える分がひっくり返す回数 (?)
            count += n1 - i
    return count

def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        c1 = merge_sort(A, left, mid)
        c2 = merge_sort(A, mid, right)
        c3 = merge(A, left, mid, right)
        return c1 + c2 + c3
    else:
        return 0

if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    c = merge_sort(A, 0, n)
    print(c)


Measured memory_bytes: 27484
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    while(true){
        cin >> H >> W;
        if(H == 0 && W == 0)break;
    
        for(int i = 0; i < H; i++){
            for(int n = 0; n < W; n++){
                if(i == 0 || i == H - 1 || n == 0 || n == W - 1){
                    cout << "#";
                }else{
                    cout << ".";
                }
               
            }
             cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, a, b, c);
  int mx = max({a, b, c});
  print((a + b + c - mx) == mx ? "Yes" : "No");
}


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

signed main(){
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    if((b - a) % 2) cout << "IMPOSSIBLE" << endl;
    else cout << a + (b - a) / 2 << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int32_t n;
	cin >> n;
	vector<int64_t> l;
	l = { 2,1 };
	for (int32_t i = 2; i <= n; i++) {
		int64_t s = l.at(i - 2) + l.at(i - 1);
		l.push_back(s);
	}
	int32_t a = l.size();
	cout << l.at(a - 1) << endl;
	system("pause");
}

Measured memory_bytes: 504
check[30], c, n, a, xor_sum, ans;
int main() {
  while (1) {
    c = getchar_unlocked();
    if (48 <= c && c <= 57)
      n = n * 10 + c - 48;
    else
      break;
  }

  for (int i = 0; i < n; i++) {
    a = 0;
    while (1) {
      c = getchar_unlocked();
      if (48 <= c && c <= 57)
        a = a * 10 + c - 48;
      else
        break;
    }
    xor_sum ^= a;
    a = a ^ (a - 1);

    check[__builtin_popcount(a) - 1] = 1;
  }

  for (int bit = 29; bit >= 0; bit--) {
    if (check[bit] && ((1 << bit) & xor_sum)) {
      int x = (1 << (bit + 1)) - 1;
      xor_sum ^= x;
      ans += 1;
    }
  }

  printf("%d\n", xor_sum ? -1 : ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(3),b(3);
	cin >> a[0] >> a[1] >> a[2];
	cin >> b[0] >> b[1] >> b[2];

// a to b

	vector<long long> dp(100000000,0);
	for(int i=0;i<dp.size();i++)
		dp[i]=i;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(i>=a[j])dp[i]=max(dp[i],dp[i-a[j]]+b[j]);
		}
	}


	int m=dp[n];

// b to a

	for(int i=0;i<dp.size();i++)
		dp[i]=i;

	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(i>=b[j])dp[i]=max(dp[i],dp[i-b[j]]+a[j]);
		}
	}




	cout << dp[m] << endl;
	
}

Measured memory_bytes: 781568
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 10007LL;
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);
    string s;
    cin >> s;
    if(s.length() == 3) {
        reverse(all(s));
    }
    cout << s << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main {
    public static void main (String[] args) throws Exception {
        Scanner sch = new Scanner(System.in);
        int q = sch.nextInt();
           int[] A = new int[q];
        int f = 0;
        for (int c = f; c < q; c++) {
            A[c] = sch.nextInt();
           
        }
         int k = 0;
         k = pa(A,q-1);
       StringBuilder dd = new StringBuilder();
        for(int i = 0; i < q; i++) {
            if(i != 0){
                dd.append(" ");
            }
            if(i == k){
                dd.append('[');
                dd.append(A[i]);
                dd.append(']');
            }else{
                dd.append(A[i]);
            }
        }
        System.out.println(dd);
    }

    public static int pa(int[] A,int r) {
         
       int f = 0;
        int sort = 0;
        int x = A[r];
        int i = f - 1;
        for (int j = 0; j < r; ++j){
            if (A[j] <= x){
                ++i;
                sort = A[i];
                A[i] = A[j];
                A[j] = sort;
            }
        }
        sort = A[i + 1];
        A[i + 1] = A[r];
        A[r] = sort;
        return i + 1;
    }

}


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

const ll INF = 1ll << 60;
ll MOD = 998244353;

vector<pair<int, int>> tasks;

int main()
{

    int n;
    cin >> n;
    vector<int> a(n), b(n);

    REP(i, n)
    {
        int a, b;
        cin >> a >> b;
        tasks.emplace_back(b, a);
    }

    sort(tasks.begin(), tasks.end());
    int sum = 0;
    bool isys = true;
    for (auto v : tasks)
    {
        sum += v.second;

        if (sum > v.first)
        {
            isys = false;
            break;
        }
    }

    cout << (isys ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3956
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

ll n;
vector<ll> v;

void generate(ll a)
{
    if(a > n){
        return;
    }
    v.push_back(a);
    generate(10*a+3);
    generate(10*a+5);
    generate(10*a+7);
}

int main()
{
    cin >> n;
    generate(3);
    generate(5);
    generate(7);
    ll ans = 0;
    rep(i, v.size()){
        string s = to_string(v[i]);
        int s3 = 0;
        int s5 = 0;
        int s7 = 0;
        rep(j, s.size()){
            if(s[j] == '3') s3++;
            if(s[j] == '5') s5++;
            if(s[j] == '7') s7++;
        }
        if(s3>0 && s5 > 0 && s7 > 0) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int c = -1;
  int f = -1;
  for (int i = 0; i < s.length(); i++)
  {
    if (s[s.length() - 1 - i] == 'C')
      c = s.length() - 1 - i;
    if (s[i] == 'F')
      f = i;
  }
  if (0 <= c && 0 <= f && c < f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;
vector<vector<string>> graph;


//39 B
int main(void) {
	ll n;
	cin >> n;
    graph = vector<vector<string>>(n,vector<string>(n));
	vector<vector<ll>> wf = vector<vector<ll>>(n, vector<ll>(n, 10000));
	rep(i, 0, n) {
		string s;
		cin >> s;
		rep(j, 0, n) {
			graph[i][j] = s[j];
			if (s[j] == '1')wf[i][j] = 1;
		}
	}
	vector<ll> nibu = vector<ll>(n, -1);
	nibu[0] = 0;
	queue<ll> q = queue<ll>();
	q.push(0);
	ll ans = 0;
	while (ans == 0 && q.size() > 0) {
		ll v = q.front();
		q.pop();
		rep(i, 0, n) {
			if (graph[v][i] == "1") {
				if (nibu[i] == -1) {
					nibu[i] = nibu[v] ^ 1;
					q.push(i);
				}
				else if (nibu[i] == nibu[v]) {
					ans = -1;
					break;
				}
			}
		}
	}
	
	if (ans == 0) {
		rep(i, 0, n)wf[i][i] = 0;
		rep(k, 0, n) {
			rep(i, 0, n) {
				rep(j, 0, n) {
					wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
				}
			}
		}
		rep(i, 0, n) {
			rep(j, 0, n) {
				ans = max(ans, wf[i][j] + 1);
			}
		}
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
bool a[2020];
int main() {
    long long i,l,r,mn=2020,v;
    cin>>l>>r;
    for(i=l;i<=min(r,l+2019);i++){
        a[i%2019]=1;
    }
    if(a[3]&&a[673]) cout<<0,exit(0);
    
    repi(i,1,2019){
        if(a[i%2019]==true){
            repi(j,i+1,2019){
                if(a[j%2019]==true){
                    v=(i%2019)*(j%2019)%2019;
                    mn=min(mn,v);
                }
            }
        }
    }
    cout<<mn;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}
vector<int> col ;
vector<vector<pll>> adj ;
vector<bool> visited ;
void dfs(int u , ll dist){
	visited[u] = true ;
	for(pll i : adj[u]){
		if(!visited[i.x]){
			if((dist + i.y) % 2) col[i.x] = 1 ;
			else col[i.x] = 0 ;
			dfs(i.x , dist + i.y) ;
		}
	}
}
//check modulo
int main(){
	IOS;
	cout.precision(30) ;
	int n ; cin >> n ;
	adj.resize(n) ;
	visited.resize(n);
	col.resize(n) ;
	int u , v ; ll w ;
	for(int i = 0 ; i < n - 1 ; i++){
		cin >> u >> v >> w ;
		u-- ; v-- ;
		adj[u].pb(mp(v , w)) ;
		adj[v].pb(mp(u , w)); 
	}
	col[0] = 0 ;
	dfs(0 , 0) ;
	for(int i = 0 ; i < n ; i++) cout << col[i] << "\n" ;
	return 0;
}


Measured memory_bytes: 9728
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	int n; 
	int m; 
	
	cin >> n;
	int *t = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	cin >> m;
	int *p = new int[m]; int *x = new int[m];
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> x[i];
	}

	int total = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (j == (p[i] - 1) ) {
				total+= x[i];
			}
			else {
				total+= t[j];
			}
		}
		cout << total << endl;
		total = 0;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define inf LLONG_MAX
#define endl "\n"
using namespace std;

void solve(){
	
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2]<<endl;
}

int32_t main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	//int t; cin >> t; while(t--)
	{
		solve();

	}

	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
int main(){
  std::string s,t;
  std::cin>>s>>t;
  std::sort(s.begin(), s.end());
  std::sort(t.rbegin(), t.rend());
  if(s<t)std::cout<<"Yes"<<std::endl;
  else std::cout<<"No"<<std::endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
int N;
vector<ll> A;
vector<ll> A_t;
ll res;
ll maxA = 0;
ll minA = 0;

ll med3(ll x, ll y, ll z)
/* x, y, z の中間値を返す */
{
  if (x < y)
    if (y < z)
      return y;
    else if (z < x)
      return x;
    else
      return z;
  else if (z < y)
    return y;
  else if (x < z)
    return x;
  else
    return z;
}

void quicksort(ll a[], int left, int right)
/* クイックソート
 * a     : ソートする配列
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 */
{
  if (left < right)
  {
    int i = left, j = right;
    ll tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
    while (1)
    { /* a[] を pivot 以上と以下の集まりに分割する */
      while (a[i] < pivot)
        i++; /* a[i] >= pivot となる位置を検索 */
      while (pivot < a[j])
        j--; /* a[j] <= pivot となる位置を検索 */
      if (i >= j)
        break;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp; /* a[i],a[j] を交換 */
      i++;
      j--;
    }
    quicksort(a, left, i - 1);  /* 分割した左を再帰的にソート */
    quicksort(a, j + 1, right); /* 分割した右を再帰的にソート */
  }
}
ll myabs(ll a)
{
  if (a < 0)
  {
    return -a;
  }
  else
  {
    return a;
  }
}

ll mymax(ll a, ll b)
{
  if (a > b)
  {
    return a;
  }
  else
  {
    return b;
  }
}

ll mymin(ll a, ll b)
{
  if (a > b)
  {
    return b;
  }
  else
  {
    return a;
  }
}

int main()
{
  cin >> N;
  A = vector<ll>(N);
  A_t = vector<ll>(N + 1, 0);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
    if (i == 0)
    {
      A_t[i] = A[i];
      maxA = A[i];
    }
    else
    {
      A_t[i] += A_t[i - 1] + A[i];
      maxA = mymax(maxA, A_t[i]);
      minA = mymin(minA, A_t[i]);
    }
  }
  quicksort(&A_t.front(), 0, N);
  ll tmp = A_t[0];
  ll count = 0;
  for (int i = 0; i <= N; i++)
  {
    if (tmp == A_t[i])
    {
      count++;
    }
    else
    {
      res += (count * (count - 1)) / 2;
      count = 1;
      tmp = A_t[i];
    }
  }
  res += (count * (count - 1)) / 2;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>

using namespace std;

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

int main() {
	int n, MAX = 0, MIN = 10000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		MAX = max(MAX, a);
		MIN = min(MIN, a);
	}
	cout << MAX - MIN << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pb push_back
#define mp make_pair
typedef pair<int,int> ii;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	for(;;)
	{
		c-=b;
		if(c<=0)
		{
			cout<<"Yes"<<endl;
			break;
		}
		a-=d;
		if(a<=0)
		{
			cout<<"No"<<endl;
			break;
		}
	}
}

Measured memory_bytes: 3660
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,m;
    cin >> n>>m;
    ll a[m],b[m];
    set<ll> v;
    rp(i,m){
      cin >> a[i] >> b[i];
      a[i]--; b[i]--;
      if(a[i] > b[i]) swap(a[i],b[i]);
      if(a[i] == 0) v.insert(b[i]);
    }
    rp(i,m){
      if(b[i] == n-1){
        if(v.find(a[i]) != v.end())
        {
          cout << "POSSIBLE"<<endl; return 0;
        }
      }
    }

    cout <<"IMPOSSIBLE"<<endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main(){
    int x,y;

    cin >> x >> y;

    for (int i = 0; i <= x; i++) {
        if ((2 * i + 4 * (x-i)) == y) {
            cout << "Yes" << endl;
            return 0;
        }

    }

    cout << "No" << endl;
    return 0;
} 


Measured memory_bytes: 3584
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

// グラフの隣接リストでの表現。 (蟻本参照)
// 辺があるかの判定: 最悪|V|
// メモリ: |V| + |E|

const int MAX_V = 100000;

struct edge {
  int to, cost;
};
vector<edge> g[MAX_V];

int N;

// 0: even
// 1: odd
vector<int> ans;
vector<bool> visit;

void dfs(int v, int cost) {
  if (visit[v]) {
    return;
  }
  visit[v] = true;
  if (cost % 2 == 0) {
    ans[v] = 0;
  } else {
    ans[v] = 1;
  }

  for (int i = 0; i < g[v].size(); i++) {
    dfs(g[v][i].to, cost + g[v][i].cost);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int ui, vi, wi;
    cin >> ui >> vi >> wi;
    ui--;
    vi--;
    g[ui].push_back(edge{vi, wi});
    g[vi].push_back(edge{ui, wi});
  }

  visit.resize(N, false);
  ans.resize(N, 0);
  dfs(0, 0);

  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 8448
import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
Color = [0] + list(map(int, input().split()))
Query =[]
for i in range(Q):
    l, r = map(int, input().split())
    Query.append(r * 10 ** 12 + l * 10 ** 6 + i)
Query.sort()
Ans = [0] * Q

BIT = [0] * (N + 1)  # BITを使う


def BIT_query(idx):  # idxまでの合計を返す
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum


def BIT_update(idx,x):  # idxにxを足す
    while idx <= N:
        BIT[idx] += x
        idx += idx&(-idx)
    return


cn = max(Color)
Last = [-1] * cn

cnt = 0
for q in Query:
    r = q // 10 ** 12
    l = (q % 10 ** 12) // 10 ** 6
    i = q % 10 ** 6
    while cnt < r:
        cnt += 1
        c = Color[cnt] - 1
        if Last[c] == -1:
            Last[c] = cnt
            BIT_update(cnt, 1)
        else:
            x = Last[c]
            BIT_update(x, -1)
            Last[c] = cnt
            BIT_update(cnt, 1)
    Ans[i] = BIT_query(r) - BIT_query(l-1)

for a in Ans:
    print(a)

Measured memory_bytes: 158448
import Control.Applicative

main :: IO ()
main = do
    xss <- map (map read . words) . lines <$> getContents
    mapM_ putStrLn $ solve xss

solve :: [[Float]] -> [String]
solve [] = []
solve (x:xs) = solve':(solve xs)
    where
        [x1,y1,x2,y2,x3,y3,xp,yp] = x
        a = (x2 - x1) * (yp - y2) - (y2 - y1) * (xp - x2)
        b = (x3 - x2) * (yp - y3) - (y3 - y2) * (xp - x3)
        c = (x1 - x3) * (yp - y1) - (y1 - y3) * (xp - x1)
        solve' = if or [and [a > 0, b > 0, c > 0], and [a < 0, b < 0, c < 0]]
                   then "YES"
                   else "NO"

Measured memory_bytes: 4188
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static long mod = 1000000007;

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);

        var sum = 0L;

        for(int i=0; i<64; i++) {
            var x = 0L;
            for(int j=0; j<n; j++) {
                x += (aa[j] >> i) % 2;
            }
            var ss = x * (n - x);
            for(int j=0; j<i; j++) {
                ss *= 2;
                ss %= mod;
            }
            sum += ss;
            sum %= mod;
        }

        return sum;
    }

    static void print(long list) {
        var buil = new StringBuilder();
        for(int i=0; i<64; i++) {
            buil.Append( (list>>(63-i)) % 2 );
        }
        Debug.Write(buil);
        Debug.WriteLine("(" + list + ")");
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
string S;

	cin >> S;
	ll ans = 0;
	int sum = 0;
	if (S.size()<3) {
		ce(0)
			return 0;
	}

	fx(S.size()-2) {
		if (S[x]=='A') {
			while (x<S.size()&&S[x]=='A') {
				x++;
				sum++;
			}
			while (x+1<S.size()&&S[x]=='B'&&S[x+1]=='C') {
				ans += sum;
				x += 2;
			}
			x--;
		}
		else {
			sum = 0;
		}
	}
	ce(ans)
	return 0;
}



Measured memory_bytes: 644
<?php
/**
 * 標準入力　複数行
 */
// 標準入力を一行ずつ配列に代入します
$times_drawing = fgets(STDIN);
while ($line = fgets(STDIN)) {
    $strs[] = trim($line);
}

$value_count = array_count_values($strs);


print(count($value_count));

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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin>>n;
    double avgpath = 0;
    vector<int> perms(n);
    vector< vector <int> > paths(n,vector<int>(2));
    int i;
    for(i=0;i<n;i++){
        cin>>paths[i][0];
        cin>>paths[i][1];
        perms[i] = i;
    }
    int count = 0;
    do{
        for(i=0;i<n-1;i++){
            avgpath += sqrt((pow((paths[perms[i]][0] - paths[perms[i+1]][0]),2)) + (pow((paths[perms[i]][1] - paths[perms[i+1]][1]),2)));
        }
        count++;
    }while(next_permutation(perms.begin(),perms.end()));
    avgpath /= count;
    cout<<fixed;
    cout<<setprecision(10);
    cout<<avgpath<<"\n";
    return 0;
}


Measured memory_bytes: 256
a,b,c = map(int, input().split())
start = a%b
for i in range(1, b+1):
    x = a%b * i
    # print(i, x, x%b)
    if x%b == c:
        print('YES')
        break
    if start == x and i != 1:
        print('NO')
        break
else:
    print('NO')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main()
{
    string s;
    int size,count1=0,count2=0,count3=0;
    cin>>s;
    size=s.length();
    for (int i=0 ; i<size ; i++) {
        if (s[i] == 'C')
            count1++;
    }
    for (int j=2 ; j<size-1 ; j++) {
        if (s[j] == 'C')
            count2++;
    }
    for (int k=0 ; k<size ; k++) {
        if (s[k]>=97)
            count3++;
    }
    if (s[0]=='A' && count1==1 && count2==1 && count3==size-2)
        cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    return 0;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i))	ans++;
  }
  cout << ans;
}

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

int main() {
    int n, k;
    cin >> k >> n;
    int a[n];
    rep(i,n) cin >> a[i];

    // 隣との距離の差の最大値を探索
    int max = 0;
    rep(i,n) {
        int diff;
        if (i != n-1) diff = a[i+1] - a[i];
        else diff = k-a[i] + a[0];
        if (diff > max) max = diff;
    }
    int ans = k - max;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
using namespace std;
const int N=100010;
int n;
int a[N];
inline int abs(int x){
	return x>=0?x:-x;
}
void readData(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
}
void solve(){
	int ans=0;
	for(int i=1;i<=n+1;i++) ans+=abs(a[i]-a[i-1]);
	for(int i=1;i<=n;i++)
		printf("%d\n",ans-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]));
}
int main(){
	readData();
	solve();
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
//using int64 = long long;
//#define int int64
#define LL long long
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
//int max(int a, int b) {if(b>a) return b; else return a;}
//int min(int a, int b) {if(b<a) return b; else return a;}
//const int INF = 1e18;

int main() {
    LL a;
    double b;
    cin >> a >> b;

    cout << a*int(b*100.0+0.5)/100 << endl;

    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<(n); i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
int C[102][102];
int n,p,cou,jud,fr,to,co;
        
signed main(void){
    while(true){
        cin>>n>>p;
        if(n==0&&p==0)break;
        cou=0;
        rep(i,102)rep(j,102)C[i][j]=INF;
        rep(z,p){
            cin>>jud;
            
            if(jud==1){
                cou=1;
                cin>>fr>>to>>co;fr--;to--;
                C[fr][to]=min(C[fr][to],co);
                C[to][fr]=min(C[to][fr],co);
            }
            
            if(jud==0){
                cin>>fr>>to;fr--;to--;
                
                if(cou==1){
                    cou=0;
                    rep(k,n)rep(i,n)rep(j,n){
                        C[i][j]=min(C[i][j],C[i][k]+C[k][j]);
                    }
                }
                
                if(C[fr][to]==INF)cout<<-1<<endl;
                else cout<<C[fr][to]<<endl;
            }
            
        
        }
    }
}


Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {

	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {

		char[] S = in.next().toCharArray();
		System.out.println(S[2] == S[3] && S[4] == S[5] ? "Yes" : "No");
	}


	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

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

int main() {
  int N,x;
  cin>>N;
  vector<int> vec(N);
  rep(i,N){cin >> x;
          vec.at(x-1)=i+1;}
  
  rep(i,N){cout<<vec.at(i)<<" ";}
  cout<<endl;
}

Measured memory_bytes: 3760
package main

import "fmt"

func isPalindromic(x int) bool {
	s := []int{}
	for x != 0 {
		s = append(s, x%10)
		x /= 10
	}

	j := len(s) - 1
	for i := 0; i < j; i++ {
		if s[i] != s[j] {
			return false
		}
		j--
	}
	return true
}

func main() {
	var A, B int
	fmt.Scan(&A, &B)

	cnt := 0
	for i := range make([]struct{}, B-A+1) {
		if isPalindromic(A + i) {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 6528
// Author : SAGORIKA DAS
#include <bits/stdc++.h>
#define F first
#define S second
#define MOD 1000000007
#define pb push_back
#define MAX 200002
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define mp make_pair
#define CLEAR(a) memset(a,0,sizeof a)
#define pii pair< int , int >
#define fr freopen("input.txt", "r", stdin)
#define fw freopen("output.txt", "w", stdout)
using namespace std;
int a[MAX];

int main(){
  //fr;fw;
  int n;
  cin >> n;
  REP(i,2*n) cin >> a[i];
  sort(a,a+2*n);
  int ans = 0;
  int i = 0;
  while(i < 2*n){
  	ans += a[i];
  	i+=2;
  }
  cout << ans;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MAX (int)1e9 + 99
#define maxof(a,b,c) max(a,max(b,c))
#define minof(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vvi vector<vector<int>>
#define vb vector<bool>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define bitcnt(x) __builtin_popcount(x)
#define gcd(a,b) __gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define ts(x) to_string(x)
#define rsort(a) sort(all(a)); reverse(all(a))
#define set0(x) memset(x, 0, sizeof(x))
const double pi = 3.14159265358979323846;
ll binpow(ll, ll);
ll mult(ll, ll);
ll add(ll , ll);
ll division(ll, ll);
ll nCr(ll, ll);
ll inv(ll);
void calc();
void maxi(int &a, int b) {if(a<b) a = b;}
void mini(int &a, int b) {if(a>b) a = b;}
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) {if (!v.empty()) {os << v.front();for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];} return os;}
const int N=50010;
const int MOD = 1e9+7;
//ll fact[N];






void solve()
{
    int n;
    cin>>n;
    vi d1(n), d2(n);

    rep(i,n) {
        cin>>d1[i]>>d2[i];
    }

    bool ok = false;
    for(int i = 0; i<n-2; i++) {
        if(d1[i] == d2[i] && d1[i+1] == d2[i+1] && d1[i+2] == d2[i+2]) {
            ok=true;break;}
        
    }

    if(ok) cout<<"Yes";
    else cout<<"No";
    
}

int main()
{
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    
    rep(i,t)
    {
        solve();
        cout<<"\n";
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}








ll add(ll a, ll b){
    a+=b;
    while(a>=MOD) a-=MOD;
    while(a<0) a+=MOD;
    return a;
}

ll mult(ll a, ll b){
    return (a * 1ll * b) % MOD;
}


ll binpow(ll a, ll b){
    ll c = 1;
    while(b > 0)
    {
        if(b % 2 == 1)
            c = mult(c, a);
        a = mult(a, a);
        b /= 2;
    }
    return c;   
}

ll inv(ll a){
    return binpow(a, MOD-2);
}

ll division(ll a, ll b){
    return mult(a, inv(b));
}
/*
ll nCr(ll n, ll r){
    if(r > n) return 0;
    return division(fact[n], mult(fact[n-r], fact[r]));
}

void calc(){
    fact[0] = 1;
    srep(i,1,N-1)
        fact[i] = (i*1ll*fac[i-1])%MOD;

}*/

Measured memory_bytes: 3792
# https://atcoder.jp/contests/agc034/tasks/agc034_b

# BCをDに置換すればあとは簡単。いくつのAがDを超えるのかをカウントするだけ
# ADとなる
s = input()
s = s.replace('BC', 'D')
# print(s)

nA = 0
ans = 0

for ss in s:
    if ss == 'A':
        nA += 1
    elif ss == 'D':
        ans += nA
    else:
        nA = 0
print(ans)


Measured memory_bytes: 3500
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    long long H;
    cin >> H;
    
    long long ans = 0;
    long long num = 1;
    while (H > 0) {
        H /= 2;
        ans += num;
        num *= 2;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;


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

    int a[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) cin >> a[i][j];
    }
    int n, x;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> x;
        s.insert(x);
    }
    bool flag = false, flag1;
    for (int i = 0; i < n; i++) {
        flag1 = true;
        for (int j = 0; j < 3; j++) {
            flag1 &= s.find(a[i][j]) != s.end();
        }
        flag |= flag1;
    }
    for (int i = 0; i < n; i++) {
        flag1 = true;
        for (int j = 0; j < 3; j++) {
            flag1 &= s.find(a[j][i]) != s.end();
        }
        flag |= flag1;
    }
    flag |= (s.find(a[0][0]) != s.end() && s.find(a[1][1]) != s.end() && s.find(a[2][2]) != s.end());
    flag |= (s.find(a[0][2]) != s.end() && s.find(a[1][1]) != s.end() && s.find(a[2][0]) != s.end());
    if (flag) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 int main() { 
int a[101][101], b[101][101];
 long long c[101][101], s;
 int i, j, k; int n, m, l; 
scanf("%d%d%d", &n, &m, &l);
 for (i = 0; i < n; i++) {
 for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
 }
 for (i = 0; i < m; i++) {
 for (j = 0; j < l; j++) scanf("%d", &b[i][j]);
 }
 for (i = 0; i < n; i++) {
 for (j = 0; j < l; j++) {
 s = 0;
 for (k = 0; k < m; k++) {
 s += a[i][k] * b[k][j];
 } 
c[i][j] = s; 
}
 }
 for (i = 0; i < n; i++) {
 printf("%lld", c[i][0]);
 for (j = 1; j < l; j++) printf(" %lld", c[i][j]);
 putchar('\n');
 } 
return 0;
 } 


Measured memory_bytes: 2124
local n, m = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
local bias, velocity = {}, {}
for i = 1, m + 2 do
  bias[i], velocity[i] = 0, 0
end
for i = 1, n - 1 do
  local src, dst = t[i], t[i + 1]
  if src < dst then
    local len = dst - src
    bias[1] = bias[1] + len
    velocity[src + 2] = velocity[src + 2] - 1
    velocity[dst + 2] = velocity[dst + 2] + 1
    bias[dst + 1] = bias[dst + 1] + len
  else
    local len = dst + m - src
    bias[1] = bias[1] + dst + 1
    velocity[1] = velocity[1] - 1
    velocity[dst + 2] = velocity[dst + 2] + 1
    bias[dst + 1] = bias[dst + 1] + len
    velocity[src + 2] = velocity[src + 2] - 1
  end
end
local ret = 0
local b, v = 0, 0
for i = 1, m do
  v = v + velocity[i]
  b = b + bias[i] + v
  if i == 1 then ret = b
  else ret = math.min(ret, b)
  end
end
print(ret)


Measured memory_bytes: 6528
#include<cstdio>
#include<algorithm>
using namespace std;

#define INF (1<<28)
#define REP(i,n) for(int i=0;i<n;i++)

int a[110][110],wf[30][110][110],p[30],q[100],r[100],sum[100];
int n,m,c,s,g,x,y,d,id,tmp;

int main(){
  while(scanf("%d%d%d%d%d",&n,&m,&c,&s,&g),n){
    REP(i,n)REP(j,n){
      a[i][j] = INF;
      REP(k,c)wf[k][i][j] = INF;
    }
    
    REP(i,m){
      scanf("%d%d%d%d",&x,&y,&d,&id);
      x--; y--; id--;
      wf[id][x][y] = min(wf[id][x][y],d);
      wf[id][y][x] = min(wf[id][y][x],d);
    }
    
    REP(l,c){
      scanf("%d",&p[l]);
      REP(k,n)REP(i,n)REP(j,n)
	wf[l][i][j] = min(wf[l][i][j],wf[l][i][k] + wf[l][k][j]);
    }

    REP(k,c){
      q[0] = 0;
      REP(i,p[k]-1)scanf("%d",&q[i+1]);
      q[p[k]] = INF;
      REP(i,p[k])scanf("%d",&r[i]);
      sum[0] = 0;
      REP(i,p[k])sum[i+1] = sum[i] + r[i]*(q[i+1]-q[i]);

      REP(i,n)for(int j=i;j<n;j++){
	if(wf[k][i][j] < INF){
	  tmp = upper_bound(q,q+p[k]+1,wf[k][i][j])-q-1;
	  a[i][j] = a[j][i] = min(a[i][j],sum[tmp] + r[tmp]*(wf[k][i][j]-q[tmp]));
	}
      }
    }

    REP(k,n)REP(i,n)REP(j,n)a[i][j] = min(a[i][j],a[i][k] + a[k][j]);

    if(a[s-1][g-1]>=INF)printf("-1\n");
    else printf("%d\n",a[s-1][g-1]);
  }
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int ans = 0;
  for (int i = 0; i < 3; ++i) {
    if (S.at(i) == T.at(i)) {
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ms(a ,value) memset(a ,value,sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define N 20000000
class Triplet{
	public:
		int x , y , z;	
};
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int mod = 1e9+7;
vector <int> adj[N];
string str;
map <int,int> freq;
const double PI=3.1415926535897;
typedef long long int ll;

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

	if(n%1000==0){
		cout<<"0"<<endl;
		return 0;
	}

	int ans = 1000*ceil(n/1000+1)-n;
	cout<<ans<<endl;
	return 0;
}

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

int main(void){
	int d;
	int res=0;
	while(cin>>d){
		for(int i=0; i<(600/d); i++){
			res += d*(d*i)*(d*i);
		}
		cout << res << endl;
		res = 0;
	}
	return 0;
}

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

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;

////////////////////////////////

int main()
{
    int n,p;
    while(cin >> n >> p,n&&p){
        int cur = 0;
        int incup = p;
        vector<int> s(n,0);
        int ret = -1;
        while(true){
            if(incup > 0){
                incup--;s[cur]++;
                if(incup==0 && s[cur] == p){
                    ret = cur;break;
                }
            }else{
                incup+=s[cur];s[cur] = 0;
            }
            cur = (cur + 1) % n;
        }
        cout << ret << endl;
    }
}




Measured memory_bytes: 2964
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };
    let K: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = S.iter()
        .map(|&c| if c == S[K - 1] {
            c.to_string()
        } else {
            "*".to_string()
        })
        .collect::<Vec<_>>()
        .join("");

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	bool f=0;
	if(a[0]==a[1]&&a[1]!=a[2])f=1;
	if(a[1]==a[2]&&a[0]!=a[1])f=1;
	cout<<(f?"Yes":"No");
	return 0;
}


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

const int M = 1000005;

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

    cout << x * y << endl;

    return 0;
}

Measured memory_bytes: 3596