akhauriyash/Code-Regression huggingface dataset:
// finish date: 2019/2/9

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
//#define input(name)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    vi A(N);
    map<int, int> mp;
    rep(i, N) {
        cin >> A[i];
        mp[A[i]]++;
    }
    if(mp.size()==N){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }


    return 0;
}


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

int main(){
    ll n,k; cin >> n >> k;
    vector<int> a(n);
    vector<int> f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(a.begin(),a.end());
    sort(f.rbegin(),f.rend());
    ll l=-1, r=1e12;
    while(r-l>1){
        ll mid=(l+r)/2; ll sum = 0;
        for(int i=0; i<n;i++){
            sum += max(a[i]-mid/f[i],0ll);
        }if(sum <= k)r = mid; else l = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 1792
w = input()
l = []
for i in range(len(w)):
	if w[i] not in l:
		l.append(w[i])
cnts = [2] * len(l)
for i in range(len(w)):
	for j in range(len(l)):
		if w[i] == l[j]:
			cnts[j] += 1
			
if all(i%2 == 0 for i in cnts):
	print("Yes")
else:
	print("No")

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  ll ans = K;
  for(int i = 0; i < N - 1; i++) {
    ans *= K - 1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll A, B, C,K;
    double k;
    cin >> A >> B >> C >> K;
    ll ans = B - A;

    if (K % 2 == 0)
    {
        ans = -ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1005];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]%2==0){
            if(a[i]%3!=0&&a[i]%5!=0){
                cout<<"DENIED";
                return 0;
            }
        }
    }
    cout<<"APPROVED";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back
#define vs vector<string>

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll H,W;
    cin>>H>>W;
    vector<vector<char>> grid(W,vector<char>(H));
    rep(i,H)rep(j,W)cin>>grid[j][i];
    vvl dp(W,vl(H,INF));
    if(grid[0][0]=='#') dp[0][0]=1;
    else dp[0][0]=0;
    rep(i,H){
        rep(j,W){
            if(j!=W-1){
                if(grid[j][i]=='.'&&grid[j+1][i]=='#'){
                    chmin(dp[j+1][i],dp[j][i]+1);
                }else{
                    chmin(dp[j+1][i],dp[j][i]);
                }
            }
            if(i!=H-1){
                if(grid[j][i]=='.'&&grid[j][i+1]=='#'){
                    chmin(dp[j][i+1],dp[j][i]+1);
                }else{
                    chmin(dp[j][i+1],dp[j][i]);
                }
            }
        }
    }
    cout<<dp[W-1][H-1]<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll M = 1e9 + 7;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  double r;
  cin >> r;
  cout << 2 * M_PI *r;
}

Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

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

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> task[100001];
    for(int i=0; i<n; i++){
        int a,b;
        cin >> a >> b;
        task[a].push_back(b);
    }
    long long ans = 0;
    priority_queue<int> que;
    for(int i=1; i<=m; i++){
        for(auto p=task[i].begin(); p != task[i].end(); p++){
            que.push(*p);
        }
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5632
/*
 　　　　　／＞　 フ
 　　　　　| 　_　 _|
 　 　　　／`ミ _x 彡
 　　 　 /　　　 　 |
 　　　 /　  ヽ　　 ?
 　／￣|　　 |　|　|
 　| (￣ヽ＿_ヽ_)_)
 　＼二つ
  */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
    static short st[30];short tp=0;
    if(x<0) putchar('-'),x=-x;
    do st[++tp]=x%10,x/=10; while(x);
    while(tp) putchar('0'|st[tp--]);
    putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 300500;
int sum[N], a[N], res, t, n;
bool check(int mid) {
    int k = 0;
    for (int i = 2;i <= n; i += 2) 
        if (sum[i-1] - k >= mid) Mn(k, sum[i]);
    return sum[n] - k >= mid;
}

int main() {
    read(n);
    for (int i = 1;i <= n; i++) {
        read(a[i]), sum[i] = i & 1 ? sum[i-1] + a[i] : sum[i-1] - a[i];
        res += a[i];
    }
    if (~n & 1) {
        t = max(sum[n], -sum[n]);
        write((res + t) / 2, ' '), write((res - t) / 2);
        return 0;
    }
    int l = 0, r = 1e9;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (check(mid)) l = mid + 1;
        else r = mid - 1;
    }
    t  = -sum[n] + 2 * r;
    write((res + t) / 2, ' '), write((res - t) / 2, ' ');
    return 0;
}

Measured memory_bytes: 5408
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n;
  cin>>n;
  map<string,int> m;
  int mc=0;
  rep(i,n) {
    string s;
    cin>>s;
    m[s]++;
    mc=max(mc,m[s]);
  }
  vector<string> ans;
  for(auto& sn : m) {
    string s;
    int n;
    tie(s,n) = sn;
    if(n==mc) {
      ans.push_back(s);
    }
  }
  sort(ans.begin(),ans.end());
  for(auto &a :ans) {
    cout << a << endl;
  }
  return 0;
}


Measured memory_bytes: 25584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

ll L;

template< int char_size >
struct TrieNode {
    int nxt[char_size];
    
    int exist;
    vector< int > accept;
    
    TrieNode() : exist(0) {
        memset(nxt, -1, sizeof(nxt));
    }
};

template< int char_size, int margin >
struct Trie {
    using Node = TrieNode< char_size >;
    
    vector< Node > nodes;
    int root;
    ll grundy=0;
    
    Trie() : root(0) {
        nodes.push_back(Node());
    }
    
    void update_direct(int node, int id) {
        nodes[node].accept.push_back(id);
    }
    
    void update_child(int node, int child, int id) {
        ++nodes[node].exist;
    }
    
    void add(const string &str, int str_index, int node_index, int id) {
        if(str_index == str.size()) {
            update_direct(node_index, id);
        } else {
            const int c = str[str_index] - margin;
            if(nodes[node_index].nxt[c] == -1) {
                nodes[node_index].nxt[c] = (int) nodes.size();
                nodes.push_back(Node());
            }
            add(str, str_index + 1, nodes[node_index].nxt[c], id);
            update_child(node_index, nodes[node_index].nxt[c], id);
        }
    }
    
    void add(const string &str, int id) {
        add(str, 0, 0, id);
    }
    
    void add(const string &str) {
        add(str, nodes[0].exist);
    }
    
    void query(const string &str, const function< void(int) > &f, int str_index, int node_index) {
        for(auto &idx : nodes[node_index].accept) f(idx);
        if(str_index == str.size()) {
            return;
        } else {
            const int c = str[str_index] - margin;
            if(nodes[node_index].nxt[c] == -1) return;
            query(str, f, str_index + 1, nodes[node_index].nxt[c]);
        }
    }
    
    void query(const string &str, const function< void(int) > &f) {
        query(str, f, 0, 0);
    }
    
    int count() const {
        return (nodes[0].exist);
    }
    
    int size() const {
        return ((int) nodes.size());
    }
    
    void DFS(int node_index,int d){
        if(nodes[node_index].accept.size()) return;
        for(int i=0;i<2;i++){
            if(nodes[node_index].nxt[i]==-1){
                for(int j=62;j>=0;j--){
                    if((L-d)%(1LL<<j)==0){
                        grundy^=(1LL<<j);
                        break;
                    }
                }
            }else{
                DFS(nodes[node_index].nxt[i],d+1);
            }
        }
    }
};


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N>>L;
    vector<string> S(N);
    Trie<2,'0'> trie;
    for(int i=0;i<N;i++){
        cin>>S[i];
        trie.add(S[i]);
    }
    
    trie.DFS(0,0);
    
    if(trie.grundy==0) cout<<"Bob"<<endl;
    else cout<<"Alice"<<endl;
}



Measured memory_bytes: 8080
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int a, b;
    cin >> a >> b;
    int cnt = 1;
    int c   = b;
    while (c != 0) {
        cnt++;
        c /= 10;
    }
    REP(i, cnt - 1) a *= 10;
    int ans = a + b;
    REP(i, ans) {
        if (ans == i * i) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
n,m = (int(i) for i in input().split())
p = []
ac = 0
wa = 0
for i in range(m):
  a,b = (input().split())
  a = int(a)
  p.append([a,b])
x = [0]*n
w = [0]*n
for i in range(m):
  tmp = p[i][0] - 1
  if p[i][1] == "AC":
    x[tmp] = 1
  elif p[i][1] == "WA":
    if x[tmp] == 0:
      w[tmp] += 1
for i in range(n):
  if x[i] == 1:
    ac += 1
    wa += w[i]
print(ac,wa)

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

template <const long long M>
class mint {
   private:
    long long x;

   public:
    constexpr mint(long long x = 0) : x((x % M + M) % M) {}
    constexpr long long value() { return x; }
    constexpr mint operator-() const { return mint(-x); }
    constexpr mint &operator+=(const mint &a) {
        if ((x += a.x) >= M) x -= M;
        return *this;
    }
    constexpr mint &operator-=(const mint &a) {
        if ((x += M - a.x) >= M) x -= M;
        return *this;
    }
    constexpr mint &operator*=(const mint &a) {
        (x *= a.x) %= M;
        return *this;
    }
    constexpr mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
    constexpr mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    constexpr mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    constexpr mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    constexpr mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    constexpr mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    constexpr mint inv() const { return pow(M - 2); }
    constexpr bool operator==(const mint &a) const { return x == a.x; }
    constexpr bool operator!=(const mint &a) const { return x != a.x; }
    friend istream &operator>>(istream &in, mint &a) {
        in >> a.x;
        if (a.x < 0) a.x += M;
        a.x %= M;
        return in;
    }
    friend ostream &operator<<(ostream &out, const mint &a) {
        out << a.x;
        return out;
    }
};

template <typename T>
T combination(int n, int r) {
    T ans = 1;
    for (int i = 0; i < r; i++) {
        ans *= n - i;
        ans /= (i + 1);
    }
    return ans;
}

int main() {
    int X, Y;
    cin >> X >> Y;
    mint<1000000007> ans = 0;
    if ((X + Y) % 3 == 0 && X <= 2 * Y && Y <= 2 * X) {
        int S = (X + Y) / 3;
        int A = Y - S;
        int B = X - S;
        ans = combination<mint<1000000007>>(A + B, A);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

    ll n;cin>>n;
    vector<ll> a(n+1,0);
    vector<ll> m(n);
    rep(i,n) {
        cin>>m[i];
        m[i]--;
        a[m[i]]++;
    }

    ll ans=0;
    rep(i,n){
        ll mm = a[i]*(a[i]-1)/2;
        ans+=mm;
    }

    rep(i,n){
        ll ans2 = ans;
        ans2 -= (a[m[i]]-1);        
        cout<<ans2<<endl;
    }

    return 0;
}

Measured memory_bytes: 6356
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)

Int dp[20][54000];
Int table[54000];
Int left[54000];
Int right[54000];
Int h, w;
Int p[20][54000];
Int f[20][54000];

int solve(int x){

    
}

int main(){
	Int N,o,f=0;
	cin >> N;
	o=N;
	while(N != 0){
		f += N%10;
		N = N/10;
	}
	if(o%f == 0)cout << "Yes" <<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import product
INF = 10**9
MOD = 10**9 + 7

def main():
    n = int(input())
    a = list(map(int,input().split()))

    bit = 0
    ans = 0
    right = 0
    for left in range(n):
        while right < n:
            num = a[right]
            if num & bit == 0:
                bit += num
                right += 1
            else:
                bit -= a[left]
                break
        ans += right - left
    
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 25164
n = gets.chomp.to_i
rests = {}

n.times do |i|
  name,p = gets.chomp.split
  p = p.to_i
  rests.has_key?(name) ? 
    rests[name] << [i+1,p] :
  	rests[name]= [[i+1,p]]
end

rests.sort.each do |rest|
  result = rest[1].sort{|a, b| b[1] <=> a[1] }
  result.each{|re| p re[0]}
end



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

int main(){
  int n,k,data[100000],sum,max;
  while(1){
    cin >> n >> k;
    sum = 0;
    max = -10000000;
    if(n == 0&&k == 0)break;
    for(int i = 0; i < n;i++)
      cin >> data[i];
    for(int i = 0;i < k;i++)
      sum += data[i];
    if(sum > max) max = sum;
    for(int i = 0; i < n-k;i++){
      sum = sum-data[i]+data[i+k];

      if(sum > max)
        max = sum;
    }
    cout << max <<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string s;
  int ans=0;
  ans=700;
  cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]=='o'){
      ans+=100;;
    }
  }
  cout<<ans<<"\n";
      
  return 0;
}

Measured memory_bytes: 3620
L, R = map(int, input().split())

if (R - L) // 2019 > 0:
    print(0)
elif (R - L) != (R % 2019 - L % 2019):
    print(0)
else:
    answer = 2019
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            tmp = i * j % 2019
            if tmp < answer:
                answer = tmp
    print(answer)


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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  string s2;
  if(s[k-1]=='A') s2="a";
  if(s[k-1]=='B') s2="b";
  if(s[k-1]=='C') s2="c";
  s.replace(k-1,1,s2);
  cout << s << endl;

}


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

typedef long long ll;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;
	cin>>n;
	
	ll ans = 1e16;
	
	for(ll i=1;i*i<=n;i++) {
		
		if(n % i > 0) continue;
		
		ans = min(ans, i + (n / i) - 2);
		
	}
	
	cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

int main(){
string s;
  cin >> s;
  ll countB=0;
  ll countW=0;
  ll ans=0;
  rep(i,s.size()){
   if(s[i]=='W'){
     countW++;
    ans+=i;
   }
  }
  ll res=0;
  rep(i,countW)res+=i;
  cout << ans-res << endl;
return 0;}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


signed main() {
	ios::sync_with_stdio(false);
	string s1, s2;
	cin >> s1 >> s2;
	sort(ALL(s1));
	sort(ALL(s2));
	reverse(ALL(s2));
	if (s1 < s2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<bool> like(m+1);
  rep(i,n){
    int k;
    cin>>k;
    int a;
    vector<bool> fg(m+1);
    rep(j,k){
      int a;
      cin>>a;
      fg[a]=true;
    }
    rep(i,m+1){
      if(!fg[i]){
        like[i]=true;
      }
    }
  }
  int count=0;
  REP(i,1,m+1){
    if(!like[i]){
      count++;
    }
  }
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int x = 0;
    int N;
    string S;
    int res = x;

    cin >> N >> S;
    for(int i = 0; i < N; i++)
    {
        if(S[i] == 'I')
            x++;
        else if(S[i] == 'D')
            x--;

        res = max(res , x);
    }

    cout << res << endl;
    return 0;
    
}


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


void solve(long long N, std::string S){
  S.erase(std::unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::string S;
  std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);;

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		for(; sc.hasNext();){
			P[] ps=new P[3];
			for(int i=0; i<3; i++){
				double x=sc.nextDouble();
				double y=sc.nextDouble();
				ps[i]=new P(x, y);
			}
			double xp=sc.nextDouble();
			double yp=sc.nextDouble();
			P q=new P(xp, yp);
			for(int i=0; i<3; i++){
				ps[i]=ps[i].sub(q);
			}
			double[] signs=new double[3];
			for(int i=0; i<3; i++){
				signs[i]=Math.signum(ps[i].det(ps[(i+1)%3]));
			}
			if(signs[0]==signs[1]&&signs[1]==signs[2]){
				println("YES");
			}else{
				println("NO");
			}
		}
	}

	class P{
		double x, y;

		P(){
			this(0, 0);
		}

		P(double x, double y){
			this.x=x;
			this.y=y;
		}

		P sub(P p){
			return new P(x-p.x, y-p.y);
		}

		double det(P p){
			return x*p.y-y*p.x;
		}
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
def main():
    import sys
    from collections import deque
    input = sys.stdin.buffer.readline
    N = int(input())
    edge = [[] for _ in range(N)]
    for i in range(N-1):
        a, b, c = (int(i) for i in input().split())
        edge[a-1].append((c, b-1))
        edge[b-1].append((c, a-1))

    dist = [-1]*N
    color = [-1]*N

    def dfs(v, G):
        todo = deque()
        dist[v] = 0
        color[v] = 0
        todo.append(v)
        while todo:
            u = todo.pop()
            for c, next_v in G[u]:
                if dist[next_v] != -1:
                    continue
                dist[next_v] = dist[u] + c
                if dist[next_v] % 2 == 1:
                    color[next_v] = 1
                else:
                    color[next_v] = 0
                todo.append(next_v)

    dfs(0, edge)
    print(*color, sep="\n")
    # print("\n", *dist, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 66720
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    string s = scan;
    if(s[2] == s[3] && s[4] == s[5]) "Yes".print;
    else "No".print;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#ifndef ONLINE_JUDGE
    freopen ( "A.in", "r", stdin );
#endif
    std::ios::sync_with_stdio ( 0 );
    cin.tie ( 0 );
    cout << fixed << setprecision ( 6 );
}
//////////////////////////////////////////
const int N = 5 + 1e1;
int main() {
   
    int a,b;
    cin>>a>>b;
    if(a+b==15)cout<<"+";
    else if(a*b==15)cout<<"*";
    else cout<<"x";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -MOD * MOD;
const long double pi = 3.141592653589793;
int fact[101];
void pfact(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i) continue;
		while (x % i == 0) {
			fact[i]++;
			x /= i;
		}
	}
	if (x >= 2) fact[x]++;
}
int main() { // 問題文はしっかり読め!!!
	int n;
	cin >> n;
	rep1(i, n) {
		pfact(i);
	}
	V ni;
	V yon;
	V itiyonn;
	V niyonn;
	V nanayonn;
	set<pair<int, pair<int, int>>> st1; // p^4*q^4*r^2,75個はこれだけやと思ってた
	set<P<int>> st2; // p^14*q^4
	set<P<int>> st3; // p^24*q^3
	int ans74 = 0; // p^74
	REP(i, 2, 101) {
		if (fact[i] >= 2) ni.push_back(i);
		if (fact[i] >= 4) yon.push_back(i);
		if (fact[i] >= 14) itiyonn.push_back(i);
		if (fact[i] >= 24) niyonn.push_back(i);
		if (fact[i] >= 74) ans74++;
	}
	rep(i, ni.size()) {
		rep(j, yon.size()) {
			rep(k, yon.size()) {
				if (ni[i] != yon[j] && ni[i] != yon[k] && yon[j] != yon[k]) {
					int a = ni[i], b = yon[j], c = yon[k];
					if (b < c) swap(b, c);
					st1.insert(make_pair(a, make_pair(b, c)));
				}
			}
		}
	}
	rep(i, yon.size()) {
		rep(j, itiyonn.size()) {
			if (yon[i] != itiyonn[j]) {
				st2.insert(make_pair(yon[i], itiyonn[j]));
			}
		}
	}
	rep(i, ni.size()) {
		rep(j, niyonn.size()) {
			if (ni[i] != yon[j]) {
				st3.insert(make_pair(ni[i], yon[j]));
			}
		}
	}
	cout << st1.size() + st2.size() + st3.size() + ans74 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <chrono>
  
    using namespace std;
    using namespace std::chrono; 
 
    typedef long long int ll;
 
    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin>>t;while(t--)
    #define forn(i,a,n) for (int i = a; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()
    
    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }
    
    
    int main()
    {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int a,b;
      cin>>a>>b;
      int ans = a*b;
      cout<<ans<<endl;

    }
    

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ara[200002];

int main()
{
    int n,i;
    ll ans;
    cin>>n;
    for(i=1;i<=n;i++)scanf("%d",&ara[i]);
    sort(ara+1,ara+n+1,greater<int>());
    ans=ara[1];
    for(i=3;i<=n;i++)ans+=ara[(i+1)/2];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4456
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#include <variant>
#define endl codeforces
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t... Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

int main() {
    ll x;
    std::cin >> x;
    vec<ll> pow5v;
    auto pow5 = [](ll x) {
        ll ret = 1;
        for (ll i = 0; i < 5; i++) ret *= x;
        return ret;
    };
    for (ll i = 0; i <= 1e3; i++) {
        ll tmp = pow5(i);
        pow5v.push_back(tmp);
    }
    for (ll a = 0; a < pow5v.size(); a++) {
        ll v = pow5v[a];
        ll b5 = v - x;
        auto ite = std::lower_bound(ALL(pow5v), std::abs(b5));
        if (ite != pow5v.end() && *ite == std::abs(b5)) {
            ll b = std::distance(pow5v.begin(), ite);
            if (b5 < 0) b = -b;
            std::cout << a << " " << b << "\n";
            return 0;
        }
    }
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t; cin>>t;
    if (t) cout<<0;
    else cout<<1;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,count=0,ans=0;
  cin >> n;
  vector<int> vec(n+1);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  vec.at(n)=1000000010;
  for(int i=0;i<n;i++){
    if(vec.at(i+1)<=vec.at(i)){
      count++;
    }
    else{
      ans = max(count,ans);
      count = 0;
    }
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int a,b,k;
	cin >> a >> b >> k;
	REP(i,k){
		if(i%2==0){
			a /= 2;
			b += a;
		}
		else{
			b /=2;
			a += b;
		}
	}
	cout << a << " " << b;

    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


n = int(readline())
s = []
check = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    ss = readline().rstrip().decode()
    if ss[0] in check:
        s.append(ss[0])
counter = list(Counter(s).values())
if len(counter) < 3:
    print(0)
    exit()
ans = cmb(sum(counter), 3)
for v in counter:
    if v >= 2:
        ans -= cmb(v, 2) * (len(s) - v)
        if v >= 3:
            ans -= cmb(v, 3)
print(ans)


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N-1]に格納する
    int* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    qsort(A,N,sizeof(int),asc);

    int ans=1;
    for(int i=1;i<N;i++){
        if(A[i]!=A[i-1]) ans++;
    }
    if(ans%2==0) ans--;
    printf("%d\n",ans);

    return 0;
}

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

using namespace std;

using ll = long long;

ll n, k;
vector<ll> a;
vector<vector<bool>> dp;

bool Check(ll idx) {
    int src = 0, dst = 1;
    fill(dp[src].begin(), dp[src].end(), false);
    dp[src][0] = true;
    for (int i = 0; i < n; ++i) {
        if (i == idx) continue;
        fill(dp[dst].begin(), dp[dst].end(), false);
        for (int j = 0; j < k; ++j) {
            dp[dst][j] = dp[dst][j] | dp[src][j];
            if (0 <= j - a[i]) dp[dst][j] = dp[dst][j] | dp[src][j - a[i]];
        }
        swap(src, dst);
    }

    for (int i = 0; i < k; ++i)
        if (dp[src][i] && k - a[idx] <= i) return true;

    return false;
}

ll Solve() {
    cin >> n >> k;
    a.resize(n);
    dp.resize(2);
    dp[0].resize(k + 1); dp[1].resize(k + 1);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());

    if (accumulate(a.begin(), a.end(), 0ll) < k) return n;

    // 必要な要素の集合を見つける
    ll lb = -1, ub = n;
    while (1 < ub - lb) {
        ll mid = (lb + ub) >> 1;
        if (Check(mid)) lb = mid;
        else ub = mid;
    }

    return n - lb - 1;
}

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

    cout << Solve() << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long w[100020], d[100020];
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &w[i], &d[i]);
	}
	long long L = 0, R = 2e18;
	while (L < R - 1) {
		long long M = (L + R) / 2, cnt = 0;
		for (int i = 0; i < n; i++) {
			if (M >= w[i]) {
				cnt += (M - w[i]) / d[i] + 1;
			}
			if (cnt >= k) {
				break;
			}
			assert(cnt >= 0);
		}
		if (cnt >= k) {
			R = M;
		} else {
			L = M;
		}
	}
	printf("%lld\n", R);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
//BIAR MANTAB LAH YA
#define Willy using
#define Indrayana namespace
#define Komara std
 
Willy Indrayana Komara;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    set<string> s;
    while (n--)
    {
        string input;
        cin >> input;
        s.insert(input);
    }
    cout << s.size() << '\n';
}

Measured memory_bytes: 19256
#include "bits/stdc++.h"
#include <typeinfo>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s1, s2;
    cin >> s1 >> s2;
    s1 += s2;

    int num = stoi(s1);

    rep(i, 1000) {
        if (i * i == num) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
#define MAX_N 100

int X,N;
set<int> p;

int main()
{
    int Answer;
    int x;
    cin >> X >> N;
    for(int i=0;i<N;i++){
        cin >> x;
        p.insert(x);
    }
    int i=0;
    while(1){
        if(p.find(X-i) == p.end()){
            Answer = X-i;
            cout << Answer;
            return 0;
        }else if(p.find(X+i) == p.end())
        {
            Answer = X+i;
            cout << Answer;
            return 0;
        }
        i++;
    }
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int b, e;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'A'){
			b = i;
			break;
		}
	}
	
	for(int i = s.size() - 1; i >= 0 ; --i){
		if(s[i] == 'Z'){
			e = i;
			break;
		}
	}
	
	cout << e - b + 1;
	return 0;
}

Measured memory_bytes: 848
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for(int i = 0; i < m; ++i)  cin >> x[i];
    sort(x.begin(), x.end());
    vector<int> gap;
    for(int i = 0; i < m-1; ++i)    gap.push_back(x[i+1] - x[i]);
    sort(gap.begin(), gap.end());
    ll res = 0;
    if(gap.size() >= n - 1) res = accumulate(gap.begin(), gap.end() - (n - 1), 0ll);
    cout << res << endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll dp[200007];
int main(){
  ll n;
  cin >> n;
  vl a(n);
  ll total = 0;
  rep(i, n){
    cin >> a[i];
    if(i==0){
      dp[0] = a[0];
      continue;
    }
    dp[i] = dp[i - 1] + a[i];
  }
  ll ans = INF*4;
  rep(i,n){
    ll a = abs(dp[n - 1] - dp[i] - dp[i]);
    chmin(ans, a);
  }
  print(ans);
}


Measured memory_bytes: 6424
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) {
		cin >> a[i];
	}
	sort(all(a));
	int i, j = a[0];
	i = a.back();
	rep(k,n-1) {
		if(fabs(j - i/2.0) > fabs(a[k] - i/2.0))
			j = a[k];
	}
	cout << i << " " << j << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	reverse(s.begin(), s.end());
	if (s == t) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

int main()
{
    string s1,s2,s3;
    int a,b;
    cin>>s1>>s2>>a>>b>>s3;
    if(s3==s1)
        cout<<a-1<<" "<<b<<endl;
    else if(s3==s2)
        cout<<a<<" "<<b-1<<endl;
    else
        cout<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range (k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))


Measured memory_bytes: 11704
n = int(input())
i = 1
m = 0
while True:
    m += i
    if m == n:
        k = i + 1
        c = 1
        break
    elif m > n:
        c = 0
        break
    i += 1
if c == 1:
    print("Yes")
    print(k)
    dp = [[0 for _ in range(k - 1)] for _ in range(k)]
    m = 0
    for i in range(k):
        for j in range(k - 1):
            if i <= j:
                m += 1
                dp[i][j] = m
            else:
                if i == j + 1:
                    dp[i][j] = dp[i - 1][j]
                else:
                    dp[i][j] = dp[i - 1][j] + 1
    for i in range(k):
        print(k - 1, end = " ")
        s = map(str, dp[i])
        print(" ".join(s))
else:
    print("No")

Measured memory_bytes: 12160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
using namespace std;

struct union_find_tree {
    vector<int> data;
    union_find_tree() = default;
    explicit union_find_tree(size_t n) : data(n, -1) {}
    bool is_root(int i) { return data[i] < 0; }
    int find_root(int i) { return is_root(i) ? i : (data[i] = find_root(data[i])); }
    int tree_size(int i) { return - data[find_root(i)]; }
    int unite_trees(int i, int j) {
        i = find_root(i); j = find_root(j);
        if (i != j) {
            if (tree_size(i) < tree_size(j)) swap(i,j);
            data[i] += data[j];
            data[j] = i;
        }
        return i;
    }
    bool is_same(int i, int j) { return find_root(i) == find_root(j); }
};

int main() {
    int n, k, l; cin >> n >> k >> l;
    union_find_tree uft1(n);
    REP (i, k) {
        int p, q; cin >> p >> q; -- p; -- q;
        uft1.unite_trees(p, q);
    }
    union_find_tree uft2(n);
    REP (i, l) {
        int r, s; cin >> r >> s; -- r; -- s;
        uft2.unite_trees(r, s);
    }
    map<pair<int, int>, int> cnt;
    REP (i, n) {
        cnt[make_pair(uft1.find_root(i), uft2.find_root(i))] += 1;
    }
    REP (i, n) {
        cout << cnt[make_pair(uft1.find_root(i), uft2.find_root(i))] << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 13568