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

using ll = long long;

constexpr ll inf = 1e18;

struct edge {
    int to;
    ll cost;
};

using graph = vector<vector<edge>>;

void add_edge(graph& g, int from, int to, int cost) {
    g[from].push_back(edge{to, cost});
    g[to].push_back(edge{from, cost});
}

int main() {
    int n, m, x; cin >> n >> m >> x;
    vector<int> h(n);
    for(int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    graph g(n);
    for(int i = 0; i < m; ++i) {
        int a, b, t; cin >> a >> b >> t;
        add_edge(g, a - 1, b - 1, t);
    }

    vector<ll> d(n, inf);
    d[0] = 0;
    using state = tuple<ll, ll, int>;
    priority_queue<state, vector<state>, greater<>> que;
    que.emplace(0, x, 0);
    ll ans = -1;
    while(!que.empty()) {
        ll cur_t, cur_h; int v;
        tie(cur_t, cur_h, v) = que.top(); que.pop();
        if(v == n - 1) {
            ans = cur_t + abs(cur_h - h[n - 1]);
            break;
        }
        if(d[v] < cur_t) continue;
        for(auto& e : g[v]) {
            ll nh = cur_h - e.cost, nt = cur_t + e.cost;
            if(nh < 0) {
                ll up = -nh;
                if(cur_h + up > h[v]) continue;
                nh = 0;
                nt += up;
            }
            if(nh > h[e.to]) {
                ll down = nh - h[e.to];
                nt += down;
                nh = h[e.to];
            }
            if(d[e.to] <= nt) continue;
            que.emplace(nt, nh, e.to);
            d[e.to] = nt;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 23484
a = [0,0,0,0]
n = int(input())
for i in range(n):
    m = input()
    if m == "AC":
        a[0] += 1
    elif m == "WA":
        a[1] += 1
    elif m == "TLE":
        a[2] += 1
    else:
        a[3] += 1
print("AC x "+str(a[0]))
print("WA x "+str(a[1]))
print("TLE x "+str(a[2]))
print("RE x "+str(a[3]))



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

int     main()
{
    int hoge[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 
    
    int K; cin >> K;
    cout << hoge[--K] << endl;
}


Measured memory_bytes: 256
def main():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    L = [[0] * w for _ in range(h)]
    R = [[0] * w for _ in range(h)]
    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if j != 0:
                L[i][j] = L[i][j - 1]
            if s[i][j] == ".":
                L[i][j] += 1
            else:
                L[i][j] = 0
    for i in range(h):
        for j in range(w - 1, -1, -1):
            if j != w - 1:
                R[i][j] = R[i][j + 1]
            if s[i][j] == ".":
                R[i][j] += 1
            else:
                R[i][j] = 0
    for j in range(w):
        for i in range(h):
            if i != 0:
                U[i][j] = U[i - 1][j]
            if s[i][j] == ".":
                U[i][j] += 1
            else:
                U[i][j] = 0
    for j in range(w):
        for i in range(h - 1, -1, -1):
            if i != h - 1:
                D[i][j] = D[i + 1][j]
            if s[i][j] == ".":
                D[i][j] += 1
            else:
                D[i][j] = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 179844
#include <stdio.h>

int coin[2] = {500,5};
int func(int yen){
    int ure1, ure2;
    int ure = 0;
    
    if (yen / coin[0] > 0) {
        ure1 = yen / coin[0];
        yen -= ure1 * coin[0];
        ure1 *= 1000;
        ure += ure1;
    }
    
    if (yen / coin[1] > 0) {
        ure2 = yen / coin[1];
        yen -= ure2 * coin[1];
        ure2 *= 5;
        ure += ure2;
    }
    
    return ure;
}

int main(void){
    int yen, ure;
    scanf("%d", &yen);
    ure = func(yen);
    printf("%d", ure);
}


Measured memory_bytes: 128
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const char dat[7][16] = {
    "Monday", "Tuesday", "Wednesday", "Thursday",
    "Friday", "Saturday", "Sunday",
};
const int s[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

int main() {
    for (;;) {
        int m, d;
        scanf("%d%d", &m, &d);
        if (m == 0 && d == 0) return 0;
        m--, d--;
        rep (i, m) d += s[i];
        puts(dat[(d+3)%7]);
    }
}

Measured memory_bytes: 0
(use '[clojure.string :only (split)])

(defn readline [s]
  (let [ss (split s #" ")]
    (map #(Long/parseLong %) ss)))

(defn solve [h hs acc ans]
  (if (empty? hs)
    ans
    (let [h' (first hs)
          hs' (rest hs)
          acc' (inc acc)]
      (if (>= h h')
        (recur h' hs' acc' (if (> acc' ans) acc' ans))
        (recur h' hs' 0 ans)))))

;; (solve 10 [4 8 7 3] 0 0)
;; (solve 4 [4 5 6 6 5 5] 0 0)
;; (solve 1 [2 3 4] 0 0)
;; (solve 4 [5 4 6 6 5 5] 0 0)

(let [n (Integer/parseInt (read-line))
      hs (readline (read-line))]
  (println (solve (first hs) (rest hs) 0 0)))


Measured memory_bytes: 84576
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>

#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)

using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
    Ryuga;
    
   
    ll L;
    cin>>L;
    cout<<fixed<<setprecision(12)<<(L*L*L)/27.0;
    
}//Goodbye...

Measured memory_bytes: 256
def main():
    N, P = map(int, input().split())
    A = list(map(int, input().split()))
    even = 0
    odd = 0
    for a in A:
        if a % 2 == 0: even += 1
        else: odd += 1

    evenchoice = pow(2, even)
    if odd == 0:
        if P == 0: return evenchoice
        else: return 0
    else:
        oddchoice = pow(2, odd) // 2
    return evenchoice * oddchoice

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int i, n, max;
int m[101];

int main(void)
{
  memset(m,0,sizeof(m));
  while(scanf("%d",&n) == 1)
    m[n]++;

  max = 0;
  for(i = 1; i <= 100; i++)
     if (m[i] > max) max = m[i];

  for(i = 1; i <= 100; i++)
    if (m[i] == max) printf("%d\n",i);
  return 0;
}

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

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

const int D = 80 * 160 + 10;
const int D2 = D*2;
typedef bitset<D2> bs;
int a[100][100];
bs dp[90][90];



const int N = 20;
int h;
int w;
vector<vector<char>> maze(N, vector<char>(N,'#'));

const int MAX_WH = 21;
int d[MAX_WH][MAX_WH];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const int INF = 1001001001;
int bfs(int x, int y) {
    queue<P> que;
    rep(i,MAX_WH) {
        rep(j,MAX_WH) {
            d[j][i] = INF;
        }
    }
    que.push(P(x,y));
    d[x][y] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        for (int i=0; i< 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    int mx = 0;
    rep(i,h) rep(j,w) {
            if (d[j][i] == INF) continue;
            mx = max(mx, d[j][i]);
        }
    return mx;
}

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}
void dfs(){

}
const int MX = 100000;
vector<int> G[MX];

int main(){
    int h, n; cin >> h >> n;
    vector<int> dp(h+1,INF);
    dp[0] = 0;
    rep(i,n) {
        int a,b;
        cin >> a >> b;
        rep(j,h) {
            int nj = min(j+a,h);
            dp[nj] = min(dp[nj], dp[j]+b);
        }
    }
    cout << dp[h] << endl;


}



Measured memory_bytes: 4352
N = int(input())
A = list(map(int,input().split()))
A.sort()
A_ = (A[0]+A[1])/2
if N ==2:
    print((A[0]+A[1])/2)
    exit()
for i in range(N-2):
    A_ = (A_ + A[i+2])/2
print(A_)


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	double x, h;
	double S;
	
	while(true){
		scanf("%lf%lf", &x, &h);
		
		if(x == 0 && h == 0) break;
		
		S = x * x + x * sqrt(x * x / 4 + h * h) * 2;
		
		printf("%lf\n", S);
	}
	
	return 0;
}

Measured memory_bytes: 1072
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>

const int MAXN = 5e5 + 5;

char s[MAXN << 2], t[MAXN];
int lenS, lenT, copyLenS, copyLenT, ans;
int next[MAXN], sum;
int entry[MAXN], res[MAXN], dp[MAXN];
bool find[MAXN << 2];

std::vector<int> con[MAXN];
std::queue<int> q;

void init() {
    int place = 0;
    next[1] = 0;
    for (int i = 2; i <= lenT; ++i) {
        while (place && t[i] != t[place + 1]) {
            place = next[place];
        }
        if (t[i] == t[place + 1])
            ++place;
        next[i] = place;
    }
}

void kmp() {
    init();
    int place = 0;
    for (int i = 1; i <= lenS; ++i) {
        while(place && s[i] != t[place + 1]) {
            place = next[place];
        }
        if (s[i] == t[place + 1])
            ++place;
        if (place == lenT && i - lenT + 1 <= copyLenS) {
            find[i - lenT + 1] = true;
            place = next[place];
            ++sum;
        }
    }
}

void ins(int start,int end) {
    con[start].push_back(end);
    ++entry[end];
}

bool topSort() {
    int cnt = 0;
    for (int i = 1; i <= copyLenS; ++i) {
        if (find[i] && entry[i] == 0)
            q.push(i);
    }
    while (!q.empty()) {
        int cur = q.front();
        res[++cnt] = cur;
        for (int i = 0; i < con[cur].size(); ++i) {
            if (--entry[con[cur][i]] == 0)
                q.push(con[cur][i]);
        }
        q.pop();
    }
    return cnt == sum;
}

int main() {
    scanf("%s%s", s + 1, t + 1);
    copyLenS = lenS = strlen(s + 1);
    copyLenT = lenT = strlen(t + 1);
    while (copyLenT > 0) {
        for (int i = 1; i <= copyLenS; ++i) {
            s[++lenS] = s[i];
        }
        copyLenT -= copyLenS;
    }
    kmp();
    for (int i = 1; i <= copyLenS; ++i) {
        int k = ((i + lenT) % copyLenS == 0) ? copyLenS : ((i + lenT) % copyLenS);
        if (find[i] && find[k])
            ins(i, k);
    }
    if (topSort()) {
        for (int k = 1; k <= sum; ++k) {
            int i = res[k];
            if (dp[i] == 0)
                dp[i] = 1;
            for (int j = 0; j < con[i].size(); ++j) {
                dp[con[i][j]] = std::max(dp[con[i][j]], dp[i] + 1);
            }
        }
        for (int i = 1; i <= sum; ++i) {
            ans = std::max(ans, dp[res[i]]);
        }
    }
    else
        ans = -1;
    printf("%d", ans);
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n;
ll x, a[maxn], b[maxn], ans = inf;
multiset<ll> st;
bool mark[maxn];

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

	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int k = 0; k < n; k++)
	{
		memset(mark, false, sizeof(mark));
		for (int i = 0; !mark[i]; i = (i + 1) % n)
		{
			st.insert(a[i]);
			if (st.size() == k + 2)
				st.erase(st.find(a[(i - k - 1 + n) % n]));
			if (st.size() == k + 1)
			{
				mark[i] = true;
				b[i] = *st.begin();
			}
		}
		ll cur = x * k;
		for (int i = 0; i < n; i++)
			cur += b[i];
		ans = min(ans, cur);
	}
	cout << ans << endl;
}



Measured memory_bytes: 640
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		long[] arr = new long[3*n];
		for(int i = 0; i < 3*n; i++){
			arr[i] = Integer.parseInt(st.nextToken());
		}
		long[] sum = new long[3*n];
		long curr = 0;
		PriorityQueue<Long> q = new PriorityQueue<>();
		for(int i = 0; i < n; i++){
			curr += arr[i];
			q.add(arr[i]);
		}
		sum[n] = curr;
		for(int i = n; i < 3*n-1; i++){
			q.add(arr[i]);
			long r = q.poll();
			curr += arr[i]; curr -= r;
			sum[i+1] = curr;
		}
		q = new PriorityQueue<>();
		curr = 0;
		for(int i = 3*n-1; i >= 2*n; i--){
			curr += arr[i];
			q.add(-arr[i]);
		}
		sum[2*n] -= curr;
		for(int i = 2*n-1; i >= 0; i--){
			q.add(-arr[i]);
			long r = -q.poll();
			curr += arr[i]; curr -= r;
			sum[i] -= curr;
		}
		long max = Long.MIN_VALUE;
		for(int i = n; i <= 2*n; i++){
			max = Long.max(max, sum[i]);
		}
		System.out.println(max);
	}

}


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

using namespace std;


void solve() {
    int n, l;
    cin >> n >> l;
    vector<int> a(n+1);
    int mi = 1e8;
    int c = -1;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        a[i] = l+i-1;
        sum += a[i];
        if (abs(a[i]) < mi) {
            mi = abs(a[i]);
            c = a[i];
        }
    }
    cout << sum - c;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

using namespace std;

int main(){
	int c,t,x,y;
  	cin>>x >>y;
  
  	c=(4*x-y)/2;
  	t=x-c;
  
  	if( c+t == x && 2*c + 4*t == y && c>=0 && t>=0){
    	cout<<"Yes"<<endl;
    }
  	else
    {
    	cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3612
class Card:
    def __init__(self, s, i):
        self.suit = s[0]
        self.value = s[1]
        self.iniorder = i

def BubbleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if C[j].value < C[j - 1].value:
                C[j], C[j - 1] = C[j - 1], C[j]

    return C

def SelectionSort(C, N):
    for i in range(N):
        minj = i

        for j in range(i, N):
            if C[j].value < C[minj].value:
                minj = j

        C[i], C[minj] = C[minj], C[i]

    return C


n = int(input())
cards = [Card(c, i) for (i, c) in enumerate(input().split())]

res_bub = BubbleSort(cards[:], n)
res_sel = SelectionSort(cards[:], n)

print(*[c.suit + c.value for c in res_bub])

for i in range(n - 1):
    if res_bub[i].value == res_bub[i + 1].value:
        if res_bub[i].iniorder > res_bub[i + 1].iniorder:
            print("Not stable")
            break
else:
    print("Stable")

print(*[c.suit + c.value for c in res_sel])

for i in range(n - 1):
    if res_sel[i].value == res_sel[i + 1].value:
        if res_sel[i].iniorder > res_sel[i + 1].iniorder:
            print("Not stable")
            break
else:
    print("Stable")

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

int main(){
    string s;
    cin>>s;
    unordered_map<ll, ll> mapp;
    ll pow = 1;
    ll sum = 0;
    for(int i=s.size()-1; ~i; i--){
        sum = ((s[i]-'0')*pow+(sum))%2019;
        pow=(pow*10)%2019;
        mapp[sum]++;
    }
    mapp[0]++;
    ll ans = 0;
    for(auto it : mapp){
        ans+=(it.second)*(it.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3756
str = gets.split
N,A,B,C,D = str[0].to_i, str[1].to_i, str[2].to_i, str[3].to_i, str[4].to_i

S = gets.chomp

e = 0
if D == N
  e = N
else
  e = D+1
end

f = 0
if C > D
  for x in B-2...e-2
    if S[x..x+2] == "..."
      f = 1
    end
  end
  if f == 0
    puts "No"
    exit(0)
  end
end

if C > D
  e = C
else
  e = D
end

for x in A-1...e-1
  if S[x..x+1] == "##"
    puts "No"
    exit(0)
  end
end

puts "Yes"

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    int n; cin >> n;
    unordered_map<string, int> memo;
    rep(i,n){
        string s;
        cin >> s;
        memo[s]++;
    }
    cout << "AC x " << memo["AC"] << endl;
    cout << "WA x " << memo["WA"] << endl;
    cout << "TLE x " << memo["TLE"] << endl;
    cout << "RE x " << memo["RE"] << endl;

    return 0;
}

Measured memory_bytes: 3632
// https://atcoder.jp/contests/abc122/tasks/abc122_a

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if (s[0] == 'A') {
        cout << "T" << endl;
    } else if (s[0] == 'T') {
        cout << "A" << endl;
    } else if (s[0] == 'C') {
        cout << "G" << endl;
    } else if (s[0] == 'G') {
        cout << "C" << endl;
    }

    return 0;
}


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

int NMAX = 100000;
int MAX  = 1000000000;

int main(){
  int N, K;
  cin >> N >> K;

  int h[NMAX + 1];
  for (int i = 0; i <= NMAX; i++ ) h[i] = 0;

  for (int i = 1; i <= N; i++ ) cin >> h[i];

  int dp[NMAX + 1];
  for (int i = 0; i <= NMAX; i++ ) dp[i] = MAX;

  dp[1] = 0;
  for (int i = 1; i <= N; i++ ) {
    for (int j = 1; j <= K; j++ ) {
      if ( (i + j) > N ) continue;

      dp[i + j] = min( dp[i + j], abs(h[i] - h[i + j]) + dp[i]);

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


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

const int MAX_THR = 18;

int main(void){
	int n;
	cin >> n;

	ll cnt[MAX_THR + 1][MAX_THR + 1];

	rep(i, MAX_THR + 1) rep(j, MAX_THR + 1) {
		cnt[i][j] = 0LL;
	}

	rep(i, n) {
		string digits;
		cin >> digits;

		ll val = 0LL;

		bool flag = false;
		int after_point = 0;

		for(auto &d: digits) {
			if(d == '.') {
				flag = true;
				continue;
			}

			val = 10 * val + (d - '0');
			
			if(flag) {
				after_point++;
			}
		}

		while(after_point < 9) {
			val *= 10LL;
			after_point++;
		}

		int two = 0, five = 0;
		rep(loop, MAX_THR) {
			if(val % 2) break;
			val /= 2, two++;
		}

		rep(loop, MAX_THR) {
			if(val % 5) break;
			val /= 5, five++;
		}

		cnt[two][five]++;
	}
	
	ll ans = 0LL;

	rep(a, MAX_THR + 1) rep(b, MAX_THR + 1) {
		if(2 * a >= MAX_THR and 2 * b >= MAX_THR) {
			ans += 1LL * cnt[a][b] * (cnt[a][b] - 1);
		}
	}

	rep(a, MAX_THR + 1) rep(b, MAX_THR + 1) {
		rep(c, MAX_THR + 1) rep(d, MAX_THR + 1) {
			if(a == c and b == d) {
				continue;
			}

			if(a + c >= MAX_THR and b + d >= MAX_THR) {
				ans += cnt[a][b] * cnt[c][d];
			}
		}
	}

	ans /= 2LL;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> adj[200005];
vector<int> c(200005);
vector<bool> vis(200005);
vector<int> ans(200005);
int n;


void DFS(int src, int val)
{
    ans[src]= val;
    vis[src]=  true;

    for(auto neig: adj[src])
    {
        if(!vis[neig])
        {
            DFS(neig, val+c[neig]);
        }
    }
}

int main() {
    int q;
    cin>>n>>q;
    for(int i = 0; i < n-1; i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 0; i <= n; i++) c[i] = 0, ans[i] = 0,vis[i] = false;
    while(q--)
    {
        int v,x;
        cin>>v>>x;
        c[v]+=x;
    }

    DFS(1,c[1]);

    for(int  i= 1; i <= n; i++) cout<<ans[i]<<" ";
    cout<<"\n"; 
    return 0;
}


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

int main()
{
	int N;
	std::cin >> N;
	std::vector<int> A(N, 0);
	for (int i = 0; i < N; i++) {
		std::cin >> A[i];
	}

	std::vector<int> all_num(1000005, 0);	// この中が0なら存在せず、2以上なら割り切れる数がいる
	for (int value : A) {
		// その数の倍数を塗りつぶす
		if( all_num[value] !=0 )
		{
			all_num[value]++;	// かぶってるものを1以外にする
			continue;	// もうその数の倍数は割り切られている
		}

		for(int i=1; /* true */; i++)
		{
			int tmp=value*i;
			if(tmp>=1000001)
			{
				break;
			}
			all_num[tmp]++;
		}
	}

	int cnt=0;
	for (int value : A) {
		if(all_num[value] == 1)
		{
			cnt++;
			// printf("%d(%d)\n", value, all_num[value]);
		}
	}

	std::cout << cnt << '\n';

	return 0;
}


Measured memory_bytes: 7524
import java.util.Scanner;

public class Main {

	
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		s.nextLine();
		
		for (int i = 0; i < n; i++) { lcs(s.nextLine(), s.nextLine());	}
		
		s.close();
	}

	public static int max(int a, int b) { return (a >= b) ? a : b;	}
	
	public static void lcs(String s1, String s2) {	
		int rows = s1.length() +  1;
		int cols = s2.length() + 1;
		int max = 0;
		//int[] maxSpot = new int[2];
		int[][] t = new int[rows][cols];
		
		for (int r = 1; r < rows; r++) {
			for (int c = 1; c < cols; c++) {
				t[r][c] = max(t[r-1][c], t[r][c-1]);
				char a = s1.charAt(r - 1);
				char b = s2.charAt(c - 1);
				
				if (Character.compare(a, b) == 0) { t[r][c] = t[r - 1][c - 1] + 1; }			
				
				//max = max(max, t[r][c]);
			} 
		}
		System.out.println(t[rows - 1][cols - 1]);	
	}
	
}



Measured memory_bytes: 64008
using System;

public class Program
{
    private int N;
    private int[] A;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = sc.NextInt();
        }

        var ans = new int[N + 1];
        for (int i = 1; i <= N; i++)
        {
            ans[i] = int.MaxValue;
        }


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

            while (max - min > 1)
            {
                int med = (min + max) / 2;
                if (ans[med] >= A[i])
                {
                    max = med;
                }
                else
                {
                    min = med;
                }
            }

            ans[max] = A[i];
        }

        for (int i = N; i >= 0; i--)
        {
            if (ans[i] != int.MaxValue)
            {
                Console.WriteLine(i);
                return;
            }
        }
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}


Measured memory_bytes: 22088
def judge(n,array1,array2,K):
    for i in range(n+1):
        if len(array1) > i and len(array2) > n-i:
            sum = array1[i] + array2[n-i]
            if sum <= K:
                return True
    return False

N, M, K = list(map(int,input().split()))
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))

cum_sum_As = [0]
cum_sum_Bs = [0]

sum_As = 0
for i in range(N):
    sum_As += As[i]
    cum_sum_As.append(sum_As)

sum_Bs = 0
for i in range(M):
    sum_Bs += Bs[i]
    cum_sum_Bs.append(sum_Bs)

l = 0
r = N + M
while(r-l>1):
    mid = (l+r)//2
    if judge(mid,cum_sum_As,cum_sum_Bs,K):
        l = mid
    else:
        r = mid

if judge(r,cum_sum_As,cum_sum_Bs,K):
    print(r)
else:
    print(l)


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

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

#define FACSIZE 200002

ll invfac[FACSIZE];
ll fac[FACSIZE];

template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);
ll gcd(ll, ll);
ll powLL(ll x, ll y);

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
ll comb(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void fact_init();

int main(void)
{
  ll a, b;
  cin >> a >> b;
  string sa = "";
  string sb = "";

  rep(i, a) sa += (char)(b + '0');
  rep(i, b) sb += (char)(a + '0');

  if (sa < sb)
  {
    cout << sa << endl;
  }
  else
    cout << sb << endl;

  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return mod_mul(t, t);
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = mod_mul(t, t);
    return (k % mod) * (x % mod);
  }
}
ll mod_add(ll a, ll b)
{
  return ((a % mod) + (b % mod)) % mod;
}

ll mod_mul(ll a, ll b)
{
  return ((a % mod) * (b % mod)) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void fact_init()
{
  make_fact(FACSIZE - 1);
  make_invfact(FACSIZE);
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

ll comb(ll n, ll r)
{

  return mod_mul(mod_mul(fac[n], invfac[r]), invfac[n - r]);
}
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;
}

ll qp(ll a, ll b)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * mod_mul(ans, a) % mod;
    a = 1LL * mod_mul(a, a) % mod;
  } while (b >>= 1LL);
  return ans;
}
ll qp(ll a, ll b, ll mo)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * (ans % mo) * (a % mo);
    a = 1LL * (a % mo) * (a % mo);
  } while (b >>= 1LL);
  return ans;
}
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
ll powLL(ll x, ll y)
{
  ll ans = 1LL;
  for (ll i = 0LL; i < y; i++)
    ans *= x;
  return ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream& operator<<(ostream& out, vector<T> &v){
  for (int i = 0; i < (int)v.size(); i++) {
    out<<v[i]<<' ';
  }
  return out;
}

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

  string a, b; cin >> a >> b;
  int la = a.size();
  int lb = b.size();
  b.erase(lb-(lb-la));
  if(a == b) cout << "Yes";
  else cout << "No";
  


  // int n, m; cin >> n >> m;
  // int a[600][600];
  // rep(i, n){
  //   rep(j, m){
  //     cin >> a[i][j];
  //   }
  // }
  // dfs(a, n, m);


  return 0;
}

// void dfs(int **a, int n, int m){
//
// }


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

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

    int ans = -1;
    for (int i = 1; i < 11000; i++) {

        int x = i * 0.08;
        int y = i * 0.1;

        if (x == a && y == b) {
            ans = i;
            break;
        }

    }
        
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  vi ans(n);
  ll a_sum = SUM(a);
  ll x = 0;
  rep(i,n) {
    if (i%2 == 1) x += a[i];
  }

  ans[0] = a_sum - 2*x;
  rep(i,n-1) {
    ans[i+1] = 2*a[i] - ans[i];
  }
  rep(i,ans.size()) printf("%d%c", ans[i], i==ans.size()-1?'\n':' ');
  return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define gcd __gcd
bool compare(ll x, ll y){
    return x>y;
}
ll isprime(ll n){
    if(n==1) return 0;
    else if(n==2) return 1;
    else{
        for(ll i=2;i<=sqrt(n);i++){
            if(n%i==0) return 0;
        }
    return 1;   
    }
}
vector<ll> get_prime_less(ll n){
    ll array[n];
    vector<ll> factor;
    for(ll i=1;i<=n;i++) array[i]=i;
    ll prime[n];
    for(ll i=0;i<n;i++) prime[i]=1;
    for(ll i=2;i<=sqrt(n);i++){
        if(prime[i]==1){
            for(ll j=i*i;j<=n;j=j+i) prime[j]=0; 
            factor.push_back(i);
        }
    }
    return factor;
}
vector<ll> retain_index(ll arr[], ll n){ 
    vector<pair<ll, ll> > vp; 
    for (ll i = 0; i < n; ++i) { 
        vp.push_back(make_pair(arr[i], i)); 
    } 
    sort(vp.begin(), vp.end());
    vector<ll> retain;
    for (ll i = 0; i < vp.size(); i++) { 
        ll a = vp[i].second;
        retain.pb(a);
    }
    return retain;
}
int main(){
    ll n,r,b;
    cin>>n>>b>>r;
    ll sum = b+r;
    ll ans  = (n/sum)*b;
    n = n%sum;
    if(b > n) ans = ans + n;
    else ans = ans + b;
    cout<<ans;
    
}


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


int main() {
	int n, q;
	int time[100000];
	char name[100000][10];
	char temp[10];
	
	scanf("%d %d", &n, &q);
	int i;
	for(i = 0; i < n; i++) {
		scanf("%s %d", &name[i][0], &time[i]);
	}
	int count = 0;
	int j = 0;
	
	for ( i = 0; i < n; i++) {
		if (time[i] > q) {
			count += q;
			time[j] = time[i] - q;
			strcpy(temp, &name[i][0]);
			strcpy(&name[j][0], temp);
			j++;
		} else {
			count += time[i];
			printf("%s %d\n", &name[i][0], count);
		}
		if ( i == n-1 ) {
			if (j > 0) {
				n = j;
				j = 0;
				i = -1;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    string s;
    cin >> s;
    ll a=0,b=0,gc=0,pc=0;
    for (ll i=0;i<s.size();i++){
        if (s[i]=='g' and pc<gc){
            pc++;
            a++;
        }else if (s[i]=='g'){
            gc++;
        }else if (pc<gc){
            pc++;
        }else{
            gc++;
            b++;
        }
    }
    cout << a-b << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define LL long long
#define INF 1e18
#define MAXN 200005
using namespace std;

int n;
LL a[MAXN], ans=INF;

int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; i++)	scanf("%lld", &a[i]), a[i]+=a[i-1];
	int l=1, r=3;
	LL maxn, minn;
	for(int i=2; i<=n-2; i++)
	{
		while(a[l]<a[i]-a[l]) l++;
		while(a[r]-a[i]<a[n]-a[r]) r++;
		if(a[l-1]>a[i]-a[l]) l--;
		if(a[r-1]-a[i]>a[n]-a[r]) r--;
		maxn=max(max(a[l], a[i]-a[l]), max(a[r]-a[i], a[n]-a[r]));
		minn=min(min(a[l], a[i]-a[l]), min(a[r]-a[i], a[n]-a[r]));
		ans=min(ans, maxn-minn);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    string S; cin >> S;
    vector<int>A(26);
    rep(i, S.size()) {
        if (A[S.at(i) - 97] == 1) {
            cout << "no" << endl;
            return 0;
        }
        A[S.at(i) - 97]++;
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> d(n);
	for(int i = 0; i < n; ++i) {
		cin >> d[i];
	}
	
	sort(d.begin(), d.end());
	
	int ans = d[n / 2] - d[n / 2 - 1];
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;



int main() {
  char a,b;
  cin >> a >>b;
  if(a=='H' && b=='H'){cout << 'H' << endl;}else
  if(a=='H' && b=='D'){cout << 'D' << endl;}else  
  if(a=='D' && b=='H'){cout << 'D' << endl;}else
  if(a=='D' && b=='D'){cout << 'H' << endl;}
}

Measured memory_bytes: 3528
#include<iostream>
#include<vector>
#include<list>
#include<algorithm>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
	list<int> v;
	int n;
	scanf("%d",&n);
	while(n--){
		char str[20];
		scanf("%s",str);
		getchar();
		int m;
		if(str[0]=='i'){
			scanf("%d",&m);
			v.push_front(m);
		}else if(strlen(str)>6){
			if(str[6]=='F'){
				v.pop_front();
			}else if(str[6]=='L'){
				v.pop_back();
			}
		}else if(str[0]=='d'){
			scanf("%d",&m);
			getchar();
			list<int>::iterator it;
			for(it=v.begin();it!=v.end();it++){
				if(*it==m){
					v.erase(it);
					break;
				}
			}
		}
	}
	int cnf=0;
	list<int>::iterator it;
	for(it=v.begin();it!=v.end();it++){
		if(cnf++>0){
			printf(" ");
		}
		printf("%d",*it);//注意这里不要搞错了，不是打印v.front()，使用迭代器打印 
	}
	printf("\n");
	return 0;	
}


Measured memory_bytes: 34384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main {


   public static void main(String args[]) throws IOException{

	   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	   int n = Integer.parseInt( br.readLine() );
	   String[] string =  br.readLine().split(" ");
       int[] S = new int[n];


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

    	   S[i] = Integer.parseInt( string[i] );

       }

       int q = Integer.parseInt( br.readLine() );
	   String[] stringq =  br.readLine().split(" ");
       int[] T = new int[q];


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

    	   T[i] = Integer.parseInt( stringq[i] );

       }


       int answer = 0;


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

           answer += binarysearch(S , n, 0, T[i] );

       }

     System.out.println(answer);


   }




   public static int binarysearch(int[] S, int right, int left, int key){


	   while(left < right){
		   int mid = (right + left)/2;
           if( S[mid] == key ){
              return 1;
           }
           else if(key < S[mid] ){
        	  right = mid;
           }
           else{
        	   left = mid + 1;
           }
	   }


	   return 0;
   }


}

Measured memory_bytes: 47252
#include<iostream>

int main() {
    int a,b,c;
    std::cin>> a >> b >> c;
    int sum = a + b;
    if (sum >= c) {
        std::cout << b + c << std::endl;
    }
    else {
        std::cout << sum + b + 1 << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<int> p(n);
    rep(i,0,n) cin >> p[i];
    sort(all(p));
    int sum = 0;
    rep(i,0,k){
        sum += p[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3624
# 129 B-Balance
N = int(input())
W =list(map(int, input().split()))
ans = abs((W[0]-sum(W[1:N])))
for i in range(2,N):
    if abs(sum(W[0:i])-sum(W[i:N])) < ans:
        ans = abs(sum(W[0:i])-sum(W[i:N]))
print(ans)

Measured memory_bytes: 3064
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

comb = r*g*b

for i in range(1, n - 1):
    for j in range(2, n):
        if i < j:
            if (2*j - i) <= n:
                if s[i - 1] != s[j - 1]:
                    if s[i - 1] != s[2*j - i - 1]:
                        if s[j - 1] != s[2*j - i - 1]:
                            comb -= 1

print(comb)

Measured memory_bytes: 68344