akhauriyash/Code-Regression huggingface dataset:
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, x;
  while (cin >> n >> x, n || x) {
    ll ans = 0;
    rep(a, 1, n+1) rep(b, 1, a) rep(c, 1, b) {
      if (a + b + c == x) ++ans;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3204
#include<stdio.h>
#define M(a,b) (a<b?a:b)
int main()
{
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	printf("%d\n",M(M(a,b),c)+M(d,e)-50);
	return 0;
}

Measured memory_bytes: 0
let  lines: any = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', function (line: string) {
  lines.push(line.split(/\s/).map(i => parseInt(i)));
});
reader.on('close', function() {
  let [n, m]: number[] = lines.shift();
  let k: number[][] = lines;
  let array: number[] = new Array(m + 1);
  array.fill(0);
  for (let i = 0; i < n; i++) {
    let idx: number = k[i].shift();
    for (let j = 0; j < idx; j++) {
      const element: number = k[i][j];
      array[element] += 1;
    }
  }
  
  console.log(array.filter(item => item === n).length);
});

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

int main()
{
  while(1){
    int x,y;
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    if(x > y) cout << y << " " << x << endl;
    else cout << x << " " << y << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let () =
        (
                let set = Str.split (Str.regexp "") (read_line ())
                          |> List.sort_uniq compare
                          |> Set.of_list
                in

                let abclst = ["a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "k"; "l"; "m"; "n"; "o"; "p"; "q"; "r"; "s"; "t"; "u"; "v"; "w"; "x"; "y"; "z"]
                             |> Set.of_list
                in
                        try 
                                Set.diff abclst set
                                |> Set.min_elt
                        with Not_found -> ("None")
        ) |> Printf.printf "%s\n"


Measured memory_bytes: 9856
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}
func main() {
	n := nextInt()
	ps := nextInts(n)
	isMiddleF := func(l, c, r int) bool {
		if (l < c && c < r) || (r < c && c < l) {
			return true
		}
		return false
	}

	count := 0
	for i := 1; i < n-1; i++ {
		if isMiddleF(ps[i-1], ps[i], ps[i+1]) {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 640
#pragma GCC optimize("O3") 
#include<bits/stdc++.h>
#define ll      				long long int
#define vi      				vector<int>
#define ii      				pair<int,int>
#define iii     				pair<ii,int>
#define iiii    				pair<ii,ii>
#define fi      				first
#define se      				second
#define unord_map				unordered_map
#define nxt_pmt					next_permutation
#define clr							clear
#define ALL(x) 					x.begin(),x.end()


#define pb      				push_back
#define pob     				pop_back

#define all(x)  				x.begin(), x.end()
#define len     				length()

#define db(x)					  cout << "!!!!!! " << #x << " => " << x << "\n"

#define fori(i, s, N)     for (int i = s; i <= N; i++)
#define ford(i, s, N)     for (int i = s; i >= N; i--)
using namespace std;

void init(int precision){
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

int t;
void cjam(int z){
	cout<<"Case #"<<z<<": ";
	
}

int main(){
//	init(10);
	float a,b,c,d;
	cin>>a>>b>>c>>d;
	if(ceil(c/b) <= ceil(a/d)) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(void)
{
	int n, k ,x, y;
	int total;

	scanf("%d %d %d %d", &n, &k, &x, &y);
	if (n > k){
		total = (k * x) + (n - k) * y;
		printf("%d\n", total);
	}
	else {
		total = n * x;
		printf("%d\n", total);
	}

	return (0);
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
 
using namespace std;
 
int main()
{
  int N;
  string S;
  cin >> N >> S;
  vector<int> left = vector<int>(N, 0);
  vector<int> right = vector<int>(N, 0);
  for (int i = 0; i < N; i++)
  {
    if (i == 0)
    {
      if (S[0] == 'W')
      {
        left[0]++;
      }
      else
      {
        right[0]++;
      }
    }
    else
    {
      right[i] += right[i - 1];
      left[i] += left[i - 1];
      if (S[i] == 'W')
      {
        left[i]++;
      }
      else
      {
        right[i]++;
      }
    }
  }
 
  int res = 1e9;
  for (int i = 0; i < N; i++)
  {
    // i=reader
    int temp = 0;
    if (i == 0)
    {
      temp = right[N - 1];
    }
    else
    {
      temp = left[i] + (right[N - 1] - right[i - 1]) - 1;
    }
    res = min(res, temp);
  }
  cout << res << endl;
  return 0;
}

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

using namespace std;

int main(){
  int science[4];
  int society[2];
  int max_science=0;
  int max_society=0;
  int total=0;

  for(int i=0;i<4;++i)
    cin>>science[i];

  sort(begin(science),end(science),greater<int>());

  for(int i=0;i<3;++i)
    total+=science[i];

  for(int i=0;i<2;++i)
    cin>>society[i];

  total+=max(society[0],society[1]);

  cout<<total<<endl;
}

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <fstream>
#include <bitset>
#include <array>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

const int INF = 1e9+7;

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

int main() {
    const string s = "CODEFESTIVAL2016";
    int ans = 0;
    string str; cin >> str;

    rep(i, str.size()) {
        if (str[i] != s[i]) ans++;
    }
    cout << ans << endl;
}


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



#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int>> vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;



class UnionFind {
public:
    vector<int> par;
    vector<int> rank;
    int N;
    UnionFind(int N_){
        N = N_;
        par = vector<int>(N, 0);
        rank = vector<int>(N, -1);
        for (int i = 0; i < N; i++){
            par[i] = i;
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }

    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    vi P(N);
    rep(i, N)cin >> P[i];
    UnionFind u(N);
    //cout << "b" << endl;
    rep(i, M){
        int x, y;
        cin >> x >> y;
        //cout << "a" << endl;
        u.unite(x-1, y-1);
    }

    int ans = 0;
    rep(i, N) {
        if(u.same(i, P[i]-1))ans++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1408
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))


import itertools

pat = list(itertools.permutations(range(1, N + 1)))

pi = pat.index(P) + 1
qi = pat.index(Q) + 1

if pi - qi < 0:
    print(qi - pi)
else:
    print(pi - qi)


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

int main(void) {
	
	int A, B;
	cin >> A >> B;

	int X = A + B;
	int Y = A - B;
	int Z = A * B;

	if (X >= Y && X >= Z) {
		cout << X << endl;
	} else if (Y>=X && Y>=Z) {
		cout << Y << endl;
	} else if (Z>=X && Z>=Y) {
		cout << Z << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace::std;
using ll = long long;
int main() {
    ll N; cin >> N;
    int res = 20;
    for (ll i=1;i<=sqrt(N);i++){
        if (N%i!=0) continue;
        ll B = N/i;
        int l = to_string(B).size();
        res = min(l,res);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N = input()
V = input().split()
C = input().split()
ret_X_Y = 0
V = [int(i) for i in V]
C = [int(i) for i in C]
for i in range(len(V)):
    if (V[i] - C[i]) > 0:
        ret_X_Y += V[i] - C[i]
print(ret_X_Y)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL ){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }


  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25152
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int cnt = 0;
        bool flg = 0;
        while(1){
            if(n == 6174)break;
            if(n%1111 == 0){
                flg = 1;
                break;
            }
            int a[4]={0};
            a[0] = n/1000;
            a[1] = (n%1000)/100;
            a[2] = (n%100)/10;
            a[3] = n%10;
            int L[4],S[4];
            sort(a,a+4);
            for(int i = 0; i < 4; i++){
                L[3-i] = S[i] = a[i];
            }
            int l=0,s=0;
            for(int i = 0; i < 4; i++){
                l += L[3-i] * pow(10,i);
                s += S[3-i] * pow(10,i);
            }
            n = l - s;
            cnt++;
        }
        if(flg)puts("NA");
        else printf("%d\n",cnt);
    }
	return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
int main(){ _
    stack<LL> s;
    string S;
    getline(cin, S);
    stringstream ss;
    ss << S;
    string tmp;
    while (ss >> tmp){
        if (tmp.size() == 1){
            if (isdigit(tmp[0])){
                s.push(tmp[0] - '0');
            }else{
                LL second = s.top();
                s.pop();
                LL front = s.top();
                s.pop();
                switch(tmp[0]){
                    case '+':
                        s.push(front + second);
                        break;
                    case '-':
                        s.push(front - second);
                        break;
                    case '*':
                        s.push(front * second);
                        break;
                }
            }
        }else{
            stringstream ss_2;
            ss_2 << tmp;
            LL LL_tmp;
            ss_2 >> LL_tmp;
            s.push(LL_tmp);
        }
    }
    cout << s.top() << '\n';
}



Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n;
    cin >> n;
    set<char> x;
    for (int i = 0; i < n; ++i) {
        char k;
        cin >> k;
        x.insert(k);
    }
    cout << (x.size() == 3 ? "Three" : "Four") << "\n";
    return 0;
}


Measured memory_bytes: 256
K, N = map(int,input().split())
A_list = list(map(int,input().split()))
sabun = []
for i in range(1,N):
    sabun.append(A_list[i] - A_list[i-1])
sabun.append(A_list[0]+ K-A_list[N-1])
#print(sabun)
print(sum(sabun)-max(sabun))

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

typedef long long ll;
const int Maxn = 2e5;

int N, A[Maxn + 5], B[Maxn + 5];
priority_queue<pair<int, int> > q;

int main() {
//	freopen("hopeless.in", "r", stdin);
//	freopen("hopeless.out", "w", stdout);
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	scanf("%d", &N);
	for(int i = 1; i <= N; i++)	
		scanf("%d", &A[i]);
	for(int i = 1; i <= N; i++) {
		scanf("%d", &B[i]);
		if(A[i] != B[i])
			q.push(make_pair(B[i], i));
	}
	ll ans = 0;
	while(!q.empty()) {
		int pos = q.top().second;
		q.pop();
		int pre = (pos == 1 ? N : pos - 1), nxt = (pos == N ? 1 : pos + 1);
		if(B[pos] - A[pos] < B[pre] + B[nxt]) {
			puts("-1");
			return 0;
		}
		ans += (B[pos] - A[pos]) / (B[nxt] + B[pre]);
		B[pos] -= ((B[pos] - A[pos]) / (B[nxt] + B[pre])) * (B[nxt] + B[pre]);
		if(A[pos] != B[pos])
			q.push(make_pair(B[pos], pos));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4724
// C - Mazimum Volume
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    double l;
    cin >> l;
    double ans = 1.0;
    // if(l%3 == 0) ans = l/3*l/3*l/3;
    // else if(l%3 == 1.0){
    //     int l2 = l/3+1;
    //     ans = l/3*l/3*l2;
    // }
    // else{
    //     int l2 = l/3+1;
    //     ans = l/3*l2*l2;
    // }
    ans = l/3*l/3*l/3;
    printf("%.20f\n", ans);
    return 0;
}

Measured memory_bytes: 3752
class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        f = [1] * (max_fact + 1)
        for idx in range(2, max_fact + 1):
            f[idx] = f[idx - 1] * idx
            f[idx] %= mod
        if mod > max_fact:
            fi = [pow(f[-1], mod - 2, mod)]
            for idx in range(max_fact, 0, -1):
                fi += [fi[-1] * idx % mod]
            fi = fi[::-1]
        else:
            fi = [pow(n, mod - 2, mod) for n in f]
        self.mod = mod
        self.f = f
        self.fi = fi

    def factorial(self, n):
        return self.f[n]

    def factorial_inverse(self, n):
        return self.fi[n]

    def combination(self, n, r):
        f = self.f
        fi = self.fi
        return f[n] * fi[r] * fi[n - r] % self.mod

    def permutation(self, n, r):
        return self.f[n] * self.fi[n - r] % self.mod

    def homogeneous_product(self, n, r):
        f = self.f
        fi = self.fi
        return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod


max_fact = 4 * 10**5 + 100
mod = 10**9 + 7
fact_instance = Factorial(max_fact, mod)
comb_repl = fact_instance.homogeneous_product
comb = fact_instance.combination

N, K = [int(_) for _ in input().split()]
ans = 0
for r in range(min(N - 1, K) + 1):
    ans += comb(N, r) * comb_repl(N - r, r)
    ans %= mod
print(ans)


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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
typedef struct aaaaa{
  int x,y,t;
}Grid;
using namespace std;
int main(){
  ll r,s,p;cin>>r>>s>>p;
  vector<ll>ho(p);
  for(int i=0;i<p;i++){
    int a,b;cin>>a>>b;
    if(b<=s){
    ho[i]=(r-a)+1+abs(s+1-b);
    }else{
    ho[i]=(r-a)+1+abs(b-s);
    }
  }
  sort(ALL(ho));
  
  ll cnt=0;
  ll mae=0;
  for(int i=1;i<p;i++){
    // if(i>1&&(ho[i-1]-ho[i-2]>1))mae=max(0LL,mae-abs(ho[i-1]-ho[i-2])+1);
    ll cn=0;
    while(i<p&&ho[i]==ho[i-1]){
      cn++;
      i++;
    }
    cnt=mae+cn;
    mae=max(0LL,cnt-(ho[i]-ho[i-1])+1);
    //cout<<mae<<endl;
  }
  //cout<<max(0LL,cnt-(ho[ho.size()-1]-ho[ho.size()-2])+1)<<endl;
  if(ho.size()>=2&&ho[ho.size()-1]!=ho[ho.size()-2])
    cout<<max(0LL,cnt-(ho[ho.size()-1]-ho[ho.size()-2])+1)+ho[ho.size()-1]<<endl;
  else
    cout<<max(0LL,cnt)+ho[ho.size()-1]<<endl;
  return 0;
}



Measured memory_bytes: 6732
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
        long long int n,a,b,ans,k,res;
        cin >> n >> a >> b;
        k = n / (a + b); 
        res = n % (a + b); 
        if (k >= 1)
        {   
                if (res >= a)
                        ans = k * a + a;
                else
                        ans = k * a + res;
        }   
        else
        {   
                if (a >= n)
                        ans = n;
                else
                        ans = a;
        }   
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int A,B,K;
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&K);
	
	int i;
	int c;
	for(i=0;i<K;i++){
		if(A+i==B){break;}
		printf("%d\n",A+i);
		c = A+i;
	}
	for(i=K;i>0;i--){
		if(c>=B-i+1){
			//nothing to do
		}else{
			printf("%d\n",B-i+1);
		}
	}
	
	return 0;}

Measured memory_bytes: 128
s = input()
n = len(s)
ans = 0
def bfs(num,i):
    if i == n:
        global ans
        ans += eval(num)
    else:
        bfs(num+'+'+s[i],i+1)
        bfs(num+s[i],i+1)
bfs(s[0],1)
print(ans)

Measured memory_bytes: 38512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a[] = new int[n + 1];
        int b[] = new int[n];
        for (int i = 0; i < n + 1; i++) {
            a[i] = in.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = in.nextInt();
        }

        long total = 0;
        for (int i = 0; i < n; i++) {
            if (b[i] <= a[i]) {
                total += b[i];
            } else {
                b[i] -= a[i];
                total += a[i];
                
                int nextBaster = Math.min(a[i + 1], b[i]);
                total += nextBaster;
                a[i + 1] -= nextBaster;
            }
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 64856
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args)
	throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] n = TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br));
		
		ArrayList<String> input1 = TempReaderCall.getStdInReadlines(br, n[0]);
		ArrayList<String> input2 = TempReaderCall.getStdInReadlines(br, n[1]);
		
		int[][] array1, array2;
		long[][] ans;
		array1 = getArrayfromStringlist(input1);
		array2 = getArrayfromStringlist(input2);
		
		ans = calcMatrixMultiplication(array1, array2);
		
		printArray(ans);
	}
	
	static void printArray(long[][] array){
		for(int i=0; i<array.length; i++){
			System.out.println(getStringlinefromArray(array[i]));
		}
	}
	
	
	static String getStringlinefromArray(long line[]){
		String data = "";
		for (int i=0; i<line.length-1; i++)
			data = data + Long.toString(line[i]) + " ";
		
		data = data + line[line.length-1];
		return data;
	}
	
	static int[][] getArrayfromStringlist(ArrayList<String> inputdata){
		int[][] array = new int[inputdata.size()][];
		
		for (int i=0; i<inputdata.size(); i++){
			array[i] = TempReaderCall.splitIntArrayFromString(inputdata.get(i));
		}
		
		return array;
	}
	
	static long[][] calcMatrixMultiplication(int[][] array1, int[][] array2){
		long[][] ans = new long[array1.length][];
		
		for (int i = 0; i < ans.length; i++){
			ans[i] = new long[array2[0].length];
			for (int j=0; j<ans[i].length; j++)
				ans[i][j] = calcMatrixMultiplicationElement(array1, array2,i,j);
		}
		
		return ans;
	}
	
	static long calcMatrixMultiplicationElement(int[][] array1, int[][] array2,int i,int j) {
		long ans = 0;
		for (int k=0; k < array2.length; k++){
			ans += array1[i][k] * array2[k][j];
		}
		
		return ans;
	}

}


class TempReaderCall{
	
	static ArrayList<String> getStdInReadlines(BufferedReader br, int line) throws IOException {
		ArrayList<String> list = new ArrayList<String>();
		for (int i = 0; i < line; i++)
			list.add(br.readLine());
		return list;
	}
	
	static String getStdInRead(BufferedReader br) throws IOException {
		return (br.readLine());
	}
	
	
	static int[] splitIntArrayFromString(String st) {
		String[] sts = st.split(" ");
		int[] data = new int[sts.length];
		
		for (int i=0;i<sts.length;i++){
			data[i] = Integer.parseInt(sts[i]);
		}
		
		return data;
	}
}

Measured memory_bytes: 60628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long LL;

constexpr long long INFLL = 1e18;

using namespace std;

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

    int n = 5;
    if (a == 0)
    {
        cout << 1 << endl;
    }

    if (b == 0)
    {
        cout << 2 << endl;
    }
    if (c == 0)
    {
        cout << 3 << endl;
    }
    if (d == 0)
    {
        cout << 4 << endl;
    }
    if (e == 0)
    {
        cout << 5 << endl;
    }
    return 0;
}

Measured memory_bytes: 3164
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  
  int N, Y; cin >> N >> Y;

  Y /= 1000;
  for(int ten = 0; ten <= N; ++ten){
    for(int five = 0; five <= N - ten; ++five){
      int cur = ten * 10 + five * 5;
      int req = Y - cur;
      if(req < 0) continue;
      if(ten + five + req == N){
        cout << ten << " " << five << " " << req << "\n";
        return 0;
      }
    }
  }
  
  cout << "-1 -1 -1\n";
  return 0;
}

Measured memory_bytes: 384
N = int(input())
nAC = 0
nWA = 0
nTLE = 0
nRE = 0
for i in range(N):
  S = input()
  if S == "AC":
    nAC += 1
  if S == "WA":
    nWA += 1
  if S == "TLE":
    nTLE += 1
  if S == "RE":
    nRE += 1
print("AC x %d" % nAC)
print("WA x %d" % nWA)
print("TLE x %d" % nTLE)
print("RE x %d" % nRE)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

const ll INF = 1LL<<60;
int MAX_N = 110;
int MAX_V = 100100;

int main()
{   
    int N;
    ll W;
    vll w(MAX_N), v(MAX_V);

    cin >> N >> W;
    rep(i, N) cin >> w[i] >> v[i];

    vvll dp(MAX_N, vll(MAX_V, INF));
    dp[0][0] = 0;

    rep(i, N) rep(j, MAX_V) {
        chmin(dp[i+1][j], dp[i][j]);
        if(j-v[i] >= 0) chmin(dp[i+1][j], dp[i][j-v[i]] + w[i]);
    }

    int ans = 0;
    rep(i, MAX_V) if(dp[N][i] <= W) ans = i;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 91112
#include<stdio.h>
int N,Q,i;
long long int T;
long long int INF = 2000000000000000000LL;
long long int A[100000];
long long int D[100000];
long long int ans[100000];
long long int boundary;

int main(){


  scanf("%d %lld %d",&N,&T,&Q);
  
  for(i=0;i<N;i++){
    scanf("%lld %lld",&A[i],&D[i]);
    if(D[i]==1){
      ans[i]=A[i]+T;
    }else{
      ans[i]=A[i]-T;
    }
  }

  boundary=-INF;
  for(i=0;i<N;i++){
    if(i>0 && D[i-1]==1&&D[i]==2){
      boundary=(A[i-1]+A[i])/2;
    }
    
    if(D[i]==2 && ans[i] <= boundary){
      ans[i]=boundary;
    }
  }

  boundary=INF;
  for(i=N-1;i>=0;i--){
    if(i+1<N && D[i]==1&&D[i+1]==2){
      boundary=(A[i]+A[i+1])/2;
    }

    if(D[i]==1 && boundary <= ans[i]){
      ans[i]=boundary;
    }
  }

  for(i=0;i<Q;i++){
    int id;
    scanf("%d",&id);
    printf("%lld\n",ans[id-1]);
  }
  return 0;
}

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
using namespace std;
int main(void){
    int N;
    cin>>N;

    vector <int> A(N,0);//数列入力
    for(int i=0;i<N; i++){
        cin>>A[i];
    }
    int ans=0;//答え
    int a;
    for(int j=0;j<N; j++){
        cin>>a;
        ans+=a;
    }
    vector <int> C(N-1,0);
    for(int k=0;k<N-1; k++){
        cin>>C[k];
    }
    int b;
    for(int k=0;k<N-1; k++){//追加の判定
        if(A[k]+1==A[k+1]){
            b=A[k];
            ans+=C[b-1];
        }
    }

    cout<<ans<<endl;

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int left, right;
  left = n/100;
  right = n%100;
  string s;
  if (left>12 && right>12) s = "NA";
  else if (left==0){
    if (right>12) s = "NA";
    else if (right==0) s = "NA";
    else s = "YYMM";
  }
  else if (right==0){
    if (left>12) s = "NA";
    else if (left==0) s = "NA";
    else s = "MMYY";
  }
  else if (left>12) s = "YYMM";
  else if (right>12) s = "MMYY";
  else s = "AMBIGUOUS";
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX/3
using namespace std;
struct edge{int to,cost;};
int n,x,y;
vector<int> vec[100010];
int d1[100010],d2[100010];
signed main(){
    cin>>n;
    rep(i,n-1){
        cin>>x>>y;
        vec[x].push_back(y);
        vec[y].push_back(x);
    }
    queue<int> q;
    q.push(1);
    fill(d1,d1+n+1,INF);
    d1[1]=0;
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(int i:vec[v]){
            if(d1[i]>d1[v]+1){
                d1[i]=d1[v]+1;
                q.push(i);
            }
        }
    }
    while(!q.empty())q.pop();
    q.push(n);
    fill(d2,d2+n+1,INF);
    d2[n]=0;
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(int i:vec[v]){
            if(d2[i]>d2[v]+1){
                d2[i]=d2[v]+1;
                q.push(i);
            }
        }
    }
    int cnta=0,cntb=0;
    for(int i=1;i<=n;i++){
		if(d1[i]<d2[i])cnta++;
		else if(d1[i]>d2[i])cntb++;
		else cnta++;
	}
	if(cnta>cntb)puts("Fennec");
	else puts("Snuke");
    return 0;
}

Measured memory_bytes: 7936
#include <fstream>
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>

using namespace std;
#define ALL(c) (c).begin(), (c).end()
#define REP(i,n) for(ll i=0; i < (n); ++i)
using ll = long long;
using vl = vector<ll>;
int main(){
#ifdef _WIN32
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cout << fixed << setprecision(8);
	ll w, h; cin >> w >> h;
	ll n; cin >> n;
	vl p(n); REP(i, n) cin >> p[i];

	ll a = (w - 1) * 2 + h;
	ll b = (w - 1) * 2 + h - 4;
	ll cnt = 0;
	REP(i, n){
		(p[i] == 0 ? a : b)--;
		if (0 < a && a <= w - 1){
			if (a == b) cnt++;
		}
		else if (w < a && a <= w + h - 2){
			if (a - 2 == b) cnt++;
		}
		else if (w + h - 1 < a && a <= w * 2 + h - 2){
			if (a - 4 == b) cnt++;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 3104
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

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

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = pow(10, 9) + 7;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};


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

int main(void) {

	double L;
	cin >> L;
	double width = L / 3.0;

	double ans = width * width * width ;

	cout << fixed;//小数点を確実に8桁で表示するためのもの
  	cout << setprecision(8) << ans << endl; 

	return 0;
}




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

int cost(int h[],int n,int k){
    int costdp[n+1];
    costdp[0]=0;
    costdp[1]=0;
    costdp[2]=abs(h[1]-h[0]);
    for(int i=3;i<=n;i++){
        int mins=INT_MAX;
        for(int j=1;j<min(k+1,i);j++){
            int count=costdp[i-j]+abs(h[i-1]-h[i-j-1]);
            if(count<mins){
                mins=count;
            }
        }
        costdp[i]=mins;
    }
    return costdp[n];
}
int main() {
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    cout<<cost(h,n,k)<<endl;

}


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    string s;
    cin>>s;
    set<char> st;
    REP(i,3){
        st.insert(s[i]);
    }
    if(st.size()==1) cout<<"No"<<en;
    else cout<<"Yes"<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0, 0)
costs = []
for i in range(n + 1):
    costs.append(abs(a[i + 1] - a[i]))

s = sum(costs)
for i in range(n):
    print(s - costs[i] - costs[i + 1] + abs(a[i] - a[i + 2]))


Measured memory_bytes: 13920
N = int(input())
A = [0] * N
X = [[] for n in range(N)]
Y = [[] for n in range(N)]

for i in range(N):
    a = int(input())
    A[i] = a
    for j in range(a):
        x, y = map(int, input().split())
        X[i].append(x)
        Y[i].append(y)

# print(N, A, X, Y)

def solve(N, A, X, Y, B):
    for n in range(N):
        if B[n] == 0:
            continue
        for a in range(A[n]):
            if B[X[n][a] - 1] != Y[n][a]:
                return False
    return True

max_pop = 0

for i in range(2**N):
    B = [0] * N
    pop = 0
    found = True
    for j in range(N):
        b = (i >> j) & 1
        B[j] = b
        if b == 1:
            pop += 1
    if max_pop >= pop:
        continue
    if solve(N, A, X, Y, B):
        max_pop = pop

print(max_pop)


Measured memory_bytes: 45532
import itertools

N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]
C = []

for a in range(1, N + 1):
  for c in itertools.combinations(CA, a):
    C.append(list(c))

p = float('inf')

for c in C:
  tp = float('inf')
  t = [0] * (M + 1)
  for con in c:
    for i in range(M + 1):
      t[i] += con[i]
      flg = True
    for i in range(1, M + 1):
      if t[i] < X: flg = False
    if flg: p = min(p, t[0])
      
if p == float('inf'):
  print(-1)
else:
  print(p)

Measured memory_bytes: 9344
from fractions import gcd
if __name__ == "__main__":
    N, X = map(int, input().split())
    x = list(map(int, input().split()))

    diff = [0] * N
    for i in range(N):
        diff[i] = abs(x[i] - X)

    ans = diff[0]
    for i in range(N):
        ans = gcd(ans, diff[i])

    print(ans)


Measured memory_bytes: 16284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)cin>>a[i];
  ll ma[n+1];
  ma[n]=2;
  ll mi[n+1];
  mi[n]=2;
  for(ll i=n-1;i>=0;i--){
    if(a[i]>ma[i+1]){
      cout<<-1<<endl;
      return 0;
    }
    ll u=ma[i+1]%a[i];
    ll r=a[i]-1;
    ma[i]=ma[i+1]+r-u;
    ll e=mi[i+1]%a[i];
    if(e!=0){
      mi[i]=mi[i+1]+a[i]-e;
    }
    else mi[i]=mi[i+1];
    if(mi[i]>ma[i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<mi[0]<<" "<<ma[0]<<endl;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};


int main() {
    string X; cin >> X;

    stack<char> st;

    for(auto c:X){
        if(c=='S'){
            st.push(c);
        }else{
            if(!st.empty() && st.top()=='S'){
               st.pop();
            }else{
               st.push(c);
            }
        }
    }

    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 832
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FORB(i,s,e,st) for (int i = int(s); i < int(e); i+=(int(st)))
#define FOR(i,s,e) FORB(i,s,e,1)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))


const int MOD = 1e+9+7;
const double PI  = acos(-1.0);


int main(){
  int n,m;
  cin>>n>>m;
  int cnt[n];
  bool pos[n];
  CLR(pos);
  REP(i,n) cnt[i]=1;
  pos[0]=true;
  int a,b;
  REP(i,m){
    cin>>a>>b;
    cnt[--a]--;
    cnt[--b]++;
    if(pos[a]){
      pos[b]=true;
      if(cnt[a]==0) pos[a]=false;
    }
  }
  int ret=0;
  REP(i,n) ret+=(pos[i]?1:0);
  cout<<ret<<"\n";  
}


Measured memory_bytes: 768
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
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; }
typedef unsigned long ul;
const ul INF = 1LL<<60;
int c[9],a[3],i;
inline void solve(){
  REP(i,3){
    cin>>c[3*i]>>c[3*i+1]>>c[3*i+2];
  }
  REP(a[0],101)REP(a[1],101)REP(a[2],101){
    if((c[0]-a[0])==(c[3]-a[1])&&(c[3]-a[1])==(c[6]-a[2])&&
       (c[1]-a[0])==(c[4]-a[1])&&(c[4]-a[1])==(c[7]-a[2])&&
       (c[2]-a[0])==(c[5]-a[1])&&(c[5]-a[1])==(c[8]-a[2])){
         OUT("Yes");
         return;
       }
  }
  OUT("No");
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char str[102],str1[102],ans[102];
int sam(int ma1,int ma2)
{
    int co,carry=0,a,b;
    for(int i=0;ma1-i>=0||ma2-i>=0||carry==1;i++){
            if(ma1-i>=0&&ma2-i>=0){
                    a=str[ma1-i]-'0';
                    b=str1[ma2-i]-'0';
                    if(a+b+carry>=10){
                        ans[i]=a+b+carry-10+'0';
                        carry=1;
                    }
                    else {
                        ans[i]=a+b+carry+'0';
                        carry=0;
                    }
            }
            else if(ma1-i>=0){
                    a=str[ma1-i]-'0';
                    if(a+carry>=10){
                        ans[i]=a+carry-10+'0';
                        carry=1;
                    }
                    else {
                        ans[i]=a+carry+'0';
                        carry=0;
                    }
            }
            else if(ma2-i>=0){
                    b=str1[ma2-i]-'0';
                    if(b+carry>=10){
                        ans[i]=b+carry-10+'0';
                        carry=1;
                    }
                    else {
                        ans[i]=b+carry+'0';
                        carry=0;
                    }
            }
            else {
                ans[i]='0'+1;
                return i;
            }
        co=i;

    }
    return co;

}
int main()
{
    int a,b,n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>str>>str1;
        a=strlen(str);
        b=strlen(str1);
        a=sam(a,b);
        if(a>80)cout<<"overflow"<<endl;
        else {
                for(int j=a;j>0;j--)cout<<ans[j];
        cout<<endl;
        }
    }

}

Measured memory_bytes: 1156
use proconio::input;

fn main() {
    input! {
        a: isize,
        b: isize,
        c: isize,
        k: isize,
    }
    let (mut result, mut remain) = (0, k);
    if remain >= a {
        remain -= a;
        result += a;
    } else {
        result += remain;
        println!("{}", result);
        std::process::exit(0);
    }

    if remain >= b {
        remain -= b;
    } else {
        println!("{}", result);
        std::process::exit(0);
    }

    if remain >= c {
        remain -= c;
        result -= c;
    } else {
        result -= remain;
        println!("{}", result);
        std::process::exit(0);
    }

    if remain == 0 {
        println!("{}", result);
    } else {
        unreachable!();
    }
}


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

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

  cin >> A >> B >> C;

  if(A == 5 && B == 7 && C == 5){
    cout << "YES";
  }else if(A == 5 && B == 5 && C == 7){
    cout << "YES";
  }else if(A == 7 && B == 5 && C == 5){
    cout << "YES";
  }else{
    cout << "NO";
  }
  
}


Measured memory_bytes: 256
n, m = map(int, input().split())
switch = []
for i in range(m):
    k, *s = map(int, input().split())
    switch.append(s)
mod_val = list(map(int, input().split()))

res = 0
for h in range(0, 1 << n):
    ok = True
    for c in range(m):
        check_mod = 0
        for s in switch[c]:
            if h >> (s - 1) & 1:
                check_mod += 1
        if check_mod % 2 != mod_val[c]:
            ok = False
            break
    if ok:
        res += 1

print(res)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){

int S,h,m,s;

cin >> S;

h = S / 3600;
m = (S % 3600) / 60;
s = (S % 3600) % 60;

cout << h << ":" << m << ":" << s << endl;

return 0;

}



Measured memory_bytes: 3096