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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef int T_CC;
const int CC_MAX = 200010;

class CC{
	T_CC unzip[CC_MAX];
	map<T_CC , int> zip;
	int size;
	
public:
	
	void dft(){
		size = 0;
		zip.clear();
	}
	
	int insert(T_CC a){
		if(size == CC_MAX) return -1;
		zip[a] = size;
		unzip[size] = a;
		return ++size;
	}
	
	int arrange(){
		int a = 0;
		for(map<T_CC , int>::iterator it = zip.begin() ; it != zip.end() ; ++it){
			(*it).second = a;
			unzip[a] = (*it).first;
			++a;
		}
		size = a;
		return size;
	}
	
	int get_size(){
		return size;
	}
	
	int code(T_CC a){
		map<T_CC , int>::iterator it = zip.find(a);
		return it != zip.end() ? (*it).second : -1;
	}
	
	T_CC decode(int a){
		if(a >= size) return 0;
		return unzip[a];
	}
} cc;

const int ST_MAX = (1 << 18);

template <class T> class ST{
	T x[ST_MAX * 2];
	
	T eval(T a , T b){
		return max(a,b);
	}
	
	void ren(int a){
		x[a] = eval(x[2 * a] , x[2 * a + 1]);
		if(a > 0) ren(a / 2);
	}
	
	T read_ST(int a , int b , int e , int s , int f){
		if(e <= s || f <= b) return 0;
		if(s <= b && e <= f) return x[a];
		return eval(read_ST(2 * a , b , (b + e) / 2 , s , f) , read_ST(2 * a + 1 , (b + e) / 2 , e , s , f));
	}
	
public:
	
	void dft(){
		fill(x,x+ST_MAX*2,0);
	}
	
	void put(int a , T b){
		if(x[a + ST_MAX] >= b) return;
		x[a + ST_MAX] = b;
		ren((a + ST_MAX) / 2);
	}
	
	T get(int s , int f){
		return read_ST(1 , 0 , ST_MAX , s , f);
	}
};

ST<int> st;
const int MC = 200010;
const int H = 1e8 - 1;
int xx1,yy1,xx2,yy2;
int N;
int X[MC] , Y[MC];
int s[MC];
const double PI = 3.141592653589793;

int main(){
	scanf("%d%d%d%d" , &xx1 , &yy1 , &xx2 , &yy2);
	if(xx1 > xx2){
		swap(xx1,xx2);
		swap(yy1,yy2);
	}
	scanf("%d" , &N);
	repp(i,0,N){
		scanf("%d%d" , X + i , Y + i);
		if(yy1 > yy2) Y[i] = H - Y[i];
		s[i] = i;
		cc.insert(Y[i]);
	}
	if(yy1 > yy2){
		yy1 = H - yy1;
		yy2 = H - yy2;
	}
	sort(s,s+N,[&](const int p , const int q){return X[p] < X[q];});
	cc.insert(yy1);
	cc.insert(yy2);
	cc.arrange();
	for(int i = 0 ; i < N && X[s[i]] <= xx2 ; ++i){
		if(X[s[i]] < xx1 || Y[s[i]] < yy1 || Y[s[i]] > yy2) continue;
		int co = cc.code(Y[s[i]]);
		st.put(co,st.get(0,co)+1);
	}
	int z = st.get(0,cc.code(yy2)+1);
	printf("%.12f\n" , (xx2-xx1+yy2-yy1)*100.0 - z*(20.0-5*PI) + (z==min(xx2-xx1,yy2-yy1)+1 ? 5*PI : 0));
	return 0;
}


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

typedef long long ll;

const ll N = 2020, LOG = 15, inF = 1e16;

ll n, x, ans = inF, a[N], dp[N << 3][LOG];

ll get_min(int l, int r) {
	ll res = inF;
	for (int i = LOG - 1; ~i; i--)
		if(l + (1 << i) - 1 <= r) {
			res = min(res, dp[l][i]);
			l += 1 << i;
		}
	return res;
}

ll MIN(int l, int r) {
	if(l >= 0)
		return get_min(l, r);
	return min(get_min(l + n, n - 1), get_min(0, r));
}

ll get(int l) {
	ll res = x * l;
	for (int i = 0; i < n; i++)
		res += MIN(i - l, i);
	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> x;
	for (int i = 0; i < N; i++)
		dp[i][0] = inF;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dp[i][0] = a[i];
	}
	
	for (int j = 1; j < LOG; j++) {
		for (int i = 0; i < N; i++)
			dp[i][j] = inF;
		for (int i = 0; i < n; i++)
			dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
	}
	cerr << get_min(0, 1) << '\n';
	for (int i = 0; i < n; i++)
		ans = min(ans, get(i));
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int get(int n) {
    int ans = 0;
    for (char c : to_string(n)) ans += c - '0';
    return ans;
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif


    const int INF = 1e9 + 7;
    int n;
    cin >> n;
    int ans = INF;
    for (int i = 1; i < n; ++i) {
        ans = min(ans, get(i) + get(n - i));
    }   
    cout << ans << '\n';

}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
const int INF=1e7;

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  int A[15][15];
  rep(i,N){
    cin >> C[i];
    rep(j,M) cin >> A[i][j];
  }
  int ans=INF;
  rep(bit,1<<N){
    int res=0;
    int S[15]={0};
    rep(i,N){
      if(bit&1<<i){
        res+=C[i];
        rep(j,M) S[j]+=A[i][j];
      }
    }
    rep(i,M){
      if(S[i]<X) break;
      if(i==M-1) ans=min(ans,res);
    }
  }
  if(ans==INF) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
a, b, c, d = gets().chomp.split("\s").map{|x| x.to_i}

cnt = 0
while(a > 0 && c > 0)
  cnt += 1
  if cnt.odd?
    c = c - b
  else
    a = a - d
  end
end

puts a > 0 ? 'Yes' : 'No'

Measured memory_bytes: 14352
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(float, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N = ii()
P = li()

dp = dp2(0, N+1, N)
dp[0][0] = 1 - P[0]
dp[0][1] = P[0]

for i in range(1, N):
    for j in range(i+1):
        dp[i][j] += dp[i-1][j] * (1-P[i])
        dp[i][j+1] += dp[i-1][j] * P[i]

print(sum(dp[N-1][(N//2+1):])) 

Measured memory_bytes: 253960
#include <iostream>
#include <map>

int main() {
  uint32_t N = 0;
  std::cin >> N;

  std::map<int64_t, uint32_t> dict;
  int64_t sum = 0;
  dict[0]++;
  for (size_t i = 0; i < N; i++) {
    int64_t A = 0;
    std::cin >> A;
    sum += A;
    dict[sum]++;
  }

  uint64_t ans = 0;
  for (auto &&d : dict) {
    if (d.second <= 1) continue;
    ans += static_cast<uint64_t>(d.second) * (d.second - 1) / 2;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 12800
// Course＞Introduction to Programming I ＞ ITP1_1_C:   Rectangle
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_C&lang=jp

// 以下のソースコードには(複数の？)誤りがあるので、このまま提出しても「誤り」と判定されます。
// ソースコード中の誤りを修正し、「正解」（Accepted）を出してください。

// 適宜、paiza.io (https://paiza.io/ja/projects/new) などのC++実行環境を、確認に用いることを推奨します。


#include <iostream>
using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	cout << (a*b) << " "<< (a+b)*2 << endl;
	return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <math.h>

int main(void)
{
    int a, b;
    double x = 0, y = 0;
    int d = 90;

    for (;;) {
        scanf("%d,%d", &a, &b);
        if (a == 0 && b == 0) break;

        x += cos(M_PI * d / 180) * a;
        y += sin(M_PI * d / 180) * a;
        d -= b;
    }

    printf("%d\n%d\n", (int)x, (int)y);

    return 0;
}

Measured memory_bytes: 604
N = int(input())
T = list(map(int, input().split()))
M = int(input())
PX = [list(map(int, input().split())) for _ in range(M)]

tsum = sum(T)

for px in PX:
    p = px[0]
    x = px[1]

    t = tsum - T[p - 1] + x
    print(t)


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

int main() {
    int a,b;cin >> a >> b;
    int A = max(a,b);char B = '0' + min(a,b);
    string ans;
    for (int i = 0;i < A;i++) ans += B;
    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

N = int(input())

xy_list = [{} for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = list(map(int, input().split()))
        xy_list[x-1][str(i)] = y

max_n_honest = 0
for n_honest in range(1, N + 1):
    for is_honest in itertools.combinations(range(N), n_honest):
        aaa = True
        for h_idx in range(N):
            target_is_honest = int(h_idx in is_honest)
            testimony = xy_list[h_idx]
            for honest_idx in is_honest:
                if str(honest_idx) in testimony:
                    if testimony[str(honest_idx)] != target_is_honest:
                        aaa = False
                        break
        if not aaa:
            continue
        n_honest = len(is_honest)

        if n_honest > max_n_honest:
            max_n_honest = n_honest

print(max_n_honest)





Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;


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

    vector<int> waters;
    rep(i,31){
        rep(j,31){
            int water = i*A*100+j*B*100;
            if (water <= F) waters.push_back(water);
        }
    }

    vector<int> sugars;
    rep(i,3001){
        rep(j,3001){
            int sugar = i*C+j*D;
            if (sugar <= F) sugars.push_back(sugar);
        }
    }

    int ans_solution = 0;
    int ans_sugar = 0;
    double concentration = -1.0;
    rep(i,waters.size()){
        rep(j,sugars.size()){
            int solution = waters[i] + sugars[j];
            if (solution > F) continue;
            int dissolve = waters[i]/100*E;
            if (dissolve < sugars[j]) continue;
            double tmp_concentration = 100.0*sugars[j] / solution;
            if (tmp_concentration > concentration){
                concentration = tmp_concentration;
                ans_solution = solution;
                ans_sugar = sugars[j];
            }
        }
    }

    cout << ans_solution << " " << ans_sugar << endl;
}

    

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

using namespace std;

int main()
{
  int h, w;
  cin >> h >> w;
  string line;
  getline(cin, line);

  vector<int> freq(26, 0);
  for (int i = 0; i < h; i++) {
	getline(cin, line);
	for (char ch : line) {
	  freq[ch - 'a']++;
	}
  }

  int num4 = 0;
  int num4_need = (h / 2) * (w / 2);
  for (int i = 0; i < 26; i++) {
	int val = min(num4_need - num4, freq[i] / 4);
	num4 += val;
	freq[i] -= val * 4;
  }

  if (num4 < num4_need) {
	cout << "No" << endl;
	return 0;
  }

  int num2 = 0;
  int num2_need = (h * w - num4_need * 4) / 2;
  for (int i = 0; i < 26; i++) {
	num2 += freq[i] / 2;
  }

  if (num2 < num2_need) {
	cout << "No" << endl;
  } else {
	cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>

using namespace std;

#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque



#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>

#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>

#define vi vector<ll>
#define vs vector<string>

#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator


#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define F first
#define S second
#define pi 2*acos(0.0)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT_ count()
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second

#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GT_ getline
#define NL_   "\n"

#define for(i, n) for(i = 0; i < n; i++)
#define fe(i, n) for(i = 1; i <= n; i++)

#define ul unsigned long long int
#define ll long long int
#define  MAX 250000

ll N, T, tC = 0, i, j, k;







int main()
{
    FAST;

  int a, b, c;
  cin >> a >> b >>c;
  cout << c <<" "<<a <<" "<< b;
    return 0;
}



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

typedef long long int ll;
typedef pair<int, int> pii;
bool R(){return true;}
template<typename T, typename ... Args>
bool R(T & x, Args & ... args){return cin >> x && R(args...);}
void init_io(){ios::sync_with_stdio(false);cin.tie(0);}

#define PB push_back
#define MP make_pair
#define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
#define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
#define SV(vec) do{int __sv;R(__sv);vec.PB(__sv);}while(0)
#define ALL(vec) (vec).begin(), (vec).end()
#define MM(co, cim) memset((co), (cim), sizeof((co)))
#define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
#define INF   1000000007
#define INFLL 4000000000000000007LL

string s;

void solve ()
{
  cin >> s;
  char c = s[s.length() - 1] - '0';
  if (c == 2 || c == 4 || c == 5 || c == 7 || c == 9) printf("hon\n");
  else if (c == 0 || c == 1 || c == 6 || c == 8) printf("pon\n");
  else printf("bon\n");
}

int main ()
{
  init_io();
  int t = 1;
  //R(t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int main(void){
	int b,c,d,e,f,g,h;
	string a;
	cin >> a ;
	
	int ans=0;int res=0;
	for(int i=0;i<a.size();i++){
		if(a[i]=='A' || a[i]=='T' || a[i]=='G' ||a[i]=='C')
			res++;
		else{
			ans=max(ans,res);
			res=0;
		}
	}
	ans=max(ans,res);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	std::string s;

	std::cin >> s;

	if (s == "ABC") {
		std::cout << "ARC" << std::endl;
	}
	else {
		std::cout << "ABC" << std::endl;
	}

	return 0;
}

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

set<int> s;
unordered_map<int, bool> mp;

int main() {
    int q;
    cin >> q;

    while( q-- ) {  
        int op, key;
        cin >> op >> key;

        // insert into set
        if (op == 0) {
            s.insert(key);
            mp[key] = true;
            cout << s.size() << endl;
        } 
        
        // check existance
        else if ( op == 1 ) {
            if ( mp[key] ) cout << 1 << endl;
            else cout << 0 << endl;
        }

        else if (op == 2) {
            auto it = s.find( key );
            s.erase( key );
            mp[key] = false;
        }
    }

    return 0;
}



Measured memory_bytes: 20316
MOD = 10 ** 9 + 7

kai = [1, 1]
for i in range(2, 10 ** 5 + 1):
    num = kai[-1] * i
    kai.append(num % MOD)
n, m = map(int, input().split())
if abs(n - m) > 1:
    ans = 0
else:
    ans = kai[n] * kai[m]
    if n == m:
        ans *= 2
    ans %= MOD
print(ans)

Measured memory_bytes: 71000
#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std ;

const int MAXN=1e5+100;

struct City
{
	int id ;
	int P , Y ;
	int rnk ;
};
City c[MAXN];
int n , m ;

inline bool cmp1 ( City p , City q )
{
	if ( p.P==q.P ) return p.Y<q.Y;
	return p.P<q.P;
}

inline bool cmp2 ( City p , City q ) { return p.id<q.id; }

int main ()
{
	int i , j ;
	scanf("%d%d",&n,&m);
	for ( i=1 ; i<=m ; i++ ) scanf("%d%d",&c[i].P,&c[i].Y),c[i].id=i;
	sort(c+1,c+m+1,cmp1);
	c[1].rnk=1;
	for ( i=2,j=1 ; i<=m ; i++ )
	{
		if ( c[i].P==c[i-1].P ) c[i].rnk=++j;
		else c[i].rnk=j=1;
	}
	sort(c+1,c+m+1,cmp2);
	for ( i=1 ; i<=m ; i++ ) printf("%06d%06d\n",c[i].P,c[i].rnk);
	return 0 ;
}

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int X, N;
    cin >> X >> N;
    map<int, int> list;
    /*for (int i = 0; i <=100; i++)
        list[i] = 0;*/
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        list[tmp]++;
    }

    int i = 0;
    while(true)
    {
        if (list[X - i] != 1)
        {
            cout << X - i;
            break;
        }
        if (list[X + i] != 1)
        {
            cout << X + i;
            break;
        }
        i++;
    }
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void){
  int a,b,c;
  int min,max;
  scanf("%d %d %d",&a,&b,&c);
  if(a<=b && b<=c){
    min=a;
    max=c;
  }
  else if(a<=c && c<=b){
    min=a;
    max=b;
  }
  else if(b<=a && a<=c){
    min=b;
    max=c;
  }
  else if(b<=c && c<=a){
    min=b;
    max=a;
  }
  else if(c<=a && a<=b){
    min=c;
    max=b;
  }
  else{
    min=c;
    max=a;
  }
  printf("%d %d\n",min,max);
  return 0;
}



Measured memory_bytes: 2144
// {{{ Headers
// vim:filetype=cpp:foldmethod=marker:foldmarker={{{,}}}

#include <cassert>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <fstream>
#include <iostream>
#include <sstream>

using namespace std;
// }}}

typedef long long int64;
const int INF = 0x3f3f3f3f;
const int64 LINF = (int64) 1e15;
template <class T> inline int len (const T &a) { return a.size (); }
#define ALL(x) (x).begin(), (x).end()

int64 dp [2][100 * 1000 + 5];
int v [100 * 1000 + 5];
int w [100 * 1000 + 5];
int N, W;

int
main () {
    scanf ("%d %d", &N, &W);
    for (int i = 0; i < N; i++) scanf ("%d %d", w + i, v + i);
    for (int j = 0; j <= 100000; j++)
        dp [0][j] = LINF;

    dp [0][0] = 0;
    for (int i = 1; i <= N; i++) {
        int t = i & 1;
        for (int j = 0; j <= 100000; j++) {
            dp [t][j] = dp [1 - t][j];
            if (j >= v [i - 1])
                dp [t][j] = min (dp [t][j], dp [1 - t][j - v [i - 1]] + w [i - 1]);
        }
    }

    int ret = 0;
    for (int j = 0; j <= 100000; j++)
        if (dp [N & 1][j] <= W)
            ret = max (ret, j);

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


#ifdef LOCALHOST
	cerr << "time: " << (int64) clock () * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#endif
    return 0;
}



Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		
		if(a.length() == 2) {
			System.out.println(a);
		} else {
			String A = a.substring(2, 3);
			String B = a.substring(1, 2);
			String C = a.substring(0 ,1);
			
			String str = A + B + C;
			
			System.out.println(str);
		}
		
	}
}


Measured memory_bytes: 21844
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;

class Counter<T> extends TreeMap<T,Long>{
    public Counter(){
        super();
    }
    public Counter(List<T> list){
        super();
        for(T e: list) this.addOne(e);
    }
    public Long count(Object elm){
        return getOrDefault(elm,0L);
    }
    public void add(T elm, long amount){
        if(!this.containsKey(elm)) put(elm, amount);
        else replace(elm, get(elm)+amount);
        if(this.count(elm)==0) this.remove(elm);
    }
    public void addOne(T elm){
        this.add(elm, 1);
    }
    public void removeOne(T elm){
        this.add(elm, -1);
    }
    public void removeAll(T elm){
        this.add(elm, -this.count(elm));
    }
    public static<T> Counter<T> merge(Counter<T> a, Counter<T> b){
        Counter<T> c = new Counter<>();
        for(T x: a.keySet()) c.add(x, a.count(x));
        for(T y: b.keySet()) c.add(y, b.count(y));
        return c;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Counter<Long> A = new Counter<>();
        long total = 0;
        for(int n=0; n<N; n++){
            long e = sc.nextLong();
            A.addOne(e);
            total += e;
        } 

        int Q = sc.nextInt();
        for(int q=0; q<Q; q++) {
            long B = sc.nextLong();
            long C = sc.nextLong();

            long m = A.count(B);
            A.removeAll(B);
            A.add(C, m);
            total = total - B*m + C*m;
            System.out.println(total);
        }
        
        
    }
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  int n; cin >> n;
  map<int,int> mp;
  for(int i = 0; i < n; ++i){
    int x; cin >> x;
    mp[x]++;
  }
  int sum = 0;
  for(auto e:mp)sum += e.second-1;
  cout << n-(sum+1)/2*2 << endl;
}



Measured memory_bytes: 8140
#include <iostream>
#include <algorithm>
#include <vector>

#define REP(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define PI 3.141592653589

using namespace std;

void InpAr(int *array, int n){
    REP(i,n) cin >> array[i];
}

int main(void){
    int k, x;
    cin >> k >> x;

    if(k * 500 >= x) cout << "Yes";
    else cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars,
        t: chars,
    }
    let n_s = s.len();
    let n_t = t.len();
    let mut ok = 0;
    let mut ook = 0;
    let mut ans = vec!['z'; n_s];

    for i in (0..n_s - n_t + 1).rev() {
        let mut acc: Vec<char> = vec![];
        let sub = &s[i..i + n_t];
        ok = 1;
        let tc = t.clone();

        for j in 0..n_t {
            if !(sub[j] == tc[j] || sub[j] == '?' as char) {
                ok = 0;
                break;
            }
        }

        if ok == 1 {
            ook = 1;
            for k in 0..n_s {
                if i <= k && k < i + n_t {
                    acc.push(tc[k - i]);
                } else if s[k] == '?' {
                    acc.push('a')
                } else {
                    acc.push(s[k]);
                }
            }
            ans = min(ans, acc);
        }
    }

    if ook == 1 {
        for i in 0..n_s {
            print!("{}", ans[i])
        }
        println!();
    } else {
        println!("UNRESTORABLE");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	int len=a.length();
	for(int i=0;i<len;i++)
	{
		if(a[i]!=b[len-i-1])
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;

#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
ll MOD = 1e9+7;
const double PI=3.14159265358979323846;


int main() {
  ll r;
  cin >> r;
  Precision13;
  cout << r*2*PI<<endl;
}

Measured memory_bytes: 3788
#include <vector>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
    string s;cin>>s;
    int n=s.length();
    bool b=0;
    if(s[n-1]=='1'||s[0]=='0')b=true;
    for(int i=0;i<n-1;i++)if(s[i]!=s[n-2-i])b=true;
    if(b)cout<<-1<<endl;
    else{
    int l = 1, i = 2;
        for(;i<=n;++i){
            cout << l << " " << i <<endl;
            if(s[i-2]=='1')l = i;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>  
#include<cmath>
#include<string>
#include<stack>
#include<queue> 
#include<algorithm>
#include<stdlib.h> 
#include<ctime>
#include<iomanip>
#include<vector>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	int count=0;
	for(int i=0;i<n;i++)
		count+=arr[i];
	double num=double(count)/(double(m)*4);
	count=0;
	for(int i=0;i<n;i++){
		if(arr[i]>=num)
			count++;
	}
	if(count>=m)
		cout<<"Yes";
	else
		cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const ll MAX_N = ll(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i,n) for (int i = n; i >=0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

ll n, a[MAX_N], cum[MAX_N]{}, ans = 0, ma, L;

int main() {
    
    cin >> n;
    REP(i,n) cin >> a[i];
    REP(i,n*2){
        cum[i+1] = cum[i] + a[i%n];
    }
    L = cum[n];
    ma = cum[n]/3;
    ll l = 0, r = 0;
    while(l <= n){
        while(n-r+l > 2 && cum[r] - cum[l] < ma){
            r++;
        }
        ll s = cum[r] - cum[l];
        ll k = lower_bound(cum+r,cum+n+l,(L-s)/2+cum[r]) - cum;
        for(int i = -1; i < 1; i++){
            ll tmp = LLINF;
            tmp = min(tmp, s);
            tmp = min(tmp, cum[k+i]-cum[r]);
            tmp = min(tmp, cum[n+l]-cum[k+i]);
            ans = max(ans, tmp);
        }
        l++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int i,num;
  string s,ans;

  cin>>num;
  for(i=0;i<num;i++)
  {
    cin>>s;
    if(s=="Y") {ans="Four";
    break;
    }

    else ans="Three";
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int n; cin >> n;

	mk(arr, n + 1, int);
	for(int i = 0; i < n; ++i)
		cin >> arr[i];

	// sort(arr, arr + n);
	int cnt = 0;
	for(int i = 0; i < n; ++i)
	{
		for(int j = i + 1; j < n; ++j)
		{
			if(arr[i] == arr[j])
				continue;

			for(int k = j + 1; k < n; ++k)
			{
				if((arr[i] == arr[k]) || (arr[j] == arr[k]))
					continue;

				if((arr[i] + arr[j] > arr[k]) && (arr[k] + arr[i] > arr[j]) && (arr[j] + arr[k] > arr[i]))
				{
					// cout << i + 1 << ' ' << j + 1 << ' ' << k + 1 << '\n';
					++cnt;
				}
			}
		}
	}

	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
using namespace std;
int main () {
    int n, k, xx;
    cin >> k >>n;
    size_t i;
    vector <int> v (n);
    int m=0, x1, x2;
    if (n!=0) cin >> x1;
    xx = x1;
    for (i=1; i<n; i++) {
        x2 = x1;
        cin >> x1;
        if (x1 - x2 > m) m=x1-x2;
    }
    if (xx+ k - x1 >m ) m = xx + k -x1;

    cout << k - m;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e5+5;
int sum[maxm];
int d[maxm];//d[i]为前i个数取i/2个的最大值
int a[maxm];
signed main(){
    int n;cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++){
        if(i&1)sum[i]=sum[i-1]+a[i];
        else sum[i]=sum[i-1];
    }
    for(int i=2;i<=n;i++){
        if(i&1)d[i]=max(d[i-2]+a[i],d[i-1]);
        else d[i]=max(d[i-2]+a[i],sum[i-1]);
    }
    cout<<d[n]<<endl;
    return 0;
}


Measured memory_bytes: 8324
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include <bits/stdc++.h>
#define ls now<<1
#define rs now<<1|1
#define res register int
using namespace std;
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0,f=1;char ch=gc();
    while(!isdigit(ch)) {if (ch=='-') f=-1;ch=gc();}
    while(isdigit(ch)) x=x*10+ch-'0',ch=gc();
    return x*f;
}
inline void write(int x)
{
  if (!x)
  {
    puts("0");
    return;
  }
  char ch[20];
  int tot=0;
  for(; x; x/=10) ch[++tot]=x%10+'0';
  for(res i=tot; i>=1; i--) putchar(ch[i]);
  puts("");
}
const int N=5000005;
set<int> s;
int n,k,site[N],q[N],deg[N],tr[N<<2];
int d[N],Next[N*2],to[N*2],tot;
struct Segmentree
{
  inline void pushup(res now)
  {
    tr[now]=min(tr[ls],tr[rs]);
  }
  inline void build(res now,res tot,res r)
  {
    tr[now]=n+1;
    if (tot==r) return;
    res mid=tot+r>>1;
    build(ls,tot,mid);
    build(rs,mid+1,r);
  }
  inline void update(res now,res tot,res r,res x,res y)
  {
    if (tot==r)
    {
      tr[now]=y;
      return;
    }
    int mid=tot+r>>1;
    if (x<=mid) update(ls,tot,mid,x,y);
    else update(rs,mid+1,r,x,y);
    pushup(now);
  }
  inline int find(int now,int tot,int r,int x,int y)
  {
    if (tot==x&&r==y) return tr[now];
    int m=tot+r>>1;
    if (y<=m) return find(ls,tot,m,x,y);
    else if (x>m) return find(ls|1,m+1,r,x,y);
    else
    {
      int a=find(ls,tot,m,x,m),b=find(rs,m+1,r,m+1,y);
      return (a<b)?a:b;
    }
  }
} T;
inline void add(int x,int y)
{
  to[++tot]=y;
  deg[y]++;
  Next[tot]=d[x];
  d[x]=tot;
}
int main()
{
  n=read();
  k=read();
  for(res i=1; i<=n; i++) site[i]=read(),q[site[i]]=i;
  T.build(1,1,n);
  for(res i=n; i>=1; i--)
  {
    int x;
    x=T.find(1,1,n,max(q[i]-k+1,1),q[i]);
    if (x<=n) add(q[i],q[x]);
    x=T.find(1,1,n,q[i],min(q[i]+k-1,n));
    if (x<=n) add(q[i],q[x]);
    T.update(1,1,n,q[i],i);
  }
  for(res i=1; i<=n; i++)
    if (!deg[i])
      s.insert(i);
  for(res i=1; i<=n; i++)
  {
    res x=q[i]=*s.begin();
    s.erase(s.begin());
    for(res i=d[x]; i; i=Next[i]) 
	  if (!(--deg[to[i]])) s.insert(to[i]);
  }
  for(res i=1; i<=n; i++) site[q[i]]=i;
  for(res i=1; i<=n; i++) write(site[i]);
  return 0;
}

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

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

int main() {
	for (int N, M; cin >> N >> M&&N;) {
		vector<int> d(N), v(N);
		vector<int> a(M);
		rep(i, 0, N) {
			cin >> d[i] >> v[i];
			d[i]--;
			chmax(a[d[i]], v[i]);
		}
		int ans = 0;
		rep(i, 0, M) {
			ans += a[i];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;i++)
int main()
{
  int N,a,b,first=1;
  cin>>N;
  vector<int> A(N,0),Edge(N-1,0),Color(N,0);
  rep(i,N-1)
  {
    cin>>a>>Edge.at(i);
    Edge.at(i)--,A.at(Edge.at(i))=a-1;
  }
  rep(i,N-1)
  {
    a=A.at(i+1),b=Color.at(a)+1;
    Color.at(a)=A.at(i+1)=(b==A.at(a)?++b:b);
    first=max(b,first);
  }
  cout<<first<<endl;
  for(int x:Edge)cout<<A.at(x)<<endl;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		long res=1;
		for(int n=s.nextInt();n>1;n--) {
			res*=n;
			res%=1000000007;
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 21332
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

func Solve() {
  var N int
  NextInt(&N)
  var A []int
  NextIntVec(&A)
  B := make([]int, N + 1)
  for _, a := range A {
    B[a]++
  }
  C := make([][]int, 2)
  for i := range C { C[i] = make([]int, N + 1) }
  for i, b := range B {
    C[0][i] = b * (b - 1) / 2
    if 0 < b { C[1][i] = (b - 1) * (b - 2) / 2 }
  }
  S := SumInt(C[0]...)
  D := make([]int, N + 1)
  for i := range D {
    D[i] = S - C[0][i] + C[1][i]
  }
  for _, a := range A {
    Write(D[a])
  }
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

int dp[2020][2020];
signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;

    vector<pair<int, int>> q;
    REP(i, N)
    {
        int tmp;
        cin >> tmp;
        q.emplace_back(make_pair(tmp, i));
    }
    sort(ALL(q));
    reverse(ALL(q));
    int ans = 0;
    REP(i, N)
    {
        for (int l = 0; l <= i; l++)
        {
            int r = i - l;
            dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + q[i].first * abs(q[i].second - l));
            dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + q[i].first * abs(q[i].second - (N - 1 - r)));
            ans = max(ans, dp[l + 1][r]);
            ans = max(ans, dp[l][r + 1]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26332
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m, l;
	int A[101][101] = {};
	int B[101][101] = {};
	ll C[101][101] = {};
	cin >> n >> m >> l;
	REP(i, n) {
		REP(j, m) {
			cin >> A[i][j];
		}
	}
	
	REP(i, m) {
		REP(j, l) {
			cin >> B[i][j];
		}
	}
	
	REP(i, n) {
		REP(j, l) {
			REP(k, m) {
				C[i][j] += (A[i][k] * B[k][j]);
			}
		}
	}
	
	REP(i, n) {
		REP(j, l) {
			cout << C[i][j];
			if(j == l - 1) cout << "\n";
			else cout << " ";
		}
	}
	
	return 0;
}

Measured memory_bytes: 1368
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//



//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s ;
  cin >> s ;
  int cntt = 0 ;
  int cnts = 0 ;
  int n = SZ(s) ;
  int ans = n ;
  
  REP(i,n){
    if(s.at(i)=='S'){
      cnts++ ;
    }
    else{
      cntt++ ;
      if(cnts>0){
        cntt-- ;
        cnts-- ;
        ans -= 2 ;
      }
    }
  }
  cout << ans <<endl ;
      
  
  
  
  return 0 ;
}



Measured memory_bytes: 720
/* kadai6_2
   Saikyo_Kazune
*/
#include <stdio.h>
#include <string.h>

 

 
int main(void){
    //宣言
   int SIZE = 103,length_str;
   char str[SIZE];
   fgets(str,SIZE,stdin);
   //文字列の長さ(null文字直前までの長さを調べる)
   length_str = strlen(str);
   //改行\nの分を削る
   length_str--;
   //先頭、末尾の文字を取る
   char head = str[0];
   char tail = str[length_str-1];
   //答え用の文字列
   char ans[103]={'\0'};
   //先頭、間の文字数、末尾の文字の順で結合する
   snprintf(ans,103,"%c%d%c",head,length_str-2,tail);
   //出力
   printf("%s\n",ans);
   return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  double root = sqrt(M);
  int range = root;

  int ans = 0;
  for(int i=1;i<=range;i++){
    if(M%i == 0){
      if(M/i >= N) ans = max(ans, i);
      if(i >= N) ans = max(ans, M/i);
    }
  }
  cout << ans <<endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn=2*1e3+10;
#define inf 99999999
int dis[maxn][maxn];
int a[maxn];
int k,n;
int main()
{
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
            dis[i][j]=inf;
    for(int i=1;i<n;++i){
        dis[i][i]=0;
        dis[i][i+1]=1;
        dis[i+1][i]=1;
    }
    dis[n][n]=0;
    for(int i=1;i<=n;++i)
        for(int j=i+1;j<=n;++j)
            dis[j][i]=dis[i][j]=j-i;
    dis[x][y]=1;
    if(x>y)
        swap(x,y);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
            dis[i][j]=min(dis[i][j],dis[i][x]+1+dis[y][j]);
    for(int i=1;i<=n;++i)
        for(int j=i+1;j<=n;++j){
            a[dis[i][j]]++;
        }
    //cout<<dis[1][7]<<dis[1][6];
    for(int i=1;i<n;++i)
        printf("%d\n",a[i]);
    return 0;
}


Measured memory_bytes: 16000
#include<stdio.h>
#define MAX 200000
#define S 1000000000
int L[MAX],R[MAX];
long long merge(int A[],int n,int left,int mid,int right){
  int i,j,k;
  long long cnt =0;
  int n1 = mid-left;
  int n2 = right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=R[n2]=S;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j])
      A[k]=L[i++];
    else{
      A[k]=R[j++];
      cnt += n1-i;
    }
  }
  return cnt;
}

long long mergeSort(int A[],int n,int left,int right){
  int mid;
  long long v1,v2,v3;
  if(left+1<right){
    mid=(left+right)/2;
    v1=mergeSort(A,n,left,mid);
    v2=mergeSort(A,n,mid,right);
    v3=merge(A,n,left,mid,right);
    return v1+v2+v3;
  }
  else return 0;
}

int main(){
  int A[MAX],n,i;
  long long ans;
  scanf("%d",&n);;
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  ans=mergeSort(A,n,0,n);
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3268
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}


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

    int cnt = 0;
    rep(i,4){
        if(s[i] == '2') cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 100010
int a[N],b[N],c[N];
int main()
{
    int i,j,k,n,l,r,mid,p1,p2;
    long long s;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
    scanf("%d",&b[i]);
    for(i=1;i<=n;i++)
    scanf("%d",&c[i]);
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    sort(c+1,c+1+n);
    s=0;
    for(i=1;i<=n;i++)
    {
        if(b[i]<=a[1])
        continue;
        if(b[i]>=c[n])
        continue;
        p1=1;
        l=1;
        r=n;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(a[mid]<b[i])
            {
                p1=max(p1,mid);
                l=mid+1;
            }
            else
            r=mid-1;
        }
        p2=n;
        l=1;
        r=n;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(c[mid]>b[i])
            {
                p2=min(p2,mid);
                r=mid-1;
            }
            else
            l=mid+1;
        }
        s=s+(long long)p1*(n-p2+1);
    }
    printf("%lld\n",s);
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
int n,t,mn;
int a,b;
int main(){
    cin>>n>>t;
    mn = 10000;
    for(int i=1;i<=n;i++){
        cin>>a>>b;
        if(b<=t){
            mn = min(mn,a);
        }
    }
    if(mn==10000)cout<<"TLE\n";
    else{cout<<mn<<endl;}


}


Measured memory_bytes: 256