akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define vpll vector< vector<pll> >
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int n = 100001;
vpll G(n);
vl d(n, -1);

void dfs(int v, ll dist, int par=-1){
    rep(j, 0, G[v].size()){
        pll p = G[v][j];
        int next_v = p.first;
        if(par == next_v) continue;
        if(d[next_v] > -1) continue;
        ll next_dist = dist + p.second;
        d[next_v] = next_dist;
        dfs(next_v, next_dist, v);
    } 
    return;
}

int main(){
    int N; cin >> N;
    rep(i, 0, N-1){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--; 
        G[a].push_back(make_pair(b, c));
        G[b].push_back(make_pair(a, c));
    }
    int Q, K; cin >> Q >> K;
    K--;
    vi X;
    vi Y;
    rep(i, 0, Q){
        ll x, y;
        cin >> x >> y;
        x--; y--;
        X.push_back(x);
        Y.push_back(y);
    }
    d[K] = 0LL;
    dfs(K, 0, -1);
    rep(i, 0, Q){
        int x = X[i];
        int y = Y[i];
        cout << llabs(d[K] - d[x]) + llabs(d[K] - d[y]) << endl;
    }
    return 0;
}




Measured memory_bytes: 15348
import math

K = int(input())

sum = 0
# for i in range(1,K+1):
#     for j in range(1,K+1):
#         for l in range(1,K+1):
#             sum += math.gcd(math.gcd(i,j),l)
for i in range(1,K+1):
    for j in range(1,K+1):
        if math.gcd(i,j)==1:
            sum += K
        else:
            for l in range(1,K+1):
                sum += math.gcd(math.gcd(i,j),l)


print(sum)


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

using namespace std;
using ll = long long;

int main() {
    string s;
    cin>>s;
    for(int i = 0;i < s.size();++i) {
        if(s[i]=='?')s[i]='D';
    }
    cout<<s<<endl;
    return 0;
}


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

int myGCD(int x, int y){
  if(x > y){
    int tmp = y;
    y = x;
    x = tmp;
  }
  if(y % x == 0) return x;
  else return myGCD(x, y % x);
}

int main(){
  int a, b;
  cin >> a >> b;
  cout << myGCD(a, b) << endl;
  return 0;
}


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

struct UnionFind {
    int par[200000];

    UnionFind(int N) {
        rep(i, N) par[i] = i;
    }

    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        par[x] = y;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int N, K, L, a, b;
    cin >> N >> K >> L;
    UnionFind road(N), rail(N);
    rep(i, K) {
        cin >> a >> b;
        road.unite(a-1, b-1);
    }
    rep(i, L) {
        cin >> a >> b;
        rail.unite(a-1, b-1);
    }
    map<pair<int, int>, int>mp;
    rep(i, N) {
        mp[make_pair(road.root(i), rail.root(i))]++;
    }
    rep(i, N) {
        cout << mp[make_pair(road.root(i), rail.root(i))] << endl;
    }
    return 0;
}

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

string  f(ll n){
  if(n==0) return "";
  n--;
  return f(n/26) + string(1, 'a'+n%26);
}

int main(){
  ll n;
  cin >> n;
  cout << f(n) << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define y1 wzpakking
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
int n,k,Q,ans,a[100005];
int main(){
	scanf("%d%d%d",&n,&k,&Q);
	For(i,1,Q){
		int x;
		scanf("%d",&x);
		++a[x];
	}
	For(i,1,n)
		puts(a[i]+k>Q?"Yes":"No");
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

int N, v[105];
i64 W, w[105];
i64 dp[105][105 * 1005];

signed main()
{
  int vsum = 0;
  cin >> N >> W;
  for (int i = 0; i < N; ++i) {
    cin >> w[i] >> v[i];
    vsum += v[i];
  }
  vsum += 5;

  memset(dp, INF, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i < N; ++i) {
    for(int j = 0; j <= vsum; ++j) {
      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;
  for (int i = 0; i <= vsum; ++i) {
    if (dp[N][i] <= W) ans = i;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 86784
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<long double,long double>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 5;
ll i,n,p[N];
long double num, den;
ii x[N];
long double go(ll i,ll j)
{
    return sqrt(pow(x[i].f - x[j].f, 2) + pow(x[i].se - x[j].se, 2));
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n){
        cin>>x[i].f>>x[i].se;
        p[i] = i;
    }
    do{
        for(i = 1;i < n;i += 1) num += go(p[i], p[i - 1]);
        den += 1;
    }while(next_permutation(p,p + n));
    cout<<setprecision(8)<<fixed<<num / den;
    return 0;
} 

Measured memory_bytes: 640
(*a,t=(0..$_.to_i).map{gets.to_i}
n=b=c=0
a=t>b ?a[n+1..-1]:a[0,n]while(s=a.size)>0&&(c+=1)&&t!=b=a[n=(s-1)/2]
p c)while gets>?1

Measured memory_bytes: 6100
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

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

	int i=62;
	while(i >= 0 && ((A&(1L<<i)) == (B&(1L<<i)))) i--;
	if (i < 0){
		cout << 1 << endl;
		return 0;
	}

	A &= (1L<<i)-1;
	B &= (1L<<i)-1;

	int j=i-1;
	while(j >= 0 && ((B&(1L<<j)) == 0)) j--;
	//cout << i << " " << j << " " << (1L<<i) << endl;

	if((1L<<(j+1))-1 >= A){
		cout << (1L<<(i+1))-1-A+1 << endl;
		return 0;
	}
	//cout << (1L<<(j+1)) << " " <<  2*((1L<<(i))-A) << endl;
	cout << (1L<<(j+1)) + 2*((1L<<(i))-A) << endl;

	return 0;
}


Measured memory_bytes: 384
var
a:array[0..26] of 0..1;
s:ansistring;
i,x:longint;
begin
read(s);
for i:=1 to length(s) do a[ord(s[i])-96]:=1;
for i:=26 downto 1 do
  begin
    x:=x+a[i];
    if a[i]=0 then s:=chr(96+i);
  end;
if x=26 then writeln('None')
        else writeln(s);
end.

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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 long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    // cin.tie(0);
    // ios_base::sync_with_stdio(0);
    int d, n;
    cin >> d >> n;

    if (n == 100) {
        cout << (n + 1) * (int)pow(100, d) << endl;
    }
    else {
        cout << (int)pow(100, d) * n << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b;
	ll k;
	//string s, t;
	ll ans = 0;
	//string ans = "NG";

	cin >> a >> b;

	ans = a * b;

	cout << ans << "\n";

	return;
}


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

	solve_abc_a();

	return 0;
}

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

//temp
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define MIN(x) *min_element(all(x))
#define MAX(x) *max_element(all(x))
#define in(x) cin >> x
#define co(x) cout << x
#define el  cout << endl
#define dump(x)  cout << #x << " = " << (x) << endl

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


int main() {
  int array[2][100050]={{},{}};
  int N, num, nummax=0, atemp, btemp, amax0=0, amax1, bmax0=0, bmax1, akey, bkey, ans;

  in(N);
  REP(i, N){
    in(num);
    chmax(nummax, num);
    array[i%2][num]++;
  }
  REP(j, nummax+1){
    atemp=amax0;
    btemp=bmax0;
    if(chmax(amax0, array[0][j])){
      amax1 = atemp;
      akey = j;
    }else{
      chmax(amax1, array[0][j]);
    }
    if(chmax(bmax0, array[1][j])){
      bmax1 = btemp;
      bkey = j;
    }else{
      chmax(bmax1, array[1][j]);
    }
  }

  if(akey==bkey){
    ans = min(N - amax0 - bmax1, N - amax1 - bmax0);
  }else{
    ans = N - amax0 - bmax0;
  }

  co(ans);
  
  return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
#ABC124C
import sys

s = input()
n=len(s)

num=0
for i in range(0,n):
	if(i%2==0):
		if(s[i]=="1"):
			num+=1
	else:
		if(s[i]=="0"):
			num+=1

print(min(n-num,num))



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

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

  for(int i = 0; i < K; i++){
    if(A >= B){
      B = B*2;
    }
    else{
      C=C*2;
    }
  }

  string ans;

  if(A < B && B < C){
    ans = "Yes";
  }
  else{
    ans = "No";
  }
  cout << ans << endl;

  /*int N = 3;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }*/

  /*for (int i = 0; i < vec.size(); i ++){
    cout << vec.at(i) << endl;
  }

  for (int i = 0; i < vec.size()-1; i ++){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(vec.size() - 1) << endl;*/
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    string S;
    cin >> N >> S;
    vector<vector<int>> charSum(N + 1, vector<int>(26, 0));
    rep(i, 0, N)
    {
        rep(j, 0, 26)
        {
            charSum[i + 1][j] = charSum[i][j] + (S[i] == 'a' + j);
        }
    }
    int ans = 0;
    rep(i, 1, N)
    {
        int num = 0;
        rep(j, 0, 26)
        {
            if ((charSum[i][j] > 0) && (charSum[N][j] - charSum[i][j] > 0)) ++num;
        }
        chmax(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  sort(v.rbegin(), v.rend());
  int sum = 0;
  for(int i = 0; i < k; i++) sum += v[i];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long res = 0;
        for(int i=1; i<=n; i++) {
            res += (long)i * (n+1-i);
        }
        for(int i=0; i<n-1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            long aa = Math.min(a, b);
            long bb = Math.max(a, b);

            res -= (aa * (n+1-bb));

        }
        System.out.println(res);


    }


}




Measured memory_bytes: 59396
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> ans(3,0);
    rep(i,n){
        ll a;
        cin >> a;
        if(a%4==0)++ans[0];
        else if(a%2==0)++ans[1];
        else ++ans[2];
    }
    bool a = true;
    if(n==1){
        if(ans[0]!=1)a = false;
    }else if(n==2){
        if(ans[2]>=2 || (ans[1]==1 &&ans[2]==1))a = false;
    }else if(n==3){
        if(ans[2]==2 && ans[1]==1)a = false;
        if(ans[1] == 2 && ans[2]==1)a = false;
        if(ans[2]>=3)a = false;
    }
    else{
        if(ans[1] != 0){
            ans[1] = 0;
            ans[2]++;
        }
        if(ans[0]+1<ans[2])a = false;
    }
    if(a)cout << "Yes"<<endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())

P = [0]*M
Y = [0]*M

for i in range(M):
    P[i],Y[i] = map(int,input().split())

A = [0]*N
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))


Measured memory_bytes: 21820
def judge_ss(word):
    l = len(word)
    
    if l % 2 != 0:
        return 0
    
    for i in range(l//2):
        if word[i] != word [i+l//2]:
            return 0

    return 1
    
S = list(input())
l = len(S)

ans = 0

for i in range(1,l-1):
    if judge_ss(S[:l-i]):
        print(len(S[:l-i]))
        break

Measured memory_bytes: 3060
s = input()
t = input()
ans = []
for i in range(len(s)-len(t)+1):
    S = s[i:i+len(t)]
    cnt = 0
    for j in range(len(t)):
        if t[j] == S[j]:
            cnt += 1
    ans.append(cnt)

a = ans.index(max(ans))
b = s[a:a+len(t)]
count = 0
for k in range(len(t)):
    if t[k] != b[k]:
        count += 1
print(count)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - k; i++) {
    //cout << "a[i]=" << a[i] << " a[k+i]=" << a[k + i] << endl;
    if (a[i] >= a[k + i]) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4772
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int K,N;
	int t[100001];
	ll d[100001];
	vll pt[100001];
	vpll dttop,dtless,dtall;
	int tnum=0;
	scan(N);scan(K);
	rep(i,N){
		scan(t[i]);scan(d[i]);
		pt[t[i]].push_back(d[i]);
	}
	rep1(i,N) if(pt[i].size()) sort(pt[i].rbegin(),pt[i].rend());
	rep1(i,N){
		if(pt[i].size()){
			dttop.push_back(mp(pt[i][0],i));
			rep1(j,pt[i].size()-1){
				dtless.push_back(mp(pt[i][j],i));
			}
			tnum++;
		}
	}
	sort(dttop.rbegin(),dttop.rend());
	sort(dtless.rbegin(),dtless.rend());
	ll dtlesssum[100001]={},dttopsum[100001]={};
	int dtlesskind[100001]={};
	bool alre[100001]={};
	int alrenum[100001]={};
	rep(i,K){
		if(i<dtless.size()) dtlesssum[i+1]=dtlesssum[i]+dtless[i].first;
		if(i<dttop.size()) dttopsum[i+1]=dttopsum[i]+dttop[i].first;
		if(i<dtless.size()) alrenum[i+1]=alrenum[i]+(alre[dtless[i].second]==0);
		if(i<dtless.size()) alre[dtless[i].second]=1;
	}
	ll ans=0;
	for(ll i=1;i<=dttop.size();i++){
		if(0<=K-i&&K-i<=dtless.size()&&alrenum[K-i]<=i) ans=max(ans,dttopsum[i]+dtlesssum[K-i]+i*i);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 10608
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007


int main(void)
{
	CIN;
	ll tc,l,k=0,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	map<string,ll>mp;
	string s;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>s;
		mp[s]++;
	}
	cin>>m;
	for(ll i=0;i<m;i++){
		cin>>s;
		mp[s]--;
	}
	for(auto i:mp){
		z=max(i.second,z);
	}
	cout<<z;
	
}

Measured memory_bytes: 3604
n = int(input())
a = [int(x) for x in input().split()]


def bubblesort(n,a):
    count = 0
    flag = 1
    while flag:
        flag = False
        for i in reversed(range(1,n)):
            if a[i-1] > a[i]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = True
                count += 1
    return a, count

a, count = bubblesort(n,a)
print(' '.join(map(str, a)))
print(count)


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    vector<int> A(3);
    rep(i, 3) cin >> A[i];
    sort(all(A));
    if ((A[0] == A[1] && A[1] != A[2]) || (A[1] == A[2] && A[0] != A[1])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split())) 

num_dict = {}
for a in a_list:
    num_dict.setdefault(a,0)
    num_dict[a] += 1

all_comb = 0
for num,cnt in num_dict.items():
    comb = cnt*(cnt-1)//2
    all_comb += comb

for a in a_list:
    a_cnt = num_dict[a]
    a_comb_diff = a_cnt*(a_cnt-1)//2 - (a_cnt-1)*(a_cnt-2)//2
    print(all_comb-a_comb_diff)



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

int main()
{
  string s;
  cin >> s;
  multiset<char> ms(begin(s), end(s));
  string ans = "Yes";
  for (auto&& e : ms) {
    if (ms.count(e) != 2) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    
    vector<int> N(3);
    N.at(0) = A;
    N.at(1) = B;
    N.at(2) = C;
    
    sort(N.begin(),N.end());
    
    int d1, d2;
    
    d1 = N.at(2) - N.at(0);
    d2 = N.at(2) - N.at(1);
    
    if((d1 + d2) % 2 == 0)
        cout << (d1 + d2)/2 << endl;
    else
        cout << (d1 + d2 + 1)/2 + 1 << endl;
    
}


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

int N, M;

int main(){
	int i, j, cnt, res;
	scanf("%d", &N); res = 0;
	for(i = 1; i <= N; i++){
		cnt = 0;
		for(j = 1; j <= i; j++){
			if(i % j == 0) cnt++;
		}
		if(i % 2 && cnt == 8) res++;
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Two Arrays
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], bs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

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

  ll an = 0, bn = 0;
  for (int i = 0; i < n; i++) {
    int di = bs[i] - as[i];
    if (di > 0) an += (di + 1) / 2, bn += (di & 1);
    else if (di < 0) bn += -di;
  }

  if (an >= bn) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 384
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score=-1000000000;
int keisan(){
  int cost=0,i,j;
  vector<int> x(26,-1);
  for(i=0;i<d;i++){
    cost+=s[i][ans1[i]];
    x[ans1[i]]=i;
    for(j=0;j<26;j++){
      cost=cost-c[j]*(i-x[j]);
    }
  }
  return cost;
}
void solve(){
  int i;
  if(score<=keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    int v=randxor()%d;
    int w=randxor()%d;
    swap(ans1[v],ans1[w]);
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
void solve1(){
  int i;
  if(score<=keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    ans1[randxor()%d]=randxor()%26;
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=i%26;
    ans[i]=ans1[i];
  }
  while(clock()-ti<198.2*CLOCKS_PER_SEC/100){
    solve();
    solve1();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

Measured memory_bytes: 3864
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <functional>
#include <time.h>
#include <math.h>

using namespace std;


int main() {

	int a, b,ans;

	cin >> a >> b;

	double buffa;
	buffa = double((b - 1)) / double((a - 1));

	ans = ceil(buffa);

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	int dx = 0;
	while(dx < s.size())
	{
		string sub = s.substr(dx, 5);
		
		if(sub == "dream")
		{
			dx += 5;
			if(s[dx] == 'e' && s[dx + 1] == 'r' && s.substr(dx, 5) != "erase")
			{
				dx += 2;
			}
		}
		else if(sub == "erase")
		{
			dx += 5;
			if(s[dx] == 'r')
			{
				dx++;
			}
		}
		else
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
    int h, w; cin >> h >> w;
    vector<string> grid(h);
    for (int i = 0; i < h; i++) {
        string line; cin >> line;
        grid.at(i) = line;
    }
    vector<vector<int64_t> > dp(h+1, vector<int64_t> (w+1,0));
    dp.at(1).at(1) = 1;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if ((grid.at(i-1).at(j-1) == '#') || (i == 1 && j == 1)) {
                continue;
            }
            dp.at(i).at(j) = (dp.at(i-1).at(j) + dp.at(i).at(j-1)) % MOD;
        }
    }
    cout << dp.at(h).at(w) << endl;
}

Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>

using namespace std;

int N;
long long L[105];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", L+i);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      for (int k = j+1; k < N; k++) {
        if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]) {
          if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
            ans++;
          }
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << # x << "; "<< x << endl


int main() {
    int N;
    cin >> N;
    string S;
    vector<string> vec;
    bool same;
    for (int i = 0; i < N; i++) {
        cin >> S;
        same = false;
        for (int j = 0; j < vec.size(); j++) {
            if (vec.at(j) == S) {
                same = true;
                break;
            }
        }
        if (!same) {
            vec.push_back(S);
        }
    }
    if (vec.size() == 3) {
        cout << "Three" << endl;
    }
    else if (vec.size() == 4) {
        cout << "Four" << endl;
    }
}


Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;


public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	
	static class Pair
	{
		int p;
		int q;
		Pair(int p,int q)
		{
			this.p = p;
			this.q = q;
		}
	}
	
	static int gcd(int a,int b)
	{
		if(a == 0) return b;
		if(b == 0) return a;
		
		return gcd(b,a%b);
	}
	
	static boolean check(char x)
	{	
		if(x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') return false;
		return true;
	}
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        int a = sc.nextInt();
        String s = sc.nextLine();
        
        if(a%2 != 0)
        {
        	out.println("No");
        	out.close();
        	return;
        }
        else
        {
        	int m = a/2;
        	for(int i = 0; i < a/2; i++)
        	{
        		if(s.charAt(i) != s.charAt(m))
        		{
        			out.println("No");
                	out.close();
                	return;
        		}
        		m++;
        	}
        }
        out.println("Yes");
        out.close();
	}

}


Measured memory_bytes: 24660
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

ll d[60][200200];
const ll inf=1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //reopen("input.txt", "r", stdin);
    ll n,k; cin >> n >> k;
    k*=n;
    vector<int> a(n);
    map<int,vector<int>> mp;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mp[a[i]].push_back(i);
    }
    for(auto p:mp){
        int sz=p.second.size();
        p.second.push_back(p.second[0]+n);
        for(int i=0;i<sz;i++){
            d[0][p.second[i]]=p.second[i+1]-p.second[i]+1;
        }
    }
    for(int i=0;i<59;i++){
        for(int j=0;j<n;j++){
            d[i+1][j]=min(inf,d[i][j]+d[i][(ll)(j+d[i][j])%n]);
        }
    }
    ll cur=0;
    for(int i=59;i>=0;i--){
        if(cur+d[i][cur%n]<=k){
            cur+=d[i][cur%n];
        }
    }
    if(cur==k){
        return 0;
    }
    vector<int> res;
    set<int> s;
    for(ll i=cur%n;i<n;i++){
        if(s.find(a[i])==s.end()){
            res.push_back(a[i]);
            s.insert(a[i]);
        }
        else{
            while(1){
                int v=res.back();
                res.pop_back();
                s.erase(v);
                if(v==a[i])break;
            }
        }
    }
    for(int i=0;i<res.size();i++){
        if(i)printf(" ");
        printf("%d",res[i]);
    }
    printf("\n");
}


Measured memory_bytes: 129780
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <list>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define xx first
#define yy second
#define $1 first
#define $2 second

void solveCase() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n, l; cin >> n >> l;
	vector<string> v; v.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++)cout << v[i];
	return;
}

int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	solveCase();
}

Measured memory_bytes: 256
import math
n=int(input())
t=[]
for i in range(n-1):
    t.append(list(map(int,input().split())))

for i in range(n):
    s=i
    ti=0
    while s!=n-1:
        if ti<t[s][1]:
            ti=t[s][1]+t[s][0]
        else:
            ti=t[s][2]*(math.ceil(ti/t[s][2]))+t[s][0]
        s+=1
    print(ti)

Measured memory_bytes: 3316
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), K = sc.nextInt();
    char S[] = sc.next().toCharArray();
    S[K - 1] += 32;
    System.out.println(S);
  }
}

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

#define int long long

int32_t main()
{
    int n,k;
    cin>>n>>k;
    
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    
    int dp[n]={0};
    for(int i=1;i<min(k,n);i++)
        dp[i]=abs(a[i]-a[0]);
    
    for(int i=k;i<n;i++)
    {
        int res=LONG_LONG_MAX;
        for(int j=max(i-k,0LL);j<i;j++)
        {
           int ans=dp[j]+abs(a[i]-a[j]);
            res=min(res,ans);
        }
        dp[i]=res;
    }
    cout<<dp[n-1];
}
                  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define debugV(x,n) for(int i = 0;i < n;i++) cerr << x[i] << " "; cerr<<endl;
#define rep(i,a,b) for(int i = (int)a;i < (int)b;i++)
#define F first
#define S second
#define pb push_back
typedef pair<int,int> ii;
typedef long long int ll;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;

int n;
string a,b;
int main(){
	cin>>n>>a>>b;
	rep(i,0,n)
	{
		cout <<a[i]<<b[i];
	}
	cout <<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

a = list(map(int,input().split()))

L = sum(a)

nagasa = 0

ans = 0

i=0

for i in range(n):
  nagasa += a[i]
  if nagasa*2 >= L:
    ans = min(abs(L - (nagasa *2)), abs(L - ((nagasa-a[i])*2)))

    break
    

print(ans)



    



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

int main() {

	string S;
	cin >> S;

	int a = (S.at(0) - '0') * 10 + (S.at(1) - '0');
	int b = (S.at(2) - '0') * 10 + (S.at(3) - '0');
	

	if (1 <= a && a <= 12 && 1 <= b && b <= 12) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (0 <= a && a <= 99 && 1 <= b && b <= 12) {
		cout << "YYMM" << endl;
	}
	else if (0 <= b && b <= 99 && 1 <= a && a <= 12){
		cout << "MMYY" << endl;
	}
	else {
		cout << "NA" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int>a(n);
	for (int& x : a)cin >> x;

	sort(a.begin(), a.end());
	cout << a[a.size()-1] - a[0] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long 

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

signed main()
{
    fastio;
    string s;
    cin>>s;
    int ans=0;
    int w=0;
    int n=s.length();
    for(int i=n-1;i>=0;--i)
    {
        if(s[i]=='W')
            ++w;
        else
        {
            ans+=w;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 720
def solve(N, arr):

	dp = [0] * 3

	for j in range(3):
		dp[j] = arr[0][j]

	for i in range(1, N):
		dp2 = [0] * 3
		for j in range(3):
			for x in [(j - 1) % 3, (j + 1) % 3]:

				if 0 <= x < 3:
					dp2[j] = max(dp2[j], dp[x] + arr[i][j])
		dp = dp2
	return max(dp)

N = int(input())
arr = []
for _ in range(N):
	arr.append([int(s) for s in input().split()])
print(solve(N, arr))






Measured memory_bytes: 24308
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  int cnt = 0;
  int tgtnum = 1;
  
  REP(i,n){
    if(a[i] != tgtnum){
      cnt++;
    }
    else{
      tgtnum++;
    }
  }

  cout << ((cnt == n) ? -1 : cnt) << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <stack>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    string x; cin >> x;
    bool check = false;
    int cnt = 0;
    int ans = 0;
    for(int i = 0; i < x.size(); i++){
        if(cnt == 0){
            check = false;
        }
        if(x[i] == 'S'){
            check = true;
            cnt++;
        } else {
            if(check && cnt > 0){
                cnt--;
                ans++;
            }
        }
    }
    cout << x.size() - ans*2 << endl;
}



Measured memory_bytes: 640
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 610;
int e[SIZE][SIZE],deg[SIZE];
double dp[SIZE],arrived_p[SIZE];
int main(){
    int N,M;
    R(N,M);
    REP(i,M){
        int x,y;R(x,y);
        e[x][y]=1;
        deg[x]++;
    }
    for(int i=N-1;i>=0;i--){
        FOR(j,i+1,N){
            if(e[i][j])dp[i]+=dp[j];
        }
        dp[i]=dp[i]/deg[i]+1;
    }
    arrived_p[1]=1;
    REPP(i,1,N){
        FOR(j,i+1,N){
            if(e[i][j])arrived_p[j]+=arrived_p[i]/deg[i];
        }
    }
    double an=dp[1];
    FOR(i,1,N)FOR(j,i+1,N){
        if(e[i][j]&&deg[i]>1){
            an=min(an,dp[1]-arrived_p[i]*dp[i]+arrived_p[i]*(((dp[i]-1)*deg[i]-dp[j])/(deg[i]-1)+1));
        }
    }
    W(an);
    return 0;
}


Measured memory_bytes: 1792
N, M = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(M)))


G = [set() for _ in range(N + 1)]
for x, y in zip(a, b):
    G[x].add(y)
    G[y].add(x)


# 次数4の頂点間のパスの数が4でないならばTrueを返す
def f():
    x, y = (i for i in range(1, N + 1) if len(G[i]) == 4)
    q = []
    dp = [0 for _ in range(N + 1)]
    q.append(x)
    dp[x] = 1
    while q:
        i = q.pop()
        for j in G[i]:
            if j != y and dp[j] == 0:
                q.append(j)
            dp[j] += 1
    return dp[y] != 4


# 以下のいずれかを満たすならば、かつ、そのときに限りYes
# - 次数4の頂点間を結ぶ異なる4つのパスが存在しない場合
# - 各頂点の次数は2または4であり、次数4の頂点は3個存在する場合
# - 各頂点の次数は偶数であり、次数が6以上の頂点が存在する場合
ans = (
    'Yes' if (
        all(len(G[i]) % 2 == 0 for i in range(1, N + 1)) and
        (
            any(len(G[i]) >= 6 for i in range(1, N + 1)) or
            sum(len(G[i]) == 4 for i in range(1, N + 1)) >= 3 or
            sum(len(G[i]) == 4 for i in range(1, N + 1)) == 2 and f()
        )
    ) else
    'No'
)

print(ans)


Measured memory_bytes: 57468
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } vector<ll> uniq(vector<ll> arr)
{vector<ll>brr;sort(all(arr));brr.append(arr[0]);
for(auto i:arr)if(brr.back()!=i)brr.append(i);return brr;}

void solve(){
    ll a; cin>>a; cout<<a+a*a+a*a*a<<endl;
}

int main(){
    ffast;
    ll t=1; //cin>>t;
    rep(t) solve();
}


// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)

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

const int MAX_N = int(3e3) + 10;

int n, l;
double a[MAX_N], ans_x, ans_y;

void get(double angle, int cnt) {
	ans_x += cnt * cos(angle);
	ans_y += cnt * sin(angle);
}

int main() {
	scanf("%d%d", &n, &l);
	for (int i = 1; i <= n; ++i) {
		scanf("%lf", a + i);
		a[i] = a[i] / l * 2 * M_PI;
	}
	std::sort(a + 1, a + n + 1);

	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			double angle1 = (a[i] + a[j]) / 2, angle2 = angle1 + M_PI;
			get(angle1, n - (j - i + 1));
			get(angle2, j - i - 1);
		}
	}
	double all = 1.0 * n * (n - 1) * (n - 2) / 6;
	printf("%.10lf %.10lf\n", ans_x / all, ans_y / all);
}

Measured memory_bytes: 4212
import sys; readline = sys.stdin.readline
from collections import deque

N = int(readline())

YX = [list(map(int, readline().split())) for i in range(N)]

total = 0

def dfs(score, last, rem):
    global total
    if len(rem) == 0:
        total = total + score
        return
    
    for n in rem:
        x = score + ((YX[last][0] - YX[n][0]) ** 2 + (YX[last][1] - YX[n][1]) ** 2) ** 0.5
        dfs(x, n, rem - {n})

n_fact = 1
for i in range(N):
    n_fact *= (i + 1)

s = set(range(N))
for n in s:
    dfs(0, n, s - {n})
print(total / n_fact)

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

int main(void){

    int a, b, c;

    scanf("%d%d%d", &a, &b, &c);

    if((a + b == c) || (b + c == a) || (c + a == b)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1664
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

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

N =  int(sys.stdin.buffer.readline())
T, A = list(map(int, sys.stdin.buffer.readline().split()))
H = list(map(int, sys.stdin.buffer.readline().split()))
H = np.array(H, dtype=float)

ans = np.argmin(np.abs((T - H * 0.006) - A))
print(ans + 1)


Measured memory_bytes: 15476