akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
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 solve(int x)
{
    int ans = 0;
    while (x > 0)
    {
        int p = 0, tmp = x;
        while (tmp > 0)
        {
            p += (tmp % 2);
            tmp /= 2;
        }
        x %= p;
        ans++;
    }
    return ans;
}

int main()
{
    int N;
    cin >> N;
    string X;
    cin >> X;
    int pcnt = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (X[i] == '1')
            pcnt++;
    }
    bool isZero = pcnt==1;
     ll xrem1 = 0, xrem2 = 0;
    vint rem1(N), rem2(N); // rem1[i] := 2^i % (pcnt-1) , rem2[i] := 2^i % (pcnt+1)
    if (pcnt != 1)
    {
        rem1[0] = 1 % (pcnt - 1);
        for (size_t i = 0; i < N; i++)
        {
            rem1[i + 1] = (rem1[i] * 2) % (pcnt - 1);
        }
        for (int i = N - 1; i >= 0; i--)
    {
        if (X[i] == '1')
        {
            xrem1 =(xrem1 + rem1[(N-1)-i])%(pcnt-1);
        }
    }
    }
    rem2[0] = 1 % (pcnt + 1);
    for (size_t i = 0; i < N; i++)
    {
        rem2[i + 1] = (rem2[i] * 2) % (pcnt + 1);
    }
    
   
    for (int i = N - 1; i >= 0; i--)
    {
        if (X[i] == '1')
        {
            xrem2 = (xrem2 + rem2[(N-1)-i]) % (pcnt+1);
        }
    }

    for (int i = 0; i < N; i++)
    {
        if (X[i] == '1' and !isZero)
        {
            int newP = pcnt - 1;
            ll nrem = ((xrem1 - rem1[N-1-i])%newP + newP)%newP;
            cout<<solve(nrem)+1<<"\n";
        }
        else if(X[i]=='1' and isZero)
        {
            cout<<0<<endl;
        }
        else
        {
            int newP = pcnt + 1;
            ll nrem = (xrem2 + rem2[N-1-i])%newP;
            cout<<solve(nrem)+1<<"\n";
        }
        
    }

    return 0;
}

Measured memory_bytes: 5152
#include "iostream"
#include "vector"

using namespace std;
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  for (auto i = 0; i < s.size(); i++)
  {
    auto c = s.at(i);
    if (c == '?')
    {
      cout << 'D';
    }
    else
    {
      cout << c;
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3748
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

vector<double> x;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k,x;
	cin >> k >> x;
	for(int i = x-k+1;i < x+k;i++){
		cout << ((i == x-k+1) ? "" : " " ) << i;
	}
	cout << '\n';
	return 0;
}


Measured memory_bytes: 256
import collections
n=int(input())
if n==1:
  print(0)
  exit()
b=int(n**0.5)
i=2
l=[]
while i<=b:
  if n%i==0:
    l.append(i)
    n=n//i
  else:
    i+=1
if n>b:
  l.append(n)
c=collections.Counter(l)
v=list(c.values())

ans=0
for vv in v:
  wa=1
  s=1
  while True:
    if vv<wa:
      break
    s+=1
    wa+=s
  ans+=(s-1)
print(ans)

Measured memory_bytes: 9608
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=998244353
    N,M,K=MI()
    
    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return (fact[n] * factinv[r] * factinv[n-r])%mod

    fact=[1,1]
    factinv=[1,1]
    inv=[0,1]
    
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
        
        
    p=[1]*(N+3)#(M-1)^i
    for i in range(N+2):
        p[i+1]=(p[i]*(M-1))%mod
        
    ans=0
    for i in range(K+1):
        temp=M*p[N-1-i]*cmb(N-1,i,mod)
        temp%=mod
        ans=(ans+temp)%mod
        
    print(ans)

main()


Measured memory_bytes: 111128
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main()
{
    ll n;
    cin>>n;
    
    ll ans=0;
    auto factor=prime_factorize(n);
    for(auto v:factor)
    {
        int s=v.second;
        int sa=1;
        while(1)
        {
            s-=sa;
            if(s<0)break;
            sa++;
            ans++;
        }
    }
    cout<<ans;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<int> counter(2);
  rep (i, n) {
    int x;
    cin >> x;
    if (x % 4 == 0) {
      counter[0]++;
    } else if (x % 2 == 0) {
      counter[1]++;
    }
  }
  if (counter[0] == n || counter[1] == n) {
    cout << "Yes" << endl;
    return 0;
  }

  if (counter[1] > 1) {
    n -= (counter[1] - 1);
  }
  n -= counter[0];

  if (n - 1 <= counter[0]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3524
/* 
	Author: ankrypt
*/

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

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
map<string, ll> mp;
set<ll> s;
string S = "";
ll cases;
string X[4] = {"AC", "WA", "TLE", "RE"};

int main() {
	go;
    cin >> cases;
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["TLE"] = 0;
    mp["RE"] = 0;
    while(cases--) {
    	cin >> S;
    	mp[S]++;
    }
    for(auto x: X) {
    	cout << x << " x " << mp[x] << " \n";
    }
	return 0;
}
/*
	Powered by Buggy Plugin
*/



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(a) cout << a << " "
#define ALL(a) (a).begin(), (a).end()
#define upper_index(v, a) (int)distance(v.begin(), upper_bound((v).begin(), (v).end(), a))
#define lower_index(v, a) (int)distance(v.begin(), lower_bound((v).begin(), (v).end(), a))

const long long INF = 1e17;

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;
}


int main(){
    int n;
    cin>>n;
    vector<vector<int>> d(n,vector<int>(n,1000000));
    vector<vector<int>> g(n,vector<int>(n,0));
    rep(i,n) {
        string s;
        cin>>s;
        d[i][i]=0;
        rep(j,n) {
            if(s[j]=='1') d[i][j]=1;
            if (d[i][j]==1) g[i][j]=1;
        }
    }
    int cnt=0;
    rep(k,n)rep(i,n)rep(j,n){
        chmin(d[i][j],d[i][k]+d[k][j]);
        if (k==n-1 && d[i][j]!=1000000) chmax(cnt,d[i][j]);
    }
    vector<int> sign(n,0);
    vector<bool> checked(n,false);

    stack<int> stack;
    stack.push(0);
    sign[0]=1;

    while (!stack.empty()){
        int node=stack.top();
        stack.pop();
        if (checked[node]) continue;
        checked[node]=true; 
        rep(i,n){
            if (g[node][i]==1){
                if (sign[i]==0){
                    sign[i]=-sign[node];
                    stack.push(i);
                }else{
                    if (sign[node]==sign[i]){
                        cout<<-1<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<cnt+1<<endl;

    return 0;
}

Measured memory_bytes: 640
-- ABC107 Candles
import Data.Array

main :: IO ()
main = do
  (n:k:_) <- fmap (map read . words) getLine :: IO [Int]
  xs <- fmap (map read . words) getLine :: IO [Int]
  print $ solve n k xs

solve :: Int -> Int -> [Int] -> Int
solve n k xs = foldr min (maxBound :: Int) $ map f [1..(n - k + 1)]
  where
    xarray = listArray (1, n) xs
    f i | left * right < 0 = min (-2 * left + right) (-left + 2 * right)
        | otherwise = max (-left) right
        where
          left = xarray!i
          right = xarray!(i+k-1)


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


int main(){
  string S;
  cin >> S;
  string atgc = "ATGC";
  int ans=0;
  int len=0;
  for(auto s : S){
    if(find(atgc.begin(), atgc.end(), s)==atgc.end()){
      len = 0;
    }else{
      len++;
      ans = max(ans, len);
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n, k, r, s, p;
  string rsp;
  cin >> n >> k >> r >> s >> p >> rsp;
  
  int ans=0;
  for(int i=0; i<k; ++i){
    vector<int> vec(n/k+1);
    for(int j=0; j<(n/k+1); ++j){
      if(j==0){
        if(rsp.at(i) == 'r') vec.at(j) = p;
        if(rsp.at(i) == 's') vec.at(j) = r;
        if(rsp.at(i) == 'p') vec.at(j) = s;
        continue;
      }
      if(n-1 < i+j*k) break;
      else if( vec.at(j-1) ==0 || rsp.at(i+j*k) != rsp.at(i+(j-1)*k)){
        if(rsp.at(i+j*k) == 'r') vec.at(j) = p;
        if(rsp.at(i+j*k) == 's') vec.at(j) = r;
        if(rsp.at(i+j*k) == 'p') vec.at(j) = s;
      }
    }
    int kari=0;
    for(int j=0; j<vec.size(); ++j){
      kari += vec.at(j);
    }
    ans += kari;
  }
  cout << ans << endl;
}

Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<string>
#include<set>
#include<cstdlib>

using namespace std;
typedef long long ll;

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

}



Measured memory_bytes: 3564
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

ll a,b,ans;

int main() {
	scanf("%lld %lld",&a,&b);
	ans=10*b;
	for(int i=0;i<=9;i++)
		if(a==(int)((ans+i)*0.08))
			{printf("%lld\n",ans+i);return 0;}
	puts("-1");
	return 0;
}


Measured memory_bytes: 128
n,m=map(int,input().split())
p=[]
for i in range(m):
    p.append(list(map(int,input().split())))
    p[i].append(i)
p.sort(key=lambda x:x[1])
p.sort(key=lambda x:x[0])
count=0
j=0
for i in range(m):
    if p[i][0] != j:
        count = 1
        j=p[i][0]
    else:
        count += 1
    ans1 = '{0:06d}'.format(p[i][0])
    ans2 = '{0:06d}'.format(count)
    p[i].append(ans1 + ans2)
p.sort(key=lambda x: x[2])
for i in range(m):
    print(p[i][3])

Measured memory_bytes: 38476
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <string>
using namespace std;

struct QuickFind {
    vector<int> i2g;
    vector< vector<int> > g2i;
    vector<long long int> weight;
    int N;

    QuickFind(int N_) {
        N = N_;
        i2g.resize(N); g2i.resize(N);
        weight.resize(N);

        for(int i=0; i<N; i++) {
            i2g[i] = i;
            g2i[i] = vector<int>{i};
        }
    }

    bool same(int u, int v) {
        return i2g[u] == i2g[v];
    }

    long long int query(int u, int v) {
        assert(same(u, v));
        return weight[v] - weight[u];
    }

    void merge(int u, int v, int w) {
        if(same(u, v)) return;
        int ru = i2g[u], rv = i2g[v];

        if(g2i[rv].size() > g2i[ru].size()) {
            swap(ru, rv); swap(u, v);
            w = -w;
        }

        long long int prev = weight[v];
        weight[v] = weight[u] + w;

        for(auto e : g2i[rv]) {
            i2g[e] = ru;
            g2i[ru].push_back(e);
            if(e == v) continue;
            int diff = weight[e] - prev;
            weight[e] = weight[v] + diff;
        }

        g2i[rv].clear();
    }
};

int main() {
    int N, Q; cin >> N >> Q;
    QuickFind qf(N);
    for(int i=0; i<Q; i++) {
        int query; cin >> query;
        if(query == 0) {
            int u, v, w; cin >> u >> v >> w;
            qf.merge(u, v, w);
        }
        else {
            int u, v; cin >> u >> v;
            if(qf.same(u, v)) cout << qf.query(u, v) << endl;
            else cout << "?" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 10548
import java.util.Scanner;

/**
 * TAKOYAKI FESTIVAL 2019
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] D = new int[N];
            for (int i = 0; i < N; i++) {
                D[i] = sc.nextInt();
            }

            long sum = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    sum += D[i] * D[j];
                }
            }

            System.out.println(sum);
        }
    }

}


Measured memory_bytes: 21844
H, W = map(int, input().split())

A = [list(input()) for _ in range(H)]
length = 0
for a in A:
    for s in a:
        if s == '#':
            length += 1


def dfs(i, j, cnt):
    if i == H - 1 and j == W - 1:
        return cnt == length - 1
    else:
        if i < H - 1 and A[i + 1][j] == '#':
            return dfs(i + 1, j, cnt + 1)
        elif j < W - 1 and A[i][j + 1] == '#':
            return dfs(i, j + 1, cnt + 1)
        else:
            return False


print('Possible' if dfs(0, 0, 0) else 'Impossible')


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 100000000

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll q; cin >> q;
    deque<ll> A;
    ll s, t, u;

    rep(i, q) {
        cin >> s;
        if (s == 0) {
            cin >> t >> u;
            if (t == 0) {
                A.push_front(u);
            }
            else {
                A.push_back(u);
            }
        }
        else if (s == 1) {
            cin >> t;
            cout << A[t] << endl;
        }
        else {
            cin >> t;
            if (t == 0) {
                A.pop_front();
            }
            else {
                A.pop_back();
            }
        }
    }

}


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

int main() {
    int n;
    double sum = 0.0, ans;
    cin >> n;
    vector<double> x(n), y(n);
    rep(i, n) cin >> x.at(i) >> y.at(i);
    for(int i = 0; i < n - 1; i++) {
        for(int j = i + 1; j < n; j++) {
            sum += sqrt((x.at(i) - x.at(j)) * (x.at(i) - x.at(j)) + (y.at(i) - y.at(j)) * (y.at(i) - y.at(j)));
        }
    }
    ans = 2.0 * sum / n;
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	int T, A, B;

	cin >> T >> A >> B;

	if(T*A<B){
		cout << T*A << endl;
	}
	else{
		cout << B << endl;
	}
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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 INF=1e18;
const int MOD=1e9+7;

signed main(){
    int N;cin>>N;
    bool allp=true,allm=true;
    vector<int>A(N),ABS(N);
    REP(i,N){
        cin>>A[i];
        if(A[i]>=0)allm=false;
        if(A[i]<=0)allp=false;
        ABS[i]=abs(A[i]);
    }
    sort(all(ABS));
    int z=ABS[0];
    queue<int>P;
    queue<int>M;
    bool check=true;
    if(allm||allp)check=false;
    int ans=0;
    REP(i,N){
        if(check||z<abs(A[i])){
            if(A[i]>0)P.push(A[i]);
            if(A[i]<0) M.push(A[i]);
            if(A[i]==0){
                if(M.size()==0)M.push(0);
                else P.push(0);
            }
            ans+=abs(A[i]);
        }
        else{
            check=true;
            ans-=abs(A[i]);
            if(A[i]>=0)M.push(A[i]);
            else P.push(A[i]);
        }
    }
    cout<<ans<<endl;
    REP(i,N-1){
        if(P.size()>1){
            int p=P.front();P.pop();
            int m=M.front();M.pop();
            cout<<m<<" "<<p<<endl;
            M.push(m-p);
        }
        else{
            int p=P.front();P.pop();
            int m=M.front();M.pop();
            cout<<p<<" "<<m<<endl;
            P.push(p-m);
        }
    }
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 998244353
#define NUM 200010

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int pid=0,pnum=0,rpid[NUM];LL cost[NUM],rcost[NUM],cpid[NUM],que[NUM];
int judge(int a,int b){if(pnum<b||b==1)return 0;return cpid[que[a]]>cpid[que[b]]?1:0;}
void push(LL a,int n){int i=++pid,j=++pnum;rpid[i]=n,cpid[i]=a,que[j]=i;while(judge(j/2,j))que[j]=que[j/2],que[j/=2]=i;}
int pop(){int ans=rpid[que[1]],i=1,j;LL n=que[pnum--];que[1]=n;while(judge(i,j=i*2+judge(i*2,i*2+1)))que[i]=que[j],que[i=j]=n;return ans;}
void Dijkstra(int v,int e,int* a,int* b,int* l,int ver){int i,flag[NUM]={0},pre[e],last[v+1];FOR(i,1,v+1)cost[i]=LNF,last[i]=-1;cost[ver]=0;FOR(i,0,e)pre[i]=last[a[i]],last[a[i]]=i;while(flag[ver]==0){flag[ver]++;for(i=last[ver];i+1;i=pre[i])if(cost[b[i]]>cost[ver]+l[i]){cost[b[i]]=cost[ver]+l[i];push(cost[b[i]],b[i]);}while(flag[ver]&&pnum)ver=pop();}}


int main(){
  int N,M,i,ans=0;
  scanf("%d%d",&N,&M);
  int L[N+M-1],R[N+M-1],C[N+M-1];
  FOR(i,0,N-1)L[i]=i+2,R[i]=i+1,C[i]=0;
  FOR(i,N-1,N+M-1)scanf("%d%d%d",&L[i],&R[i],&C[i]);
  Dijkstra(N,N+M-1,L,R,C,1);

  printf("%lld\n",cost[N]<LNF?cost[N]:-1);
	return 0;
}


Measured memory_bytes: 10752
N = int(input())
A  = [input() for _ in range(N)]
c0=A.count("AC")
c1=A.count("WA")
c2=A.count("TLE")
c3=A.count("RE")
print("AC x",c0)
print("WA x",c1)
print("TLE x",c2)
print("RE x",c3)

Measured memory_bytes: 16296
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
	double n;
	cin >> n;
	double end = (n / 3) * (n / 3) * (n / 3);
	printf("%0.12lf", end);
}

Measured memory_bytes: 256
s = input()
akiba = ["KIHBR", "KIHABR", "KIHBAR", "KIHABAR"]

new_akiba = []
for aki in akiba:
	new_akiba.append("A" + aki)
akiba += new_akiba
new_akiba = []
for aki in akiba:
	new_akiba.append(aki + "A")
akiba += new_akiba
if s in akiba:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll          = long long;
using db          = double;
using ld          = long double;
using uint        = unsigned int;
using ull         = unsigned long long;

using pii         = pair<int, int>;
using pll         = pair<ll, ll>;
using tiii        = tuple<int, int, int>;

#define mod7        1000000007
#define mod9        1000000009

#define forall(v)   v.begin(), v.end()
#define prec(x)     setprecision(x) << fixed

/* [💭] [💡] [🎈] */

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

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(a, b) << ' ' << max(0, a + b - n);

    return 0;
}

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

typedef long long int ll;

int main(){

    ll n;
    cin>>n;

    ll arr[n];
    for(ll i=0;i<n;i++)cin>>arr[i];
    ll e = 0;
    ll o = 0;
    for(ll i=0;i<n;i++){
        if(arr[i]%2==0){
            e+=1;
        }else{
            o+=1;
        }
    }

    if(o%2==0){
        cout<<"YES"<<endl;
    }else
    cout<<"NO"<<endl;


}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;
int main(){
    int n,m=0;
    cin>>n>>m;
    cout<< ((n>m)?"a > b":(n==m)?"a == b":"a < b")<<endl;
}



Measured memory_bytes: 3092
s = list(input())
t = s[::-1]
for i, k in enumerate(t):
  if k == "b":
    t[i] = "d"
  elif k == "d":
    t[i] = "b"
  elif k == "p":
    t[i] = "q"
  elif k == "q":
    t[i] = "p"
if s == t:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 4652
#include<stdio.h>

int dp[50];

int fib(int n)
{
	if(n == 0 || n == 1) return dp[n] = 1;
	if( dp[n] != -1) return dp[n];
	return dp[n] = fib(n-1)+fib(n-2);
}

int main()
{
	int n , i;
	for( i = 0; i < 50; i++)
	{
		dp[i] = -1;
	}
	scanf("%d",&n);
	printf("%d\n",fib(n));
	return 0;
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 1e5+500;
const int inf = 0x3f3f3f3f;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000010LL;
#define X first
#define Y second

int n,p;
char s[maxN];
int main() {
	scanf("%s",s+1);
	int n = strlen(s+1);
	int ans = 0;
	for(int i=1;i<=n/2;i++)
	{
		if(s[i] != s[n+1-i])
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin>>s;
  ll sum = 0;
  for(int i=0;i<s.size();i++){
    ll x = s[i]-'0';
	sum+=x;
  }
  if(sum%9)
	  cout<<"No\n";
  else
      cout<<"Yes\n";
  return 0;
}

Measured memory_bytes: 3696
from functools import reduce
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)

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

n, m = map(int, input().split())
A = list(map(lambda x: int(x) // 2, input().split()))

l = reduce(lcm, A, 1)
for a in A:
    if((l // a) % 2 == 0):
        print(0)
        break

else:
    ans = (m // l +1) // 2
    print(ans)

Measured memory_bytes: 14748
x = [1,3,5,7,8,10,12]
y = [4,6,9,11]
z = [2]
a, b=map(int, input().split())
if (a in x and b in x) or (a in y and b in y) or (a in z and b in z):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9048
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> p(n);
  for(Int i=0;i<n;i++) cin>>p[i];

  vector<Int> ans;
  auto mov=
    [&](Int k){
      if(k==0||k==n) return;
      ans.emplace_back(k);
      for(Int i=k;i<n;i++)
	swap(p[i],p[i-k]);
    };

  for(Int t=0;t<n;t++){
    mov(1);
    for(Int i=1;i<n;i++){
      if(p[0]<p[n-1]) mov(n-1);
      mov(1);
    }
  }
  
  assert(is_sorted(p.begin(),p.end()));
  cout<<ans.size()<<endl;
  for(Int x:ans) cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1000006];
void fun(int n, ll cnt)
{
  if (a[n]!=0)
  {
    cout<<cnt+1<<endl;
    return ;
  }
  a[n]++;
  if (n%2==0)
  {
    fun(n/2,cnt+1);
  }
  else
   fun(3*n+1,cnt+1);
  return ;
}
int main()
{
  int g;
  cin>>g;
  fun(g,0);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    string  str;cin>>str;
    int ans=0,max=str.size();
    rep(i,max/2+1){
        if(str[i]!=str[max-i-1]){
            str[i]=str[max-i-1];
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define    ll     long long int

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

int h, w;

int isValid(int x, int y)
{
    if (x >= 0 && x < h && y >= 0 && y < w) {
        return 1;
    }
    return 0;
}

int main( )
{
    cin >> h >> w;
    string grid[55];
    int i, j, k, c = 0;
    for (i = 0; i < h; i++) {
        cin >> grid[i];
    }
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            if (grid[i][j] == '.') {
                c = 0;
                for (k = 0; k < 8; k++) {
                    int x = i + dx[k];
                    int y = j + dy[k];
                    if (isValid(x, y) && grid[x][y] == '#')
                        c++;
                }
                grid[i][j] = char(c + '0');
            }
        }
    }
    for (i = 0; i < h; i++) {
        cout << grid[i] << '\n';
    }
    return 0;
}



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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
int n, k, a[N];
int tree[N * 4];

void change(int i, int l, int r, int pos, int val) {
    if (l == r) {
        tree[i] = val;
        return;
    }
    int mid = l + r >> 1;
    if (pos <= mid)change(i << 1, l, mid, pos, val);
    else change(i << 1 | 1, mid + 1, r, pos, val);
    tree[i] = max(tree[i << 1], tree[i << 1 | 1]);
}

int ask(int i, int l, int r, int L, int R) {
    if (L <= l && r <= R) { return tree[i]; }
    int mid = l + r >> 1;
    int ans = -1;
    if (L <= mid)ans = max(ans, ask(i << 1, l, mid, L, R));
    if (R > mid)ans = max(ans, ask(i << 1 | 1, mid + 1, r, L, R));
    return ans;
}

int dp[N];

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)cin >> a[i], a[i]++;
    int maxx = *max_element(a + 1, a + n + 1);
    dp[a[1]] = 1;
    change(1, 1, maxx, a[1], 1);
    for (int i = 2; i <= n; i++) {
        int ans = ask(1, 1, maxx, max(1, a[i] - k), min(maxx, a[i] + k));
        dp[a[i]] = max(ans + 1, dp[a[i]]);
        change(1, 1, maxx, a[i], dp[a[i]]);
    }
    int out = 0;
    for (int i = 1; i <= maxx; i++)
        out = max(out, dp[i]);
    cout<<out;
    return 0;
}


Measured memory_bytes: 10148
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

min_ab = min(a) + min(b)

for _ in range(M):
    x, y, c = map(int, input().split())
    min_ab = min(min_ab, a[x - 1] + b[y - 1] - c)
print(min_ab)

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

int64_t f(int64_t n){
    return n*(n-1)/2;
}

int main(){
    int n;
    cin>>n;
    
    vector<int64_t> a(n);
    rep(i,n)cin>>a[i], a[i]--;
    
    vector<int64_t> m(n,0);
    rep(i,n)m[a[i]]++;
    
    int64_t ans = 0;
    rep(i,n)ans += f(m[i]);
    
    for(int i=0; i<n; i++){
        cout << ans -( m[a[i]] - 1 ) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		long n = Long.parseLong(t[0]);
		long k = Long.parseLong(t[1]);

		long min = Math.min(n, n % k);
		min = Math.min(min, (n % k) + k);
		min = Math.min(min, Math.abs((n % k) - k));

		System.out.println(min);
	}
}


Measured memory_bytes: 35856
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	long long a[200000+5];
	long long n,min,x,sum;
	while (cin>>n)
	{
		sum=min=0;
		for (int i=0;i<n;i++)
		{
			cin>>a[i];
			min=min+fabs(a[i]);
			sum=sum+a[i];
		}
		x=0;
		for (int i=n-1;i>0;i--)
		{
			x=x+a[i];
			if(fabs(2*x-sum)<min)
			min=fabs(2*x-sum);
		}
		cout<<min<<endl;
	}
return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    // amaxとamx/2に近いほうの組み合わせ
    sort(a.begin(), a.end(), greater<>());
    ll num1 = a.at(0), num2 = a.at(0);
    double mind = INF;
    double diff = 0;
    rep(i,n){
        diff = abs(num1/2.0-a.at(i));
        mind = min(mind, diff);
        if(mind==diff) num2 = a.at(i);
    }
    cout << num1 << " " << num2 << endl;
}

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned int
#define uint64_t unsigned long long

#define int8_t signed char
#define int16_t signed short
#define int32_t signed int
#define int64_t signed long long

using namespace std;
bool isInclude(int target,int* p, int N)
{
  for(int j = 0; j < N; j++) {
    if (p[j] == target) {
      return true;
    }
  }
  return false;
}


int main(int argc, char const* argv[])
{
    int X = 0;
    int N = 0;
  	int p[100] = {};
  
    cin >> X >> N;
  	REP(i, N) cin >> p[i];
    
  	int ans_l = -100;
  	for (int i = X; i >= -1; i--) {
    	if (isInclude(i,p,N)) {
        	continue;
        }
        else {
          	ans_l = i;
        	break;
        }
    }
  	int ans_h = 200;
    for (int i = X; i < 102; i++) {
    	if (isInclude(i,p,N)) {
        	continue;
        }
        else {
          	ans_h = i;
        	break;
        }
    }
	if (abs(X-ans_l) <= abs(X-ans_h)) {
    	cout << ans_l << endl;
    }  
  	else {
        cout << ans_h << endl;
    }
  
    return 0;
}




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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;
//const int mod = 998244353;


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

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  --a; --b; --c; --d;
  auto check = [&](int st, int g) {
    rep(i, g-st-1) {
      if(s[st+i] == '#' && s[st+i+1] == '#') return false;
    }
    return true;
  };
  if(c < d) {
    if(check(a, c) && check(b, d)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else {
    bool ok = false;
    for(int i = b; i <= d; ++i) if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') ok = true;
    if(check(a, c) && check(b, d) && ok) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


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

int main(){
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    int i=0;
    bool sw = true;
    while(i < s.size()){
        if(s.size()-i < 5){
            sw = false;
            break;
        }
        string t = s.substr(i,5);
        if(t == "maerd"){
            i += 5;
        }
        else if(t == "esare"){
            i += 5;
        }
        else if(s.size()-i >=6){
            string u = s.substr(i,6);
            if(u == "resare"){
                i += 6;
            }
            else if(s.size()-i >=7){
                string r = s.substr(i,7);
                if(r == "remaerd"){
                    i += 7;
                }
                else{
                    sw = false;
                    break;
                }
            }
            else{
                sw = false;
                break;
            }
        }
        else{
            sw = false;
            break;
        }
    }
    if(sw){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int n,i,max,min;
    long long sum=0;
    int a[100000];
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
        sum=sum+a[i];
        if(i==1){
            max=a[i];
            min=a[i];
        }
        else{
            if(max<a[i]){
                max=a[i];
            }
            if(min>a[i]){
                min=a[i];
            }
        }
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
long long  p[200000],q[200000],r[200000];
int  main()
{
	long long  x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;

	for (long long  i = 0; i < a; ++i)
	{
		cin>>p[i];
	}
	for (long long  i = 0; i < b; ++i)
	{
		cin>>q[i];
	}
	for (long long  i = 0; i < c; ++i)
	{
		cin>>r[i];
	}

	sort(p,p+a,greater<long long >());
	sort(q,q+b,greater<long long >());
	sort(r,r+c,greater<long long >());

	std::vector<long long > v;
	for (long long  i = 0; i < x; ++i)
	{
		v.push_back(p[i]);
	}
	for (long long  i = 0; i < y; ++i)
	{
		v.push_back(q[i]);
	}

	sort(v.begin(),v.end(),greater<long long >());
	long long  sum = 0,f=0;
	long long  c1 = 0,c2=0,cnt=0;
	// for (long long  i = 0; i < c; ++i)
	// {
	// 	if(r[i]>v[cnt])
	// 	{
	// 		v[cnt] = r[i];
	// 		cnt++;
	// 	}
	// }

	while(cnt<x+y)
	{
		if(f==1)
		{
			sum+=v[c1];
			c1++;
		}
		else if(v[c1]>=r[c2])
		{
			sum+=v[c1];
			c1++;
		}
		else
		{
			sum+=r[c2];
			c2++;
			if(c2==c)
			{
				f = 1;
			}
		}
		cnt++;
	}
	cout<<sum<<endl;
	
	return 0;
}

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

int a[100],x[10],l,MAX[10],MIN[10],y[10],z,w;

int saidai(){
  //max
  int i,j,mae=0,tmp,t;
  tmp =0;
  for(j = 0;j < l ;j++){
    i = x[0];
    for(t = 0; t < l ;t++){
      if(i <= x[t]){
	i = x[t];
	tmp = t;
      }
    }
    x[tmp] = 0;
    MAX[j] = i;
    mae += MAX[j] * pow(10,l-j-1);
  }
  return mae;
}
int saisyou(){
  int ato,i,j,tmp,t;
  //min
  ato =0;
  tmp = 0;
  for(j = 0;j < l ;j++){
    i = y[0];
    for(t = 0; t < l ;t++){
      if(i >= y[t]){
	i = y[t];
	tmp = t;
      }
    }
    y[tmp] = 9;
    MIN[j] = i;
    ato += MIN[j] * pow(10,l-j-1);
  } 
  return ato;
} 

int main(){

  while(1){
 
    int i,j,t,b,tmp,z,sa,ansi,ansj;

    cin >> a[0] >> l;
    //終了
    if(a[0] == 0 && l == 0)
      break;

    b = pow(10,l-1);
    for(t = 0;t < l;t++){
      x[t] = a[0] / b % 10 ;
      y[t] = x[t];
      b /=10;

    }
   
    //a[i]
    for(i = 1;i < 21 ;i++){
      z = saidai();
      w = saisyou(); 
      a[i] = z - w;
      //     cout << z << " - " << w << " = " << a[i] <<endl;
      b = pow(10,l-1);
      for(t = 0;t < l;t++){
	x[t] = a[i] / b % 10 ;
	y[t] = x[t];
	b /=10;
      }
    }


  
    sa = 100;
    tmp =0;
    for(j = 0; j <= 19 ;j++){
      if(tmp ==1) break;
      for(i = j+1;i <= 20 ;i++){	
	if(a[j] == a[i]){
	  tmp = 1;
	  sa = i-j;
	  ansi = i;
	  ansj = j;
	  break;
	}
      }	   
    }
  
    cout << j-1 << " " << a[ansj] << " " << i-j+1 << endl;
 
  }
  return 0;
}

  

Measured memory_bytes: 1208
#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;
    cin >> n;
    vector<int> A(n);
    rep(i, n) cin >> A[i];
    vector<int> B(n);
    rep(i, n) B[i] = A[i] - i;
    sort(B.begin(), B.end());
    ll ans = 0;
    rep (i, n) {
        int a = upper_bound(B.begin(), B.end(), -A[i]-i) - lower_bound(B.begin(), B.end(), -A[i]-i);
        ans += a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll h;
    cin>>h;
    ll steps=1;
    while(h>1){
        h/=2;
        steps++;
    }
    ll ans = (1LL<<steps) - 1LL;
    cout<<ans;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

N, A, B = map(int, input().split())

tmp1 = pow(2, N, MOD) - 1 #1本以上の選び方

#計算量 log(m)くらい
def modinv(a, m): #mod. m でのaの逆元 a^{-1}を計算する
    b = m
    u = 1
    v = 0
    while b:
        t = a//b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    
    u %= m
    if u < 0:
        u += m
    return u


def combination(n, r): #nCrを求める
    if n - r < r:
        r = n - r
    tmp1 = 1
    for i in range(n - r + 1, n + 1):
        tmp1 *= i
        tmp1 %= MOD
    tmp2 = 1
    for i in range(1, r + 1):
        tmp2 *= i
        tmp2 %= MOD
    return tmp1 * modinv(tmp2, MOD)

tmp2 = combination(N, A)
tmp3 = combination(N, B)

print ((tmp1 - tmp2 - tmp3) % MOD)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n1) for(int i=0;i<n1;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
#define PI 3.141592653589793
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const ll inf=1000000007;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vector<Pii> v[100001];
ll dp[300000][60]={};
ll dp2[300000][60]={};
ll a[300000];
int main() {
	int n;
	cin>>n;
	ll r=0;
	ll ndp1[60]={};
	ll ndp2[60]={};
	ll s1[60];
	s1[0]=1;
	rep(i,59)s1[i+1]=s1[i]*2;
	rep(i,n){
		cin>>a[i];
		rep(j,60){
			if((a[i]&s1[j])>0){
				ndp1[j]++;
			}else{
				ndp2[j]++;
			}
			dp[i][j]=ndp1[j];
			dp2[i][j]=ndp2[j];
		}
	}	
	rep(i,n-1){
		rep(j,60){
			if((a[i]&s1[j])>0){

				r+=(s1[j]%inf)*(dp2[n-1][j]-dp2[i][j]);
				r%=inf;
			}else{
				r+=(s1[j]%inf)*(dp[n-1][j]-dp[i][j]);
				r%=inf;
			}

		}
	}
	cout<<r<<endl;

	return 0;
}


Measured memory_bytes: 286208
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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 ll mod = 1e9+7;




int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0,num=0;
    rep(i,s.size()){
        if(s[i] == 'R'){
            num ++;
        }else{
            ans = max(num,ans);
            num = 0;
        }
    }
    ans = max(ans,num);

    cout << ans << endl;
    return 0;


}


Measured memory_bytes: 3636