akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    string S;
    cin >> S;
    
    i64 cnt=0;
    rep(i,0,S.size()){
        if(S[i]=='o') ++cnt;
    }
    
    cnt+=15-S.size();
    
    cout << (cnt>=8?"YES":"NO") << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(){
	vector<int> a(3);
	rep(i,3)cin>>a[i];
	sort(a.begin(), a.end());
	
	printf("%d %d %d\n",a[0],a[1],a[2]);
}

Measured memory_bytes: 1188
from sys import stdin
N=int(stdin.readline().rstrip())
T,A=[int(x) for x in stdin.readline().rstrip().split()]
elev=[int(x) for x in stdin.readline().rstrip().split()]
cnt=0
comp=10000
for i in elev:
    cnt+=1
    temperature=T-(i*0.006)
    tmp=abs(A-temperature)
    if comp > tmp:
        comp=tmp
        ans=cnt
print(ans)

Measured memory_bytes: 3064
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)]
N = n*(n-1)//2
index = {}
ind = 0
from collections import defaultdict
ns = defaultdict(list)
for i in range(n):
    for j in range(i+1,n):
        index[i,j] = ind
        index[j,i] = ind
        ind += 1
for i in range(n):
    for j in range(n-2):
        u = index[i,a[i][j]]
        v = index[i,a[i][j+1]]
        ns[u].append(v)
### サイクル検出 cycle detection
seen = [False] * N
done = [False] * N
vals = [None] * N
def dfs(u):
    s = [u]
    while s:
        u = s.pop()
        if u>=0:
            seen[u] = True
            s.append(~u)
            for v in ns[u]:
                if done[v]:
                    continue
                elif not seen[v]:
                    s.append(v)
                else:
                    # 閉路発見
                    return True
        else:
            u = ~u
            done[u] = True
            # ここに帰りがけ処理を書く
            val = 0
            for v in ns[u]:
                val = max(val, vals[v]+1)
            vals[u] = val
    return False

ans = -float("inf")
for u in range(N):
    if seen[u]:
        continue
    pos = dfs(u)
    if pos:
        print(-1)
        break
else:
    print(max(vals)+1)

Measured memory_bytes: 272980
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N, 0);
    rep(i, N) cin >> A[i];

    rep(l, K) {
        bool flag = true;
        rep(i, N) {
            if (A[i] != N) flag = false;
        }
        if (flag) break;
        vector<int> sum(N + 2, 0); 
        rep(i, N) {
            int l = i - A[i], r = i + A[i] + 1;
            l = max(0, l);
            r = min(r, N + 1);
            sum[l]++;
            sum[r]--;
        }

        rep(i, N + 1) {
            sum[i + 1] += sum[i];
        }

        rep(i, N) {
            A[i] = sum[i];
        }
    }

    rep(i, N - 1) cout << A[i] << " ";
    cout << A[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 4796
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define P 998244353 
using namespace std;
int sum,n,x,ans;
bool f[2200*2200];
int a[2200],q[2200*2200],tail;
int add(int x){
	for(int i=tail;i>=1;i--){
		if(f[q[i]+x]==0)q[++tail]=q[i]+x,f[q[i]+x]=1;
	}
}
int main(){
	scanf("%d",&n);
	f[0]=1;
	tail=1;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		x=a[i];	
		add(x);
		sum+=x;
	}
	for(int i=0;i<=sum;i++)if(f[i])ans++;
	ans/=2;
	for(int i=1;i<=sum;i++){
		if(f[i])ans--;
		if(ans==0){
			printf("%d\n",i);
			return 0;
		}
	}
}

Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
int D,ans=0,G;
int bitsearch(bitset<10> b,vector<int> &p,vector<int> &c){
    int score=0, num=0;
    for(int i=0;i<10;i++){
        if(b[i]==1){
         	score+=100*(i+1)*p[i]+c[i];
            num+=p[i];
        }
    }
    if(score>=G||num>=ans) return (num<ans?num:ans);
    int i=D-1;
    for(;i>=0&&b[i]!=0;i--);
    if((i==0&&b[0]==1)||G-score>100*(i+1)*(p[i]-1)) return ans;
    return num+(G-score)/100/(i+1)+((G-score)/100%(i+1)==0?0:1);
}
int main(){
    cin>>D>>G;
    vector<int> P(D);
  	vector<int> C(D);
    for(int i=0;i<D;i++){
        int p,c;
        cin>>p>>c;
        P[i]=p, C[i]=c;
        ans+=p;
    }
    for(int i=0;i<(1<<D);i++){
        bitset<10> b(i);
        ans=min(bitsearch(b,P,C),ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

const int mod = 1000000007;
const int N = 1000005;
char s[N];
int fac[N<<1], inv[N<<1];
int main(){
    int k;
    scanf("%d %s",&k,s+1);
    int n = strlen(s+1);
    auto mul = [&] (int a, int b){
        return a * 1ll * b % mod;
    };
    auto add = [&] (int a, int b){
        int c = a+b;
        if(c >= mod) return c-mod;
        return c;
    };
    auto bp = [&] (int a, int b){
        int i, ans = 1, res = a;
        for(i=1;i<=b;i<<=1,res=mul(res,res)){
            if(i&b) ans=mul(ans,res);
        }
        return ans;
    };
    auto cnr = [&] (int a, int b){
        return mul(fac[a], mul(inv[b], inv[a-b]));
    };
    fac[0] = inv[0] = 1;
    FOR(i, 1, n+k){
        fac[i] = mul(fac[i-1], i);
        inv[i] = bp(fac[i], mod-2);
    }
    int ans = 0;
    FOR(i, 0, k){
        ans = add(ans, mul( bp(26, i), mul( cnr(n+k-1-i, n-1), bp(25, k-i) ) ) );
    }
    printf("%d",ans);
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 20272
#include <iostream>

using namespace std;

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

    int ans;
    if(A<0){
        ans=-A*C+D+B*E;
    }
    if(A>0){
        ans=(B-A)*E;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <map>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin>>s;
    
    ll total=0;
    int n=s.size()-1;
    for(int bit=0; bit<(1<<n); ++bit) {
        ll num=stoi(s.substr(0,1));
        ll ans=0;
        for(int i=0; i<n; ++i) {
            if(bit&(1<<i)) {
                ans+=num;
                num=0;
            }
            else num*=10;
            num+=stoi(s.substr(i+1,1));
        }
        ans+=num;
        total+=ans;
    }
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int N;
	while(cin >> N){
		long long res = 0;
		int p = 1;
		for(int i=0;i<N;i++){
			int v; cin >> v;
			int b = (v-1)/p;
			if(b > 0){
				res += b;
				if(p==1) p = 2;
			} else if(p == v){
				p = v+1;
			}
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_N = 1e5 + 2;

int n;
int MOD;
vector<int> g[MAX_N];
vector<int> subtree[MAX_N];

vector<ll> prf[MAX_N];
vector<ll> suf[MAX_N];
ll dp_down[MAX_N], dp_up[MAX_N];

void add_edge(int from, int to)
{
    g[from].push_back(to);
    g[to].push_back(from);
}
 
void dfs(int x, int par) {
    for (int i=0; i<g[x].size(); i++) {
        int y = g[x][i];
        if (y != par) {
            subtree[x].push_back(y);
            dfs(y, x);
        }
    }
}
 
void solve_down(int x) {
    const int sz = subtree[x].size();
    prf[x].resize(sz);
    suf[x].resize(sz);
 
    dp_down[x] = 1;
    for (int i = 0; i < sz; i++) {
        int y = subtree[x][i];
        solve_down(y);
        dp_down[x] = (dp_down[x] * (1 + dp_down[y]))%MOD;
    }
    for (int i = 0; i < sz; i++) {
        int y = subtree[x][i];
        prf[x][i] = 1 + dp_down[y];
        if (i != 0) {
            (prf[x][i] *= prf[x][i - 1])%=MOD;
        }
    }
    for (int i = sz - 1; i >= 0; i--) {
        int y = subtree[x][i];
        suf[x][i] = 1 + dp_down[y];
        if (i != sz - 1) {
            (suf[x][i] *= suf[x][i + 1])%=MOD;
        }
    }
}
 
void solve_up(int x) {
    if (x == 1) dp_up[x] = 1;
    const int sz = subtree[x].size();
    for (int i = 0; i < sz; i++) {
        int y = subtree[x][i];
        dp_up[y] = dp_up[x];
        if (i != 0) (dp_up[y] *= prf[x][i - 1])%=MOD;
        if (i != sz - 1) (dp_up[y] *=suf[x][i + 1])%=MOD;
        (dp_up[y] += 1)%=MOD;
        solve_up(y);
    }
}

void solve()
{
    dfs(1,-1);
    solve_down(1);
    solve_up(1);
    for (int i = 1; i <= n; i++)
		printf("%lld\n", (dp_down[i] * dp_up[i]) % MOD);
}
 
int main() 
{
    scanf("%d%d", &n, &MOD);
    int x, y;
    for (int i=0; i<n-1; i++) {
        scanf("%d%d", &x, &y);
        add_edge(x, y);
    }
	solve();
    return 0;
}

Measured memory_bytes: 32952
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n+1), b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,n) {
        ll tmp = min(a[i], b[i]);
        ans += tmp; a[i] -= tmp; b[i] -= tmp;
        if (b[i] > 0) {
            ll tmp2 = min(a[i+1], b[i]);
            ans += tmp2; a[i+1] -= tmp2; b[i] -= tmp2;
        }
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

ll dobi(string s)
{
    ll n = (s[0]-'0')*100;
    n += (s[2]-'0')*10;
    n += (s[3]-'0');
    return n;
}

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

    ll res = 0LL;
    ll a;
    cin >> a;
    string s;
    cin >> s;
    ll b = dobi(s);
    res = (a * b) / 100;
    cout << res << '\n';
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    set<string> O;
    string W;
    cin >> W;
    O.insert(W);
    bool kanan = true;
    for (int i = 0;i < N-1;i++) {
        string w;
        cin >> w;
        if(W.back() != w.front()){
            kanan = false;
        }
        if(O.find(w) != O.end()){
            kanan = false;
        }
        W = w;
        O.insert(w);
    }
    if(kanan == true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env php
<?php
function genInputs() {
    while(($input = rtrim(fgets(STDIN))) !== false) {
        foreach (explode(' ', $input) as $v) {
            yield $v;
        }
    }
}
function getNext($gen) {
    $value = $gen->current();
    $gen->next();
    return $value;
}
$gen = genInputs();

$s = getNext($gen);
$n = 0;
for ($i = 0; $i < strlen($s); $i++) {
    if ($s[$i] == 1) {
        $n++;
    }
}
echo $n.PHP_EOL;


Measured memory_bytes: 4728
N = int(input())
A = list(map(int, input().split()))

A_max = max(A)
A.remove(A_max)
A_min = min(A)
A.remove(A_min)

moves = []
for i in range(N-2):
    if A[i] <= 0:
        moves.append(str(A_max)+' '+str(A[i]))
        A_max = A_max - A[i]
    else:
        moves.append(str(A_min)+' '+str(A[i]))
        A_min = A_min - A[i]
moves.append(str(A_max)+' '+str(A_min))
print(A_max-A_min)
for move in moves:
    print(move)

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

map<int64_t, int> prime_factor(int64_t n) {
    map<int64_t, int> ret;
    for(int64_t i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

void Main();
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
    Main();
    return 0;
}

void Main() {
    int N;
    cin >> N;
    cout << N << ":";
    for (auto p : prime_factor(N)) {
        while(p.second--) cout << " " << p.first;
    }
    cout << endl;
}


Measured memory_bytes: 3200
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int N,M;

int v[10][10000];
int a[10];
int m;

int main(){

    cin.sync_with_stdio(false);

    while(1){

    cin >> N >> M;

    if(N==0 && M==0)break;

    for(int i=0;i<N;++i)
        for(int j=0;j<M;++j)
            cin >> v[i][j];

    m=0;

    memset(a,0,sizeof(a));

    for(int i=0;i<=N;++i){

        for(int j=0;j<i;++j) a[N-1-j]=1;

        do{

            int s=0;

            for(int k=0;k<M;++k){

                int ts=0;

                for(int l=0;l<N;++l){

                    ts += (v[l][k]+a[l])%2;

                }

                s += max(ts,N-ts);
            }

            m = max(m,s);


        }while(next_permutation(a,a+N));

    }

    cout << m << endl;

    }

    return 0;

}

Measured memory_bytes: 1580
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        String str = scanner.next();
        int a = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '+') {
                a++;
            } else {
                a--;
            }
        }
        System.out.println(a);
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

typedef long long ll;

const int MAXN = 2e5 + 10;

int n, k, arr[MAXN];

bool check(int x) {
    ll cnt = 0;
    rep(i, 1, n) cnt += (arr[i] - 1) / x;
    return cnt <= k;
}

int main() {
    IO::read(n), IO::read(k);
    rep(i, 1, n) IO::read(arr[i]);
    int l = 1, r = *max_element(arr + 1, arr + n + 1), ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (check(mid)) r = mid - 1, ans = mid;
        else l = mid + 1;
    }
    printf("%d\n", ans);
    return 0;
}

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

int n;
vector<vector<P>> h(20, vector<P>(0));

bool check(int S){
  rep(i, n){
    if(!(S & (1 << i))) continue;
    for(auto x : h[i]){
      if((bool)(S & (1 << x.first)) != x.second)
        return false;
    }
  }
  return true;
}

int main(){
  cin >> n;
  rep(i, n){
    int a; cin >> a;
    rep(j, a){
      P tmp;
      cin >> tmp.first >> tmp.second;
      tmp.first--;
      h[i].emplace_back(tmp);
    }
  }
  //rep(i, n) for(auto x : h[i]) cerr << x.first << x.second << endl;
  int res = 0;
  for(int S = 0; S < (1 << n); S++){
    if(check(S)) res = max(res, __builtin_popcount(S));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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 main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    // 降順
    sort(all(a));
    reverse(all(a));

    ll ans = 0;
    priority_queue<ll> q;
    q.push(a[0]);
    for (int i = 1; i < n; i++) {
        ans += q.top();
        q.pop();
        q.push(a[i]);
        q.push(a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6924
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

string s,t;
int main(){
  cin >> s >> t;
  vector<string> ans;

  for(int i = 0;i + t.size() <= s.size();i++){
    bool ok = true;
    string temp = s;
    for(int j = 0;j < t.size();j++){
      ok = ok && (s[i + j] == '?' || s[i + j] == t[j]);
      temp[i + j] = t[j];
    }
    if(ok){
      for(char& c : temp) if(c == '?') c = 'a';
      ans.push_back(temp);
    }
  }

  if(ans.empty()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  cout << *min_element(ans.begin(),ans.end()) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>

int main(){
    std::string a, b;
    std::cin >> a >> b;

    std::stringstream ss;
    ss << a + b;
    int val;
    ss >> val;

    if(0 == std::fmod(std::sqrt(val), 1)){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [-1, -1] + [int(sys.stdin.readline()) for _ in range(N - 1)]

tree = [[] for _ in range(N + 1)]
for i, a in enumerate(A[2:], start=2):
    tree[a].append(i)


def depth(n):
    if not tree[n]:
        return 0
    depths = []
    for c in tree[n]:
        depths.append(depth(c))
    depths.sort(reverse=True)
    ret = 0
    for i, d in enumerate(depths):
        ret = max(ret, d + i)
    return ret + 1


print(depth(1))


Measured memory_bytes: 123672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin>>s;
    int n = s.size();
    int l,r;
    for(int i=0; i<n; i++) {
        if(s[i] == 'A') {
            l = i;
            break;
        }
    }
    for(int i=n-1; i>0; i--) {
        if(s[i] == 'Z') {
            r = i;
            break;
        }
    }
    cout<<r-l+1<<"\n";
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

struct Part {
    ll size;
    int position;

};

int main() {


    ll n;
    cin >> n;
    vector<Part> parts(3 * n);

    rep(i, n) {
        int a;
        cin >> a;
        parts[i] = {a, 0,};
    }

    rep(i, n) {
        int b;
        cin >> b;
        parts[n + i] = {b, 1,};
    }

    rep(i, n) {
        int c;
        cin >> c;
        parts[n + n + i] = {c, 2,};
    }

    sort(parts.begin(), parts.end(), [](Part p, Part q) {
        if (p.size == q.size) {
            return p.position > q.position;
        }
        return p.size < q.size;
    });

    ll before_0 = 0;
    ll tsusan_0_count = 0;
    ll tsusan_1_count = 0;
    for (ll i = 0; i < (3 * n); i++) {
        if (parts[i].position == 0) {
            before_0++;
        } else if (parts[i].position == 1) {
            tsusan_0_count += before_0;
        } else {
            tsusan_1_count += tsusan_0_count;
        }
    }

    cout << tsusan_1_count << endl;
}


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

int main() {
  int N, H;
  while (cin >> N) {
    int maxH = 0, num = 0;
    while (N--) {
        cin >> H;
        if (H >= maxH) {
            ++num;
            maxH = H;
        }
    }
    cout << num << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

	int sheet[101][101] = { 0 };   //要素
	int Ctotal[101] = { 0 };   //各列の和
	int Rtotal[101] = { 0 };   //各行の和
	int i, j;   //くり返し用
	int r, c;   //行、列
	int input;   //要素の入力に使用する
	int total = 0;

	/*行数、列数入力*/
	scanf("%d %d", &r, &c);

	/*要素入力*/
	for (i = 0; i < r; i++)
	{
		for (j = 0; j < c; j++)
		{
			scanf("%d", &input);
			sheet[i][j] = input;
		}
	}
	
	/*各列の和を求める*/
	for (i = 0; i < r; i++)
	{
		for (j = 0; j < c; j++)
		{
			Ctotal[j] += sheet[i][j];
		}
	}

	/*各行の和を求める*/
	for (i = 0; i < r; i++)
	{
		for (j = 0; j < c; j++)
		{
			Rtotal[i] += sheet[i][j];
		}
	}

	/*表の出力*/
	for (i = 0; i < r; i++)
	{
		for (j = 0; j < c; j++)
		{
			printf("%d ", sheet[i][j]);
		}
		/*各行の和表示*/
		printf("%d\n", Rtotal[i]);
	}

	/*各列の和表示*/
	for (i = 0; i < c; i++)
	{
		printf("%d ", Ctotal[i]);
		/*各列の和の和を求める*/
		total += Ctotal[i];
	}
	printf("%d\n", total);

	return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
#include<algorithm>
int main()
{
	int a,b,t,i,j,k,n,c[21][21],d[21],s,V=99999;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<21;++i)for(j=0;j<21;++j)c[i][j]=V,c[j][j]=0,d[i]=0;
		for(i=1;i<n;++i)scanf("%d%d%d",&a,&b,&t),c[a][b]=c[b][a]=t,d[a]++,d[b]++;
		for(i=2;i<=n;++i)
			if(d[i]==1)
				for(j=1;j<=n;++j)
					if(c[i][j]!=V)
						c[i][j]=c[j][i]=0;	
		for(s=0,i=1;i<=n;++i)
			for(j=1;j<=n;++j)
				if(c[i][j]!=V)
					s+=c[i][j];
		for(k=1;k<=n;++k)
			for(i=1;i<=n;++i)
				for(j=1;j<=n;++j)
					c[i][j]=std::min(c[i][j],c[i][k]+c[k][j]);
		printf("%d\n",s-*std::max_element(c[1]+1,c[1]+1+n));
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for (int i=(b-1);i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;
int n;
int a[100005];
long long sum=0;
int main (){
	char s[1000];
	scanf(" %s",s);
	rep(i,0,3) printf("%c",s[i]);cout<<endl;
	
	return 0;
} 

Measured memory_bytes: 3660
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");

}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL) calcDepth(T[u].r,p);
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }

  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);

  return 0;
}



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

using namespace std;

const int MOD = 1000000007;

int solve(const vector<int>& A){
	int N = A.size();
	vector< vector<int> > back(N);
	for(int i=0;i<N;i++){
		back[A[i]].push_back(i);
		if(back[A[i]].size() >= 3) return 0;
	}
	vector<int> check(N, 0);
	long long mul = 1;
	for(int i=0;i<N;i++){
		if(check[i]) continue;
		if(back[i].size() < 2) continue;
		int cur = i;
		while(true){
			int p0 = back[cur][0];
			int p1 = back[cur][1];
			if(back[p0].size() > back[p1].size()) swap(p0, p1);
			int s0 = back[p0].size();
			int s1 = back[p1].size();
			if(s0 == 0 && s1 == 0) return 0;
			if(s0 + s1 >= 3) return 0;
			if(s0 == 0 && s1 == 1) mul = (2*mul)%MOD;
			int l0 = 0, l1 = 0;
			while(back[p0].size() == 1 && !check[p0]){ check[p0] = 1; p0 = back[p0][0]; ++l0; }
			while(back[p1].size() == 1 && !check[p1]){ check[p1] = 1; p1 = back[p1][0]; ++l1; }
			if(back[p0].size() != 2 && back[p1].size() != 2) return 0;
			if(back[p0].size() == 2 && back[p1].size() == 2) return 0;
			if(back[p0].size() == 2){ swap(p0, p1); swap(l0, l1); }
			if(s0 == 1 && s1 == 1){
				if(l1 > l0) mul = (2*mul)%MOD;
				else if(l1 < l0) return 0;
			}
			check[p0] = check[p1] = 1;
			cur = p1;
			if(cur == i) break;
		}
	}
	vector<int> cycleNum(N+1, 0);
	for(int i=0;i<N;i++){
		if(check[i]) continue;
		if(back[i].size() != 1) return 0;
		int l = 1, cur = back[i][0];
		while(cur != i){
			check[cur] = 1;
			if(back[cur].size() != 1) return 0;
			cur = back[cur][0];
			if(check[cur]) return 0;
			++l;
		}
		check[i] = 1;
		cycleNum[l]++;
	}
	vector<long long> inv(1000000);
	vector<long long> fact(1000000);
	vector<long long> factInv(1000000);
	vector<long long> pow2(1000000);
	inv[0] = inv[1] = 1;
	fact[0] = fact[1] = 1;
	pow2[0] = 1, pow2[1] = 2;
	factInv[0] = factInv[1] = 1;
	for(int i=2;i<inv.size();i++){
		inv[i] = inv[MOD%i] * (MOD - MOD/i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
		factInv[i] = factInv[i-1] * inv[i] % MOD;
		pow2[i] = pow2[i-1] * 2 % MOD;
	}
	for(int i=1;i<=N;i++){
		if(!cycleNum[i]) continue;
		long long add = (i%2 == 1 && i >= 3 ? pow2[cycleNum[i]] : 1);
		long long cur = 1;
		for(int j=1;2*j<=cycleNum[i];j++){
			cur = (cur * (2*j-1)) % MOD;
			cur = (cur * (2*j)) % MOD;
			cur = (cur * i) % MOD;
			cur = (cur * inv[j]) % MOD;
			cur = (cur * inv[2]) % MOD;
			long long comb = fact[cycleNum[i]] * factInv[2*j] % MOD * factInv[cycleNum[i] - 2*j] % MOD;
			long long curAdd = comb * cur % MOD;
			if(i%2 == 1 && i >= 3){
				curAdd = curAdd * pow2[cycleNum[i] - 2*j] % MOD;
			}
			add = (add + curAdd) % MOD;
		}
		mul = (mul * add) % MOD;
	}
	return mul;
}

int main(){
	int N;
	while(cin >> N){
		vector<int> A(N);
		for(int i=0;i<N;i++){
			cin >> A[i];
			--A[i];
		}
		cout << solve(A) << endl;
	}
}



Measured memory_bytes: 38144
#include<stdio.h>
double absolute(double n) {
  return n<0.0?-n:n;
}
double degree(int T, double elevation) {
  return (double)T - (elevation * 0.006);
}
int main(void) {
  int A,N,T,H;
  scanf("%d", &N);
  scanf("%d %d", &T,&A);

  double nearest = -1;
  int index = 0;

  for(int i=0;i<N;i++) {
    scanf("%d", &H);

    if(nearest < 0 || absolute(A-degree(T,H)) < nearest) {
      nearest = absolute(A-degree(T,H));
      index = i;
    }
  }

	printf("%d\n",index+1);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,ans=0;
map<int,bool> visited;
map<int,bool>::iterator it;
inline void get(int x)
{
	if (x==1)  return;
	int m=n;
	while (m%x==0) m/=x;
	if (m%x==1 && !visited[x]) visited[x]=1;
}
signed main()
{
	cin>>n;
	for (int i=1;i*i<=n;i++) if (n%i==0)  get(i),get(n/i);
	for (int i=1;i*i<=n-1;i++) if ((n-1)%i==0)  get(i),get((n-1)/i);
	for (it=visited.begin();it!=visited.end();it++)  ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
vector<int> pre, in;
int n, idx;
vector<int> ans;
void f(int l, int r){
  if(r-l<=0) return;
  int root = pre[idx++];
  int d = find(in.begin(), in.end(), root) - in.begin();
  f(l, d);
  f(d + 1, r);
  ans.push_back(root);
}
int main()
{
  cin >> n;
  FOR(i,0,n){
    int p;
    cin >> p;
    pre.push_back(p);
  }
  FOR(i,0,n){
    int p;
    cin >> p;
    in.push_back(p);
  }
  f(0, n);
  FOR(i,0,n)printf("%d%c",ans[i],i==n-1?'\n':' ');
  return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int abs(int x){
    if(x<0) return -x;
    else return x;
}
int main() {
    int n;
    cin>>n;
    bool ok=false;
    for(int i=0;i<30;i++){
        for(int j=0;j<30;j++){
            int total= 4*i+7*j;
            if(total == n) ok=true;
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 3592
import scala.math.{min,max}
import scala.math.pow
import scala.math.{acos, asin}
import scala.math.sqrt
import scala.math.abs


object Main {
  val sc = new java.util.Scanner(System.in)
  def main(args: Array[String]) {
    while(true) {
      val n = sc.nextInt
      if(n == 0) return

      val w = Array.ofDim[Int](n,3);
      for(i <- 0 until n) {
        for(j <- 0 until 3) {
          w(i)(j) = sc.nextInt
        }
      }

      val m = sc.nextInt
      val ts = Array.ofDim[Int](m, 4)
      for(i <- 0 until m) {
        for(j <- 0 until 4) {
          ts(i)(j) = sc.nextInt
        }
      }
      ts.foreach(tsi => println(test(w, tsi)))
    }
  }
  def test(w: Array[Array[Int]], tsi: Array[Int]) = {
    val eps = 1e-10
    if (w.forall( wi => {
        val d1 = pow(tsi(0) - wi(0),2) + pow(tsi(1) - wi(1),2)
        val d2 = pow(tsi(2) - wi(0),2) + pow(tsi(3) - wi(1),2)
        ( d1 < pow(wi(2), 2) && d2 < pow(wi(2), 2) ) ||
          ( d1 > pow(wi(2), 2) && d2 > pow(wi(2), 2) && !{
            val x = pow(tsi(0) - tsi(2), 2) + pow(tsi(1) - tsi(3), 2)
            x >= d1 - wi(2) * wi(2) && abs(asin(wi(2)/sqrt(d1))) - abs(acos((x + d1 - d2)/(2*sqrt(d1*x)))) > -eps
          })
      })) {
      "Danger"
    } else {
      "Safe"
    }
  }
}

Measured memory_bytes: 52504
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

string s;

int main() {
    cin>>s;
    string ans="AC";
    if(s[0]!='A') ans="WA";
    bool ok=false;
    REP(i,1,s.size()){
        if(i>1&&i!=s.size()-1) {
            if (ok && s[i] == 'C') {
                ans = "WA";
                break;
            } else if (!ok && s[i] == 'C') {
                ok = true;
            }else if(CK(s[i], 'A','Z'+1)){
                ans = "WA";
            }
        }else if(CK(s[i], 'A','Z'+1)){
            ans = "WA";
        }

    }
    if(!ok) ans="WA";
    p(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define NREP(i, n) for(int i = 1; i <= (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cout << fixed << setprecision(7);
////////////////////////////////////////////
	int a,b,c;
	cin >> a >> b >> c;
	cout << max(0,b+c-a) << endl;
///////////////////////////////////////////
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,m,x,c=0,d=0,e=0;
	cin>>n>>m>>x;
	int a[n+1],b[m];
	for (int i=0;i<=n;i++) a[i]=0;
	for (int i=0;i<m;i++) cin>>b[i];
	for (int i=0;i<m;i++)
	{
	    a[b[i]]=1;
    }
    for (int i=x;i>=0;i--) d=d+a[i];
    for (int i=x;i<=n;i++) e=e+a[i];
    if (d>=e) cout<<e<<endl;
    else cout<<d<<endl;
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        for (int i=0; i<N; i++) {
        		System.out.print(s.charAt(i));
        		System.out.print(t.charAt(i));
        }
    }
} 

Measured memory_bytes: 23892
s=input()
alp="".join([chr(i) for i in range(97,97+26)])
if len(s)<26:
    for i in alp:
        if i not in s:
            print(s+i);exit()
else:
    if s=="".join([chr(i) for i in range(97,97+26)][::-1]):
        print(-1)
    else:
        for i in range(25)[::-1]:
            for j in range(i+1,26)[::-1]:
                if s[i]<s[j]:
                    print(s[:i]+s[j]);exit()

Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
using namespace std;
int map[11][11];
int dx[] = { 0, 0, 0, 1, -1, 1, 1, -1, -1, 0, 0, 2, -2 };
int dy[] = { 0, 1, -1, 0, 0, -1, 1, 1, -1, 2, -2, 0, 0 };
int ans;
int total;
void draw(int x, int y, int size){
	for (int i = 0; i < size * 4 + 1; i++){
		int xx = x + dx[i];
		int yy = y + dy[i];
		if (xx < 0 || xx >= 10 || yy < 0 || yy >= 10) continue;
		map[yy][xx]++;
		ans = max(ans, map[yy][xx]);
		if (map[yy][xx] == 1)total--;
	}
}
int main(){
	int x, y, size;
	char c;
	total = 10 * 10;
	while (cin >> x >> c >> y >> c >> size){
		draw(x, y, size);
	}
	cout << total << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
    int a,b,c,x;
    cin >>a>>b>>c>>x;

    int count = 0;
    for (int i = 0; i <= a; i++)
    {
        int sum = 500 * i;
        if (sum == x)
        {
            count++;
            continue;
        }
        
        for (int j = 0; j <= b; j++)
        {
            sum = (500 * i) + (100 * j);
            if (sum == x)
            {
                count++;
                continue;
            }
            for (int k = 0; k <= c; k++)
            {
                sum = (500 * i) + (100 * j) + (50 * k);
                if (sum == x)
                {
                    count++;
                    continue;
                }
            }
        }
    }
    
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int num=0;
	int ans=0;
	string ds;
	cin>>ds;
	int len=ds.size();
	for(int i=0;i<len;i++)
	{
		if(ds[i]=='g'&&num<len/2)
		{
		ans++;
		num++;
		}
		if(ds[i]=='p'&&num>=len/2)
		{
			ans--;
		}
		if(ds[i]=='p'&&num<len/2)
		{
			num++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    for(int i = 0; i < 5; i++){
        int x;
        cin >> x;
        if(x == 0) cout << i+1 << endl; 
    }

    return 0;
}

Measured memory_bytes: 3620
#pragma region 
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<string>
typedef long long ll;
template <typename T>void read(T &x){x=0;char ch=getchar();ll f=1;while(!isdigit(ch)){if(ch=='-')f*=-1;ch=getchar();}while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}x*=f;}
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
#pragma endregion

int main() {
    IO;
    ll a, b, n;
    cin >> a >> b >> n;
    ll x;
    if (n<b)
        x = n;
    else
        x = b - 1;
    cout << (a * x / b) << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  if (a[0] == a[1] || a[1] == a[2] || a[0] == a[2]){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define digit(A,B) ((A>>B)&1)
#define N_MAX 10

/* 

gÝí¹ðQiÅ\µÄð­B

n[i]ciðQiÅ\µ½É1ª§Ârbg
s[i]ciðQiÅ\µ½ÉAurbgÚªPvÆÈÁÄ¢éæ¤ÈÌa

 */

int main(void){
	int n[(int)pow(2,N_MAX)], s[(int)pow(2,N_MAX)], i, j, t1, t2;
	
	for(i=0; i<(int)pow(2,N_MAX); i++){
		t1=0, t2=0;
		
		for(j=0; j<N_MAX; j++)
			if(digit(i,j)) t1++, t2+=j;
	
		n[i]=t1, s[i]=t2;
	}
	
	while(scanf("%d %d",&t1,&t2), t1!=0){
		j=0;
		
		for(i=0; i<(int)pow(2,N_MAX); i++)
			if(n[i]==t1 && s[i]==t2) j++;
		
		printf("%d\n",j);
	}
	
	return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int first = s.size() - 1;
  while(first >= 4)
  {
    if(first >= 6)
    {
      if(s.at(first-6)=='d' && s.at(first-5)=='r' && s.at(first-4)=='e' && s.at(first-3)=='a' && s.at(first-2)=='m' && s.at(first-1)=='e' && s.at(first)=='r')
      {
        first -= 7;
      }
      else if(s.at(first-5)=='e' && s.at(first-4)=='r' && s.at(first-3)=='a' && s.at(first-2)=='s' && s.at(first-1)=='e' && s.at(first)=='r')
      {
        first -= 6;
      }
      else if(s.at(first-4)=='d' && s.at(first-3)=='r' && s.at(first-2)=='e' && s.at(first-1)=='a' && s.at(first)=='m')
      {
        first -= 5;
      }
      else if(s.at(first-4)=='e' && s.at(first-3)=='r' && s.at(first-2)=='a' && s.at(first-1)=='s' && s.at(first)=='e')
      {
        first -= 5;
      }
      else
      {
        break;
      }
    }
    else if(first >= 5)
    {
      if(s.at(first-5)=='e' && s.at(first-4)=='r' && s.at(first-3)=='a' && s.at(first-2)=='s' && s.at(first-1)=='e' && s.at(first)=='r')
      {
        first -= 6;
      }
      else if(s.at(first-4)=='d' && s.at(first-3)=='r' && s.at(first-2)=='e' && s.at(first-1)=='a' && s.at(first)=='m')
      {
        first -= 5;
      }
      else if(s.at(first-4)=='e' && s.at(first-3)=='r' && s.at(first-2)=='a' && s.at(first-1)=='s' && s.at(first)=='e')
      {
        first -= 5;
      }
      else
      {
        break;
      }
    }
    else if(first >= 4)
    {
      if(s.at(first-4)=='d' && s.at(first-3)=='r' && s.at(first-2)=='e' && s.at(first-1)=='a' && s.at(first)=='m')
      {
        first -= 5;
      }
      else if(s.at(first-4)=='e' && s.at(first-3)=='r' && s.at(first-2)=='a' && s.at(first-1)=='s' && s.at(first)=='e')
      {
        first -= 5;
      }
      else
      {
        break;
      }
    }
    else
    {
      break;
    }
  }
  if(first == -1)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


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

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CRemainderMinimization2019 {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int L, R;
        cin >> L >> R;

        if (R - L + 1 >= 2019) {
            cout << 0 << endl;
            return;
        }
        int res = INF;
        FOR(i, L, R - 1) {
            FOR(j, i + 1, R) {
                res = min(res, (i * j) % 2019);
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CRemainderMinimization2019 solver;
    solver.solve(in, out);
    return 0;
}


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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, K;
  cin >> N >> K;
  map<int, int> mp;
  for (int i = 1; i <= N; i++) {
    mp[i % K]++;
  }
  dumpv(mp);
  ll ans = 0;
  for (int a = 0; a < K; a++) {
    int b = (K - a) % K;
    int c = (K - b) % K;
    if ((c + a) % K != 0) {
      continue;
    }
    dump(a, b, c);
    ans += (ll)mp[a] * mp[b] * mp[c]; 
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    string s;
    cin >> s;
    if(s == "SUN"){
        cout << 7 << endl;
    } else if(s == "MON"){
        cout << 6 << endl;
    } else if(s == "TUE") {
        cout << 5 << endl;
    } else if(s == "WED") {
        cout << 4 << endl;
    } else if(s == "THU") {
        cout << 3 << endl;
    } else if(s == "FRI") {
        cout << 2 << endl;
    } else if(s == "SAT") {
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256