akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? " " : "");
    outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? "\n" : "");
    outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
    cout << head;
    outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    var(i64, a, b);
    i64 gcd = __gcd(a, b);
    i64 res = primeFactorize(gcd).size() + 1;
    outl(res);
    return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int n;

bool good (int a, int b, int c) {
	return (a + b > c);
}

int main() {

	FAST;

	cin >> n;
	vector <int> a(n + 1);
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		for (int j = i + 1; j <= n; j ++) {
			for (int k = j + 1; k <= n; k ++) {
				if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) {
					if (good(a[i], a[j], a[k]) && good(a[j], a[k], a[i]) && good(a[i], a[k], a[j])) {
						ans ++;
						// cout << i << ' ' << j << ' ' << k << '\n';
					}
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}	

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

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

  // 最小の価値は L 最大の価値は L + N -1
  // ゼロのりんごが存在するのは　L < 0 かつ |L| < N
  int ans = 0;
  if (L < 0){
    if (-L < N){
      for(int i=0; i<N; i++){
        ans += L + i;
      }
    } else{
      // 価値は全部負
      for (int i=0; i<N-1; i++){
        ans += L + i;
      }
    }
  } else{
    // 価値は全部正
    for (int i=1; i<N; i++){
      ans += L + i;
    }
  }
  cout << ans << endl;
  return 0;
}


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int ans = S.length();
    int cnt0 = 0, cnt1 = 0;
    rep(i, S.length()) {
        if (S[i] == '0') cnt0++;
        else cnt1++;
    }
    cout << min(cnt0, cnt1) * 2 << endl;

    return 0;
}


Measured memory_bytes: 512
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = INF
  for S in [s[b - 1], s[b]]:
    for T in [t[d - 1], t[d]]:
      d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
      res = min(res, d1, d2)
  print(res) 

Measured memory_bytes: 14232
#include <iostream>
#include <string>
#include<algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (i % 2 == 0) cout << s[i];
	}
	cout << endl;
    return 0;
}



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

int st[1001],head=0;

void push(int x){
  st[head++]=x;
}

void pop(void){
  head--;
}

int top(void){
  return st[head-1];
}

main(){
  int i,t[100],a,b;
  char s[100];
  
  while(scanf("%s",s)!=EOF){
    a=0;
    b=0;
    if(s[0]=='+'){
      a=top();
      pop();
      b=top();
      pop();
      push(a+b);
    }
    else if(s[0]=='-'){
      a=top();
      pop();
      b=top();
      pop();
      push(b-a);
    }
    else if(s[0]=='*'){
      a=top();
      pop();
      b=top();
      pop();
      push(a*b);
      
    }
    else push(atoi(s));
    
  }
  printf("%d\n",top());
  return 0;
}
  

Measured memory_bytes: 548
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		no3();
	}

	static void no3() {
		try (Scanner sc = new Scanner(System.in)) {
			Integer N = sc.nextInt();
			Integer M = sc.nextInt();

			long once = (M * 1900) + 100 * (N - M);
			double percent = Math.pow(0.5, M);

			long time = (long) (once / percent);
			System.out.println(time);
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int a,b;
  string ans;
  cin>>a>>b;
  if(a%2==1 && b%2==1) ans="Yes";
  else ans="No";

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main()
{
  string s;
  cin >> s;
  int ans;
  if (s == "SAT") ans = 1;
  else if (s == "FRI") ans = 2;
  else if (s == "THU") ans = 3;
  else if (s == "WED") ans = 4;
  else if (s == "TUE") ans = 5;
  else if (s == "MON") ans = 6;
  else if (s == "SUN") ans = 7;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 100005;
int N;
vi G[100005];
vi va[100005];

int bin(vi &a, int r, int lim) {
    auto g = [&](int mid) {
        int i = 0, j = r - 1;
        for (int k = 0; k < r / 2;) {
            if (i == mid) i++;
            else if (j == mid)j--;
            else {
                k++;
                if (a[i++] + a[j--] > lim) {
                    RT 0;
                }
            }
        }
        RT 1;
    };

    if (!g(r - 1))RT - 1;

    int ok = r - 1, ng = -1;
    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;
        (g(mid) ? ok : ng) = mid;
    }

    RT ok;
}

int f(int u, int p, int lim) {
    int C = sz(G[u]) - 1;

    auto &a = va[u];
    if (sz(a) < C) {
        a.reserve(C);
        a.resize(C);
    }

    for (int i = 0, j = 0; i < sz(G[u]); ++i) {
        int v = G[u][i];
        if (v != p) {
            a[j++] = f(v, u, lim);
        }
    }
    sort(all(a));
    if (sz(a) && a.back() > lim)RT INF;

    if (C % 2) {
        int k = bin(a, C, lim);
        if (k == -1)RT INF;
        RT a[k] + 1;
    } else {
        int chk = 1;
        rep(i, C / 2) {
            if (a[i] + a[C - 1 - i] > lim) {
                chk = 0;
                break;
            }
        }
        if (chk)RT 1;

        int k = bin(a, C - 1, lim);
        if (k == -1 || u == 1)RT INF;

        RT a[k] + 1;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    cin >> N;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int A = 0;
    rep(i, N + 1)A += sz(G[i]) & 1;
    A /= 2;
    G[1].push_back(0);

    int ng = 0, ok = N;
    while (ok - ng > 1) {
        int mid = (ng + ok) / 2;
        int re = f(1, 0, mid);
        (re - 1 <= mid ? ok : ng) = mid;
    }
    
    int B = ok;
    cout << A << ' ' << B << endl;
}

Measured memory_bytes: 21888
#include<stdio.h>


int fibonacci(int);

int F[45];

int main(){

  int i,n;

  scanf("%d",&n);
  for(i=0;i<45;i++)F[i]=0;

  printf("%d\n",fibonacci(n));

  return 0;

}


int fibonacci(int n){

  if(n==0 || n==1) return F[n]=1;
  if(F[n]!=NULL)return F[n];

  return F[n]=fibonacci(n-2)+fibonacci(n-1);

}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pll> vp;
typedef vector<ll> vll;


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

    int N, M;
    while (cin >> N >> M && N) {
        vi h(N);
        vi w(M);
        rep(i, N) cin >> h[i];
        rep(i, M) cin >> w[i];

        vi sh;
        rep(i, N) {
            int t = 0;
            rep2(j, i, N) {
                t += h[j];
                sh.emplace_back(t);
            }
        }
        sort(all(sh));

        ll ans = 0;
        rep(i, M) {
            int t = 0;
            rep2(j, i, M) {
                t += w[j];
                ans += upper_bound(all(sh), t) - lower_bound(all(sh), t);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 15536
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
//#include<unordered_set>
//#include<unordered_map>
#include<bitset>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;

const int N = 6e5 + 5;
int t;

int main()
{
	int n, k, c;
	while (cin >> n >> k)
	{
		map<int, int> mp;int x;
		while (k--)
		{
			cin >> c;
			f(i, 1, c) { scanf("%d", &x);mp[x]++; }
		}
		ll ans = 0;
		f(i, 1, n)if (mp[i] == 0)ans++;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define all(in) in.begin(),in.end()

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

// 遅延評価セグメント木 lazyRMQ
struct lazyRMQ{
    int n;
    const int INF = 2e9;
    vector<int> node, lazy;

    lazyRMQ(int n_){
        int x = 1;
        while ( x < n_ ) x *= 2;
        n = x;
        node.resize(n*2-1,INF);
        lazy.resize(n*2-1,INF);
    }

    void eval(int k, int l, int r){
        if(lazy[k] != INF){
            chmin(node[k], lazy[k]);
            if(r-l > 1){
                chmin(lazy[2*k+1], lazy[k]);
                chmin(lazy[2*k+2], lazy[k]);
            }
            lazy[k] = INF;
        }
    }

    void update(int a, int b, int x, int k = 0, int l = 0, int r = -1){
        if(r == -1) r = n;
        eval(k,l,r);
        if (r <= a || b <= l) return;
        else if (a <= l && r <= b) {
            lazy[k] = x;
            eval(k,l,r);
        }
        else {
            update(a, b, x, k * 2 + 1, l, (l + r) / 2);
            update(a, b, x, k * 2 + 2, (l + r) / 2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    int query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r == -1) r = n;
        if (r <= a || b <= l) return INF;
        eval(k, l, r);
        if (a <= l && r <= b) return node[k];
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

using pp = pair<int,pair<int,int>>;

int main(){
    int n, q; cin >> n >> q;
    vector<pp> data(n); rep(i,n) cin >> data[i].se.fi >> data[i].se.se >> data[i].fi;
    sort(all(data));
    vector<int> d(q); rep(i,q) cin >> d[i];

    lazyRMQ ans(q);
    rep(i,n){
        int x = data[i].fi;
        int left = data[i].se.fi, right = data[i].se.se;
        left = lower_bound(all(d), left-x) - d.begin();
        right = lower_bound(all(d), right-x) - d.begin();
        ans.update(left,right,x);
    }
    rep(i,q){
      int res = ans.query(i,i+1);
      cout << (res == 2e9 ? -1 : res) << endl;
    }
    return 0;
}

Measured memory_bytes: 10364
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int ans = 0;

		for(int i = a; i <= b; i++){
			if(c%i == 0)ans++;
		}

		System.out.printf("%d\n",ans);
	}
}



Measured memory_bytes: 26420
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];

    }
    sort(ALL(a));
    ll ans = 0;
    for (ll i = 0; i < k; i++)
    {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define inf 1000000000000000009
#define mod 1000000007
typedef long long ll;
using namespace std;
#include<set>
set<int> st;
int main(){
	int n;
	cin>>n;
	lol(i,n){
		int a;cin>>a;
		if(st.find(a)==st.end()){
			st.insert(a);
		}
		else st.erase(a);
	}
	cout<<st.size()<<endl;
	return 0;
}


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

#define ll long long
int main() {
	int r, D; ll x;
	while (scanf("%d%d%lld", &r, &D, &x) != EOF) {
		for (int i = 1; i <= 10; ++i) {
			x = 1ll * r * x - D;
			printf("%lld\n", x);
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e5+5;
const ll inf=1e17;




int main()
{
    idfc;


    ll ans=0;
    ll c=0;

    ll n;
    cin>>n;
    ll e;
    ll i;
    ll tmp;
    for(i=1;i<=n;i++)
    {
        cin>>e;
        tmp=(e*c)%modo;
        ans=(ans+tmp)%modo;
        c=(c+e)%modo;
    }
    cout<<ans;


    return 0;
}

Measured memory_bytes: 3640
n = int(input())
b = list(map(int, input().split()))
a_sum = 0

a_sum += b[0]

for i in range(n-2):
    if b[i] >= b[i+1]:
        a_sum += b[i+1]
    if b[i+1] > b[i]:
        a_sum += b[i]

a_sum += b[n-2]
print(a_sum)

Measured memory_bytes: 3064
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: BTreeSet<_> = (0..n + 1).collect();
    let mut r2: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    let mut cnt = 1;
    while !r2.is_empty() {
        if !rems.is_empty() {
            cnt += 1;
        }
        while let Some(s_idx) = q.pop_front() {
            rems.remove(&s_idx);
            if !r2.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            if let Some(destv) = dests.remove(&s_num) {
                for dest in destv {
                    q.push_back(dest);
                }
            }
        }
        if let Some(&rem) = r2.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
        if let Some(&r) = rems.iter().next() {
            // q.push_back(r);
            cnt += r;
        }
    }
    if cnt > 1e18 as usize{
        println!("{}", "hoge");
    }
    println!("{}", ans);
}


Measured memory_bytes: 27576
fun main(args: Array<String>) {
  val N = readInt()
  val P = readInts()
  val Q = readInts()

  val origin = (1..N).toMutableList()
  var pIndex = 0
  var qIndex = 0
  for (i in 0 until Int.MAX_VALUE) {
    if (origin == P) pIndex = i
    if (origin == Q) qIndex = i
    if (!nextPermutation(origin)) break
  }
  println(Math.abs(pIndex - qIndex))
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }

/** 順列の列挙 c++ のやつと一緒 */
fun nextPermutation(list: MutableList<Int>): Boolean {
  for (i in list.size - 2 downTo 0) {
    if (list[i] < list[i + 1]) {
      for (j in list.size - 1 downTo 0) {
        if (list[i] < list[j]) {
          val tmp = list[i]
          list[i] = list[j]
          list[j] = tmp
          list.subList(i + 1, list.size).reverse()
          return true
        }
      }
    }
  }
  list.reverse()
  return false
}

Measured memory_bytes: 41148
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define F first
#define S second


int main()
{

// #ifndef ONLINE_JUDGE
// 	// for getting input from input.txt
// 	freopen("input.txt", "r", stdin);
// 	// for writing output to output.txt
// 	freopen("output.txt", "w", stdout);
// #endif

	int n;
	cin >> n;
	vector<ll> a(n), b(n), c(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}

	vector<vector<ll>> dp(n + 1, vector<ll>(3, 0));
	for (int i = 0; i < n; i++)
	{
		dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][1], dp[i][2]) + a[i]);
		dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][0], dp[i][2]) + b[i]);
		dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][0], dp[i][1]) + c[i]);
	}
	ll ans = max(max(dp[n][0], dp[n][1]), dp[n][2]);
	cout << ans << "\n";
	return 0;
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
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; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int gcd(ll a, ll b){
  if(b == 0){
    return a;
  }else{
    return gcd(b,a%b);
  }
}

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,k,m;
  cin >> n >> m >> k;
  
  vector<vector<int>> graph(n,vector<int>(0));
  vector<vector<int>> ng(n,vector<int>(0));
  int a,b;
  REP(i,m){
    cin >> a >> b;
    a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
    ng[a].push_back(b);
    ng[b].push_back(a);
  }
  REP(i,k){
    cin >> a >> b;
    a--;b--;
    ng[a].push_back(b);
    ng[b].push_back(a);
  }
  vector<int> visited(n,-1);
  queue<int> q;
  umap<int,ll> group_size;
  REP(i,n){
    if(visited[i] == -1){
      q.push(i);
      int size = 1;
      int p;
      visited[i] = i;
      while(q.size() > 0){
        p = q.front();q.pop();
        for(auto v : graph[p]){
          if(visited[v] == -1){
            visited[v] = i;
            q.push(v);
            size++;
          }
        }
      }
      group_size[i] = size-1;
    }
  }
  REP(i,n){
    int res = group_size[visited[i]];
    
    for(auto v : ng[i]){
      if(visited[i] == visited[v]){
        res--;
      }
    }
    cout << res <<" ";
  }
  
  return 0;
}


Measured memory_bytes: 16144
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    rep(i,n){
        int a; cin >> a;
        if(a%2==1) continue;
        if(a%3!=0&&a%5!=0){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll K;
	cin >> K;
 
	// 解法
	if (K%2==0){
		cout << pow(K/2, 2) << endl;
	}
	else{
		cout << (K/2)*(K/2+1) << endl;
	}
}
 


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

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

  vector<long long> X = {A, B, C};
  sort(X.begin(), X.end());
  if (X.at(0) % 2 == 0 || X.at(1) % 2 == 0 || X.at(2) % 2 == 0)
    cout << 0 << endl;
  else
    cout << ((X.at(2)/2 + 1) * X.at(0) * X.at(1)) - (X.at(2) /2 * X.at(0) * X.at(1)) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue> 
#include<cmath>
#include<utility>
#include<set>
using namespace std;
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n, x;
  cin >> n;
  set<int> se;
  for(int i = 0; i < n; i++)
  {
    cin >> x;
    se.insert(x);
  }
  if(se.size()==n)
    cout << "YES\n";
  else
    cout << "NO\n";
}

Measured memory_bytes: 9600
N=int(input())
H=[int(i) for i in input().split()]
W=[0]*N
num=0
i=0
while i<N:
    if W[i]==H[i]:
        i+=1
        continue
    for j in range(i,N):
        if W[j]>=H[j]:
            break
        W[j]+=1
    num+=1
    #print(W)
print(num)

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

int main() {
  int A,B,Q;
  cin >> A >> B >> Q;
  vector<long> a(A+2);
  vector<long> b(B+2);
  for(int i=1;i<A+1;i++)cin >> a[i];
  for(int i=1;i<B+1;i++)cin >> b[i];
  a[0]=-10000000000;
  b[0]=-10000000000;
  a[A+1]=10000000000000;
  b[B+1]=100000000000;
  for(int i=1;i<Q+1;i++){
    long x;
    cin >> x;
    auto iia=lower_bound(a.begin(),a.end(),x);
    auto iib=lower_bound(b.begin(),b.end(),x); // OK
    long p,q,r,s;
    int ia=iia-a.begin();
    int ib=iib-b.begin(); // OK
    p=max(a[ia]-x,b[ib]-x);
    ib--;
    q=min(2*(a[ia]-x)+x-b[ib],a[ia]-x+2*(x-b[ib]));
    ia--;
    ib++;
    r=min(2*(x-a[ia])+b[ib]-x,x-a[ia]+2*(b[ib]-x));
    ib--;
    s=max(x-a[ia],x-b[ib]);
    cout << min({p,q,r,s}) << endl;
  }
}



Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC085_A();
        }

        static void ABC085_A()
        {
            Console.WriteLine(Console.ReadLine().Replace("2017", "2018"));
        }
    }
}

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

const int MAXN = 100010;
int A[MAXN], n;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int solve() {
	int cx = 0, tot = 0;
	for (int i = 1; i <= n; ++i) if (A[i] > 1)
		cx += A[i] & 1, ++tot;
	if (cx == 1) {
		for (int i = 1; i <= n; ++i) if (A[i] & 1) --A[i];
		int G = 0;
		for (int i = 1; i <= n; ++i) G = gcd(G, A[i]);
		for (int i = 1; i <= n; ++i) A[i] /= G;
		return solve() ^ 1;
	}
	return tot - cx & 1;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	std::cout << (solve() ? "First\n" : "Second\n");
	return 0;
}


Measured memory_bytes: 768
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2
# ここで分割を行う
 left = arr[:mid]
 right = arr[mid:]
# 再帰的に分割を行う
 left = merge_sort(left)
 right = merge_sort(right)
# returnが返ってきたら、結合を行い、結合したものを次に渡す
 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0
# ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
 while l_i < len(left) and r_i < len(right):
    # ここで=をつけることで安定性を保っている
  if left[l_i][0] <= right[r_i][0]:
   merged.append(left[l_i])
   l_i += 1
  else:
   merged.append(right[r_i])
   r_i += 1

# 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
for i in range(N):
 A,B= map(int,input().split())
 lst[i]=[B,A]
lsta=merge_sort(lst)
ans=0
t=0
for i in range(N):
 t+=lsta[i][1]
 if t>lsta[i][0]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

Measured memory_bytes: 40336
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int r = sc.nextInt();
			if (n == 0 && r == 0)
				break;
			int[] s = new int[n];
			int[] scpy = new int[n];
			for (int i = n - 1; i >= 0; i--) {
				s[i] = n - i;
			}
			for (int i = 0; i < r; i++) {
				int p = sc.nextInt();
				int c = sc.nextInt();
				for (int j = 0; j < n; j++) {
					if (0 <= j && j <= c - 1) {
						scpy[j] = s[(p - 1) + j];
					} else if (c <= j && j <= c + (p - 2)) {
						scpy[j] = s[j - c];
					} else {
						scpy[j] = s[j];
					}
				}
				for (int j = 0; j < n; j++) {
					s[j] = scpy[j];
				}
			}
			System.out.println(s[0]);
		}
	}
}

Measured memory_bytes: 37208
#include <iostream>
using namespace std;
int main(){
    int a[5];
    for(int i = 0; i < 5; i++)cin >> a[i];
    int temp = 9;
    int ind = 0;
    for(int i = 0; i < 5; i++){
        if(temp > a[i] % 10 && a[i] % 10 != 0){
            ind = i;
            temp = a[i] % 10;
        }
    }
    int ans = 0;
    for(int i = 0; i < 5; i++){
        if(i != ind) ans += (a[i] + 9) / 10 * 10;
        else ans += a[i];
    }
    cout << ans << endl;
}

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

#define sz(o) ((int)o.size())
#define all(o) o.begin(), o.end()
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define repr(i, a, b) for(int i = (a); i >= (b); i--)

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<int> vi;

int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};


void solve(int testcase) {
    int h, w;
    cin >> h >> w;
    char g[55][55];
    rep(i, 0, h-1){
        cin >> g[i];
    }
    rep(i, 0, h-1){
        rep(j, 0, w-1){
            if(g[i][j]=='#'){
                bool ok = false;
                rep(k, 0, 3){
                    int x = dr[k] + i, y = dc[k] + j;
                    if(x >= 0 && x < h && y >= 0 && y < w && g[x][y] == '#'){
                        ok = true;
                    }
                }
                if(!ok){
                    cout << "No";
                    return;
                }
            }
        }
    }
    cout << "Yes";
}

int main(){
    #ifdef VPAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << setprecision(2);
    clock_t b = clock();
    int t = 1;
    //cin >> t;
    rep(tt, 1, t) solve(tt);
    clock_t e = clock();
    cerr << (double(e - b) / CLOCKS_PER_SEC) << " sec";
    return 0;
}

Measured memory_bytes: 256
from heapq import heapify, heappop, heappush, heappushpop


class PriorityQueue:
    def __init__(self, heap):
        self.heap = heap
        heapify(self.heap)

    def push(self, item):
        heappush(self.heap, item)

    def pop(self):
        return heappop(self.heap)

    def pushpop(self, item):
        return heappushpop(self.heap, item)

    def __call__(self):
        return self.heap

    def __len__(self):
        return len(self.heap)


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

    first_half = PriorityQueue(a[:N])
    second_half = PriorityQueue(list(map(lambda x: -x, a[2 * N:])))
    f_max, s_min = [0] * (N + 1), [0] * (N + 1)
    f_max[0], s_min[-1] = sum(a[:N]), sum(a[2 * N:])

    for k in range(N):
        first_half.push(a[k + N])
        f_max[k + 1] = f_max[k] + a[k + N] - first_half.pop()
        second_half.push(-a[-N - 1 - k])
        s_min[N - 1 - k] = s_min[N - k] + a[-N - 1 - k] + second_half.pop()

    ans = -float('inf')
    for k in range(N + 1):
        if ans < f_max[k] - s_min[k]:
            ans = f_max[k] - s_min[k]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k,d,a;cin>>n>>k;
  lvector sunuke(n,0);
  rep(i,k) {
    cin>>d;
    rep(j,d) {
      cin>>a;a--;
      sunuke[a]++;
    }
  }
  ll ans=0;
  rep(i,n) if(sunuke[i]==0) ans++;
  print(ans);
  return 0;
}

Measured memory_bytes: 3664
import sys

n = int(sys.stdin.readline())
lst = list(map(int, sys.stdin.readline().split()))

pref = [lst[0]]
for i in range(1, len(lst)):
    pref.append(pref[i-1]+lst[i])

ans = 0
for i in range(len(lst)):
    ans += lst[i] * (pref[-1] - pref[i])

print(ans%(10**9+7))

Measured memory_bytes: 100160
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

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

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,k=0,ans=0;
  string s;
  cin>>s;
  rep(i,(ll)s.size()){
    if(s[i]=='T'){
      if(k){
        k--;
      }else{
        ans++;
      }
    }else{
      k++;
    }
  }
  cout<<ans*2<<endl;
  return 0;
}

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

int main() {
    map<int,long long> mp;
    int n;
    long long k;
    cin >> n >> k;
    for ( int i=0; i<n; i++ ) {
        int a,b;
        cin >> a >> b;
        mp[a]+=b;
    }
    for ( auto p:mp ) {
        if ( p.second>=k ) {
            cout << p.first << '\n';
            break;
        }
        k-=p.second;
    }

    return 0;
}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(c)     for(bool p=1;p;p=next_permutation(ALL(c)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll inf = 1e15;
const ll mod = 1e9+7;
const double eps = 1e-10;

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

struct edge { ll from, to, cost; };

int main() {
    ll N; cin >> N;
    
    map<ll, vector<edge>> mp;
    REP(i, N-1) {
        ll a, b, c; cin >> a >> b >> c;
        mp[b].push_back((edge){b, a, c});
        mp[a].push_back((edge){a, b, c});
    }
    
    ll Q, K; cin >> Q >> K;
    vector<ll> x(Q), y(Q); REP(i, Q) cin >> x[i] >> y[i];
    
    vector<ll> dist(N+1, 0);
    queue<edge> que;
    for (edge e : mp[K]) que.push(e);
    
    while (!que.empty()) {
        edge e1 = que.front(); que.pop();
        if (dist[e1.to] != 0) continue;
        
        dist[e1.to] = e1.cost + dist[e1.from];
        for (edge e2 : mp[e1.to]) 
            if (dist[e2.to] == 0) que.push(e2);
    }
    
    REP(i, Q) cout << dist[x[i]] + dist[y[i]] << endl;
    
    return 0;
}


Measured memory_bytes: 19888
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        long sum = 0;
        for (int i = 0; i < N.length(); i++) {
            sum += N.charAt(i) - '0';
        }

        System.out.println(sum%9 == 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 40204
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

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

void insertionSort(int A[], int N)
{
	int i, j,tmp;

	for (i = 1; i < N; i++)
	{
		j = i;
		while (j > 0 && A[j - 1] > A[j])
		{
			tmp = A[j - 1];
			A[j - 1] = A[j];
			A[j] = tmp;

			j--;
		}
		print(A, N);
	}
}

void bubbleSort(int A[], int N,int *count)
{
	int flag = 0;
	int i, j,tmp;

	for (i = 0; i < N; i++)
	{
		for (j = N - 1; j > 0; j--)
		{
			if (A[j - 1] > A[j])
			{
				tmp = A[j - 1];
				A[j - 1] = A[j];
				A[j] = tmp;
				flag = 1;
				(*count)++;
			}
		}
		if (flag == 0)
			break;
		else
			flag = 0;
	}
}

void selectionSort(int A[], int N,int *count)
{
	int i, j;
	int key,tmp;

	for (i = 0; i < N; i++)
	{
		key = i;
		for (j = i; j < N; j++)
		{
			if (A[j] < A[key])
				key = j;
		}
		if (i != key)
		{
			tmp = A[i];
			A[i] = A[key];
			A[key] = tmp;
			(*count)++;
		}
	}
}


int binary_search(int A[], int N, int key)
{
	int left, right, middle;

	left = 0, right = N - 1;

	while (left <= right)
	{
		middle = (left + right) / 2;
		if (A[middle] == key)
			return 1;
		else if (A[middle] > key)
			right = middle - 1;
		else if (A[middle] < key)
			left = middle + 1;
	}
	return 0;
}

#define SIZE 1000

int stack[SIZE];
int pos;

void init()
{
	pos = 0;
}

int isEmpty()
{
	if (pos == SIZE)
	{
		printf("ERROR\n");
		return 1;
	}
	return 0;
}

void push(int x)
{
	stack[pos++] = x;
}

int pop()
{
	int x;
	x = stack[--pos];

	return x;
}

int main()
{
	int i, j, n, q;
	int S[100000], T[10000];

	int count = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
		scanf("%d", &S[i]);

	scanf("%d", &q);

	for (i = 0; i < q; i++)
		scanf("%d", &T[i]);

	for (i = 0; i < q; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (T[i] == S[j])
			{
				count++;
				break;
			}
		}
	}

	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 2116
#include<stdio.h>
int main()
{
    int n;
    scanf("%lld",&n);
    long long ans=0;
	for(int i=0;i<n;i++)ans=ans+((long long)(n-i)*(long long)(i+1));
    for(int i=1,u,v;i<n;i++)
    {
    	scanf("%d%d",&u,&v);
    	if(u>v)u=u+v,v=u-v,u=u-v;
    	long long d=(long long)u;
    	if(n-v+1<u)d=(long long)n-v+1;
    	d*=(long long)(n-v+u+1)-d;
    	ans-=(long long)d;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1736
#include <stdio.h>
int main(void){
    int n,r=0,l=0;
    char s[110];
    scanf("%d %s",&n,s);
    for(int i=0;i<n;i++){
        if(s[i]=='(')l++;
        else r++;
        if(s[i]==')'&&s[i+1]=='('&&l-r<=0){
            for(int i=0;i<r-l;i++){
                printf("(");
            }
            r=0;
            l=0;
        }
    }
    int d=l-r;
    if(d>=0){
        printf("%s",s);
        for(int i=0;i<l-r;i++){
            printf(")");
        }
    }
    else{
        for(int i=0;i<r-l;i++){
            printf("(");
        }
        printf("%s",s);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair
#define F first
#define S second

int main() {
	int n,m, a,b, now = 0, ans = 0;
	vector<pair<int, int>> p;
	cin >> n >> m;
	p.resize(m);
	REP(i, m) {
		cin >> a >> b;
		p[i] = MP(b, a);
	}
	sort(ALL(p));
	REP(i, m) {
		if (p[i].S >= now) {
			now = p[i].F;
			ans++;
		}
	}
	cout << ans << endl;
}




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

int main()
{
    char s[100001];
    int a[26] = {0};
    int i, j;
    scanf("%s", s);
    for (i=0; i<strlen(s); i++)
    {
        for (j=0; j<26; j++)
        {
            if (s[i] == j+97) {
                a[j] ++;
            }
        }
    }
    int count = 0;
    for (i=0; i<26; i++)
    {
        if (a[i] == 0) {
            printf("%c\n", i + 97);
            break;
        }
        count ++;
    }
    if (count == 26) {
        printf("None\n");
    }
    return 0;
}


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

int main() {
    vector<int> a(4);
    vector<int> A = {1, 4, 7, 9};
    
    for (int i = 0; i < a.size(); i++)
    {
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());

    for (int i = 0; i < A.size(); i++)
    {
        if (a[i] != A[i])
        {
            cout << "NO" << endl;
            return 0;
        }
        
    }
    
    cout << "YES" << endl;
}

Measured memory_bytes: 256