akhauriyash/Code-Regression huggingface dataset:
def resolve():
    r, c, k = map(int, input().split())
    dict = {}
    for i in range(k):
        a,b,z = map(int, input().split())
        a -= 1
        b -= 1
        dict[(a,b)] = z
    now = [[0]*4 for _ in range(c)]
    prev = [0]*c

    if (0,0) in dict:
        now[0][1] = dict[(0,0)]
    for i in range(1, c):
        if (0, i) in dict:
            now[i][0] = now[i-1][0]
            now[i][1] = max(dict[(0,i)]+now[i-1][0] , now[i-1][1])
            if now[i-1][1] != 0:
                now[i][2] = max(dict[(0,i)]+now[i-1][1], now[i-1][2])
            if now[i - 1][2] != 0:
                now[i][3] = max(dict[(0,i)]+now[i-1][2], now[i-1][3])
        else:
            now[i][0] = now[i-1][0]
            now[i][1] = now[i-1][1]
            now[i][2] = now[i-1][2]
            now[i][3] = now[i-1][3]
    for i in range(c):
        prev[i] = max(now[i])
    for i in range(1, r):
        now = [[0] * 4 for _ in range(c)]
        now[0][0] = prev[0]
        if (i, 0) in dict:
            now[0][1] = dict[(i,0)]+now[0][0]

        for j in range(1, c):
            now[j][0] = max(now[j-1][0], prev[j])

            if (i,j) in dict:
                if now[j-1][2] != 0:
                    a3 = now[j-1][2]+dict[(i,j)]
                else:
                    a3 = 0
                if now[j][2] != 0:
                    a4 = now[j][2]+dict[(i,j)]
                else:
                    a4 = 0

                if now[j-1][1] != 0:
                    a1 = now[j-1][1]+dict[(i,j)]
                else:
                    a1 = 0
                if now[j][1] != 0:
                    a2 = now[j][1]+dict[(i,j)]
                else:
                    a2 = 0
                now[j][3] = max(now[j - 1][3], a3, a4)
                now[j][2] = max(now[j-1][2], a1, a2)
                now[j][1] = max(now[j-1][1], now[j-1][0] + dict[(i,j)],now[j][0] + dict[(i,j)])
            else:
                now[j][1] = now[j-1][1]
                now[j][2] = now[j-1][2]
                now[j][3] = now[j-1][3]
        prev = [0]*c

        for j in range(c):
            prev[j] = max(now[j])
    print(prev[-1])
resolve()

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
    int n, ans;

    cin >> n;

	if(n == 100000) {
		ans = 90909;
	} else if (n > 9999) {
		ans = n-9999 + 909;
	} else if (n > 999) {
		ans = 909;
	} else if (n > 99) {
		ans = n-99 + 9;
	} else if (n > 9) {
		ans = 9;
	} else {
		ans = n;
	}
	cout << ans << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(n, a) for(int i = 0; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "Yes" : "No")
#define mod(a, b) (b + (a % b)) % b
#define MOD  (int)1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::pair <ll, ll> pll;
typedef std::vector<pii> vpii;
using namespace std;

 
void solve(){
    int a, b;
    cin >> a >> b;
    string s = "", t = "";
    for(int i = 0; i < a; i++) t += to_string(b);
    for(int i = 0; i < b; i++) s += to_string(a);
    if(s >= t) cout << t;
    else cout << s;
    
}
 
int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}
 


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

int nw[100003][11] , N , M , Q , val[100003];
vector < int > nxt[100003];
struct data{int val , i , j; friend bool operator <(data p , data q){return p.val < q.val;}};
priority_queue < data > q;

int main(){
	cin >> N >> M; for(int i = 1 ; i <= M ; ++i){int x , y; cin >> x >> y; nxt[x].push_back(y); nxt[y].push_back(x);}
	cin >> Q; for(int i = 1 ; i <= Q ; ++i){int v , d , c; cin >> v >> d >> c; val[i] = c; nw[v][d] = i; q.push((data){i , v , d});}
	while(!q.empty()){
		int x = q.top().i , y = q.top().j; q.pop();
		if(y) for(auto t : nxt[x]) if(nw[t][y - 1] < nw[x][y]){nw[t][y - 1] = nw[x][y]; q.push((data){nw[x][y] , t , y - 1});}
	}
	for(int i = 1 ; i <= N ; ++i){
		int ans = 0; for(int j = 0 ; j <= 10 ; ++j) ans = max(ans , nw[i][j]);
		cout << val[ans] << endl;
	}
	return 0;
}


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

int main() {
	int N;
	string s;
	cin >> N >> s;
	int x = 0;
	int high = 0;
	for(int i = 0;i < N;i++){
		if(s.at(i) == 'I'){
			x++;	
		}
		else{
			x--;
		}
		if(high < x){
			high = x;
		}
	}
	cout << high << endl;
}

Measured memory_bytes: 256
nx = []
while True:
    nx.append([int(i) for  i in input().split(" ")])
    if nx[-1] == [0, 0]:
        nx.pop()
        break

for c in range(len(nx)):
    count = 0
    for i in range(1, nx[c][0]+1):
        for j in range(i+1, nx[c][0]+1, 1):
            for k in range(j+1, nx[c][0]+1, 1):
                if i + j + k == nx[c][1]:
                    count += 1
    print(count)



Measured memory_bytes: 5604
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i = 1 ;i<=n ;i++){
    scanf("%hd",&A[i]);
  }
  for(i = 0;i<=VMAX+1;i++){
    C[i] = 0;
  }
  for(j=1;j<=n;j++){
    C[A[j]] = C[A[j]]+1;
  }
  
  for(i = 1 ;i<=VMAX+1;i++){
    C[i] = C[i]+C[i-1];
  }
  for(j=n ;j>=1 ;j--){
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]]-1;
  }
  for(j = 1;j<n+1;j++){
    if(j ==n)
    printf("%d\n",B[j]);
    else printf("%d ",B[j]);
    }
  return 0;
}



Measured memory_bytes: 9636
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  ldouble n;
  cin >> n;
  cout << fixed << setprecision(3) << n*3.1415926535*2 << endl;
  return 0;
}

Measured memory_bytes: 3788
import java.io.*;
import java.util.*;

public class Main {
    static final String YES = "Yes";
    static final String NO = "No";

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        String S;
        S = sc.next();

        final Solver solver = new Solver();
        solver.solve(S);
    }
}

class Solver {
    public void solve(String S) {
        int aCount = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'A') aCount++;
        }

        if (aCount == 0 || aCount == 3) {
            System.out.println("No");
        }
        else {
            System.out.println("Yes");
        }
    }
}



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

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double l  = sqrt(pow(x1 - x2,2) + pow (y1 - y2,2));
    printf("%lf\n", l);
    return 0;
}


Measured memory_bytes: 3184
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n + 10), v2(n + 10);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      v2[j] = 0;
    }
    for (int j = 0; j < n; j++) {
      v2[max(0, j - v[j])]++;
      v2[min(n + 1, j + v[j] + 1)]--;
    }
    for (int j = 0; j < n; j++) {
      if (j) {
        v2[j] += v2[j - 1];
      }
      v[j] = v2[j];
    }
    int flag = 1;
    for (int j = 0; j < n; j++) {
      if (v[j] != n) {
        flag = 0;
      }
    }
    if (flag) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4792
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
typedef pair<int,int> pii;
int MOD = 998244353;

signed main(){

    int x,k;
    cin >> k >> x;

    int mini = max(x-k+1,-1000000LL);
    int maxi = min(x+k-1,1000000LL);
    for(int i = mini; i <= maxi ;i++)cout << i << " ";
    
    
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc137.contest.atcoder.jp/tasks/abc137_b


Measured memory_bytes: 256
# -*- coding: utf-8 -*-       

n = input()
a = map(int, raw_input().split())

m4 = 0
m2 = 0
k = n/2
flg = 1
for i in a:
    if(i%4 == 0):
        m4 += 1
    elif(i%2 == 0):
        m2 += 1
if(m4 >= k):
    print('Yes')
    flg = 0
else:
    if(n%2 == 0):
        if(m2 >= (k-m4)*2):
            print('Yes')
            flg = 0
    else:
        if(m2 >= (k-m4)*2+1):
            print('Yes')
            flg = 0
if(flg):
    print('No')


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

using namespace std;

using ll = int_fast64_t;
constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max()
constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min()
using ull = uint_fast64_t;
constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max()

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    string S;
    cin >> S;
    const int left = (S[0] - '0') * 10 + (S[1] - '0');
    const int right = (S[2] - '0') * 10 + (S[3] - '0');
    if (1 <= left && left <= 12){
        if (1 <= right && right <= 12){
            puts("AMBIGUOUS");
        }else{
            puts("MMYY");
        }
    }else{
        if (1 <= right && right <= 12){
            puts("YYMM");
        }else{
            puts("NA");
        }
    }
}


Measured memory_bytes: 256
# 入力
N = int(input())
hist = list(map(lambda x: int(x), input().split()))
max_num = 0

stack = [(0, -1)] # 高さと位置, 初期値右隅
for i in range(N):
    # 一番左の位置
    base = i
    # stackが空の時
    if len(stack) == 1 or 0:
        stack.append((hist[i], base))  
        
    # stackの末尾より、高さが大きい
    elif stack[-1][0] < hist[i]:
        stack.append((hist[i], base))
        
    # stackの末尾より、高さが大きい
    elif stack[-1][0] > hist[i]:
        while stack and (hist[i] <= stack[-1][0]):
            h, j = stack.pop()
            max_num = max(max_num, h * (i - j))
        stack.append((hist[i], j))

# 残りのスタックで出力
while stack:
    h, j = stack.pop()
    max_num = max(max_num, (N - j) * h)

print(max_num)


Measured memory_bytes: 19668
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "********************************************\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
ll dp[200005][10][2], n, last, fun[10][10];
ll a[200005];
ll pwr(ll b, ll e)
{
	if (e < 0)
		return 1;
	ll ans = 1;
	while (e)
	{
		if (e & 1)
			ans = (ans * b);
		b = (b * b);
		e >>= 1;
	}
	return ans;
}
ll cal(ll idx, ll lv, ll f)
{
	if (idx == n)
		return (lv == last);
	if (dp[idx][lv][f] != -1)
		return dp[idx][lv][f];
	ll lim, ans = 0;
	if (f)
		lim = a[idx];
	else
		lim = 9;
	for (int i = 0; i <= lim; ++i)
	{
		if (f)
		{
			if (i < lim)
				ans += cal(idx + 1, i, 0);
			else
				ans += cal(idx + 1, i, 1);
		}
		else
		{
			ans += cal(idx +  1, i, 0);
		}
	}
	return dp[idx][lv][f] = ans;
}
ll solve()
{
	memset(dp, -1, sizeof(dp));
	return cal(1, a[0], 1);
}
int main(int argc, char const *argv[])
{
	fast;
	string s;
	cin >> s;
	n = s.length();
	for (int i = 0; i < s.length(); ++i)
	{
		a[i] = s[i] - '0';
	}
	if (n == 1)
		cout << s;
	else
	{
		
		for (int i = 1; i <= 9; ++i)
		{
			for (int j = 0; j <= 9; ++j)
			{
				if (i < a[0])
					fun[i][j] = pwr(10, n - 2);
				else if (i == a[0])
				{
					last = j;
					fun[i][j] = solve();
				}
				for (int l = 2; l < n; ++l)
				{
					fun[i][j] += pwr(10, l - 2);
				}
				if (i == j)
					fun[i][j] ++;
			}
		}
		// for (int i = 0; i <= 9; ++i)
		// {
		// 	for (int j = 0; j <= 9; ++j)
		// 	{
		// 		cout << fun[i][j] << ' ';
		// 	}
		// 	cout << '\n';
		// }
		ll ans = 0;
		for (int i = 0; i <= 9; ++i)
		{
			for (int j = 0; j <= 9; ++j)
			{
				ans += fun[i][j] * fun[j][i];
			}
		}
		cout << ans;
	}
	return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
int s;
int main(){
  cin >> s;
  int a=0,t=s;
  while (t>0) {
    a += t%10;
    t /= 10;
  }
  cout << (s%a == 0? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	ll C;
	cin >> N >> C >> K;
	vl T(N);
	for (i = 0; i < N; i++) cin >> T[i];
	sort(T.begin(), T.end());
	ll count = 1;
	ll begin = T[0];
	for (i = 1; i < N; i++) {
		if (count < C && T[i] <= begin + K) {
			count++;
		}
		else {
			ans++;
			begin = T[i];
			count = 1;
		}
	}
	ans++;
	cout << ans;
}

Measured memory_bytes: 1024
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2881
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;

int comv(string s)
{
    int res = 0;
    int t = 1;
    for (int i = 0; i < s.size(); ++i)
    {
        switch (s[i])
        {
        case 'm':
            t *= 1000;
            res += t;
            t = 1;
            break;
        case 'c':
            t *= 100;
            res += t;
            t = 1;
            break;
        case 'x':
            t *= 10;
            res += t;
            t = 1;
            break;
        case 'i':
            t *= 1;
            res += t;
            t = 1;
            break;
        default:
            break;
        }
        if (s[i] >= '2' && s[i] <= '9')
        {
            t = s[i] - '0';
        }
    }
    return res;
}

string comb(int n)
{
    string s = "";

    int t = 0;
    while (n)
    {
        t++;
        if (n % 10 != 0)
        {
            switch (t)
            {
            case 1:
                s.push_back('i');
                break;
            case 2:
                s.push_back('x');
                break;
            case 3:
                s.push_back('c');
                break;
            case 4:
                s.push_back('m');
                break;
            default:
                break;
            }
            if (n % 10 != 1)
                s.push_back((char)'0' + n % 10);
        }
        n /= 10;
    }
    reverse(s.begin(), s.end());
    return s;
}
int main(void)
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        string s, t;
        cin >> s >> t;

        int n = comv(s);
        int m = comv(t);

        int sum = n + m;
        cout << comb(sum) << endl;
    }
    return 0;
}


Measured memory_bytes: 3196
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let h: usize = sc.read();
    let w: usize = sc.read();

    let mut count = vec![0; 26];
    for i in 0..h {
        let s: String = sc.read();
        for c in s.chars() {
            let c = c as usize - 'a' as usize;
            count[c] += 1;
        }
    }

    let mut one = 0;
    let mut two = 0;
    for count in count.into_iter() {
        match count % 4 {
            1 => {
                one += 1;
            }
            2 => {
                two += 1;
            }
            3 => {
                one += 1;
                two += 1;
            }
            _ => {}
        }
    }

    let mut allow_one = 0;
    if h % 2 == 1 && w % 2 == 1 {
        allow_one += 1;
    }
    if allow_one < one {
        println!("No");
        return;
    }

    let mut allow_two = 0;
    if h % 2 == 1 {
        allow_two += w / 2;
    }
    if w % 2 == 1 {
        allow_two += h / 2;
    }
    if allow_two < two {
        println!("No");
        return;
    }
    println!("Yes");
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

template <typename T>
struct FenwickTree {
    int n;
    vector<T> data;

    FenwickTree(int n) : n(n), data(n+1) {}

    T sum(int i) {
        T ret = 0;
        for (i++; i > 0; i -= i & -i) ret += data[i];
        return ret;
    }

    void add(int i, T x) {
        for (i++; i <= n; i += i & -i) data[i] += x;
    }

    int lower_bound(T x) {
        if (x <= 0) return 0;
        int k = 1;
        while (k * 2 <= n) k *= 2;
        int j = 0;
        for (; k > 0; k /= 2) {
            if (j + k <= n && data[j+k] < x) {
                x -= data[j+k];
                j += k;
            }
        }
        return j;
    }
};

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

    int N, Q;
    cin >> N >> Q;
    FenwickTree<ll> ft(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        ft.add(i, a);
    }
    for (int i = 0; i < Q; i++) {
        int t;
        cin >> t;
        if (t == 0) {
            int p, x;
            cin >> p >> x;
            ft.add(p, x);
        } else {
            int l, r;
            cin >> l >> r;
            cout << ft.sum(r - 1) - ft.sum(l - 1) << "\n";
        }
    }
}

Measured memory_bytes: 8260
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (void)
{
	int build[4][3][10];
	for(int i = 0 ; i < 4 ; i++)
	{
		for(int j = 0 ; j < 3 ; j++)
		{
			for(int k = 0 ; k < 10 ; k++)
			{
				build[i][j][k] = 0;
				//printf("build[%d][%d][%d] = %d\n" , i , j , k , build[i][j][k]);
			}
		}
	}
	int n = 0;
	scanf("%d" , &n);
	while(n--)
	{
		int a , b , c , d;
		scanf("%d %d %d %d" , &a , &b , &c , &d);
		build[a-1][b-1][c-1] += d;
	}
	for(int i = 0 ; i < 4 ; i++)
	{
		for(int j = 0 ; j < 3 ;j++)
		{
			for(int k = 0 ; k < 10 ; k++)
			{
				printf(" %d" , build[i][j][k]);
			}
			printf("\n");
		}
		if(i != 3)
		{
			printf("####################\n");
		}
	}
}


Measured memory_bytes: 2092
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
int main()
{
    lint a, b, x;
    cin >> a >> b >> x;
    lint ans;
    if (a != 0)
    {
         ans = b / x - (a - 1) / x;
    }
    else
    {
         ans = b / x + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ok = True
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 != 0 and a[i] % 5 != 0:
            ok = False
if ok: print('APPROVED')
else: print('DENIED')

Measured memory_bytes: 61872
#include"bits/stdc++.h"
using namespace std;

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
    ll res=1;
    while(b)
    {
        if(b&1LL)
            res=(res*a)%c;
        a=(a*a)%c;
        b>>=1;
    }
    return res;
}

int main()
{
    FASTIO;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n;
     cin>>n;

    vector<ll>a(n);
    vector<ll>b(n);

    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];

    vector<ll>vect;
    for(int i=0;i<n;i++)
        vect.push_back(i+1);
    ll fi=0,sec=0;
    int index=0;
    do
    {   
        ++index;
        if(vect==a)
        {   
            fi=index;
        }
        if(vect==b)
        {
            sec=index;
        }

        if(fi!=0 and sec!=0)
            break;

    }while(next_permutation(vect.begin(),vect.end()));

    //error(fi);
    //error(sec);
    cout<<abs(fi-sec)<<"\n";


    return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
      	int N = sc.nextInt();
      
      	switch(N%10){
          case 2:
          case 4:
          case 5:
          case 7:
          case 9:
            System.out.println("hon");
            break;
          
          case 0:
          case 1:
          case 6:
          case 8:
            System.out.println("pon");
            break;
            
          case 3:
            System.out.println("bon");
            break;  
      		
        }
	}
}

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

int main(){
  int a,b,t;
  cin >> a >> b >>t;
  cout << t/a*b << endl;
}

// cout << fixed << setprecision(15) <<  << endl;


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
template<class T> inline void chmax(T &a,T b){if(a<b)a=b;}
template<class T> inline void chmin(T &a,T b){if(a>b)a=b;}

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s; cin >> s;
    if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3])) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;



int main(void){
	int N,D,X,A[110];
	scanf("%d%d%d",&N,&D,&X);
	rep(i,N)scanf("%d",&A[i]);
	rep(i,N)X+=(D-1)/A[i]+1;
	printf("%d\n",X);
	return 0;
}

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

int main(){
  int N,i;
  cin >> N;
  vector<int> students(N);
  vector<int> toukou(N);

  for(i=0;i<N;i++)
  cin >> students.at(i);
  for(i=0;i<N;i++)
  toukou.at(students.at(i)-1) = i+1;
  for(i=0;i<N;i++)
  cout << toukou.at(i) << " ";
}

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

long dp[110][100010];
int main() {
	int N, W, w[110], v[110];
	cin >> N >> W;
	for(int i=1; i<=N; ++i) cin >> w[i] >> v[i];
	for(int i=1; i<100010; ++i) dp[0][i]=-1;
	for(int i=1; i<=N; ++i){
	    for(int j=1; j<100010; ++j){
	        if(dp[i-1][j]>0) dp[i][j]=dp[i-1][j];
	        if(v[i]<=j){
	            if(dp[i-1][j-v[i]]>=0){
	                if(dp[i][j]>0) dp[i][j]=min(dp[i][j], dp[i-1][j-v[i]]+w[i]);
	                else dp[i][j]=dp[i-1][j-v[i]]+w[i];
	            }
	        }
	        if(dp[i][j]==0) dp[i][j]=-1;
	    }
	}
	for(int ans=100005; ans>=0; --ans){
	    if(dp[N][ans]>0 && dp[N][ans]<=W){
	        cout << ans << endl;
	        return 0;
	    }
	}
	return 0;
}


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

const int MAXN = 3002;

double dp[MAXN][MAXN],P[MAXN];
int vis[MAXN][MAXN],N;

double solve(int pos,int heads){
	
	if(heads < 0) return 0.0;

	if(pos == 0){
		return (heads == 0);
	}

	if(vis[pos][heads]) return dp[pos][heads];
	vis[pos][heads] = 1;

	return dp[pos][heads] =  (P[pos])*solve(pos-1,heads-1) + (1.0 - P[pos])*solve(pos-1,heads);

}

int main(){

	cin >> N;
	for(int i = 1;i<=N;i++){
		cin >> P[i];
	}

	double tot = 0;
	for(int heads = 0;heads<=N;heads++){
		int tails = N - heads;
		if(heads > tails) tot += solve(N,heads);
	}

	printf("%.9lf\n",tot);

	return 0;

}

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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(long long X, long long K, long long D) {
    __int128_t x = abs(X);
    __int128_t k = K;
    __int128_t d = D;
    __int128_t n = x / d;
    __int128_t ans = x;

    if (k < n) {
        ans = x - k * D;
        k = 0;
    } else {
        ans = x - n * D;
        k -= n;
    }
    k %= 2;
    if (0 < k) {
        __int128_t tmp = ans - D;
        if (tmp < 0) tmp *= -1;
        ans = tmp;
    }
    cout << (long long)ans << endl;
}

int main() {
    long long X;
    scanf("%lld", &X);
    long long K;
    scanf("%lld", &K);
    long long D;
    scanf("%lld", &D);
    solve(X, K, D);
    return 0;
}


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

int main(){
  int x,i,n;

  cin>>n;
  for(int i=1;i<=n;i++){
    if(i%3==0) cout<<" "<<i;
    else if(i%10==3) cout<<" "<<i;
    else if((i/10)%10==3||(i/100)%10==3||(i/1000)%10==3) cout<<" "<<i;
  }
  cout<<endl;
}


Measured memory_bytes: 1168
#include<cstdio>
#include<algorithm>
using namespace std;
int dp[101][4][4],box[101]={0};
int main(void)
{
	int n,K,a,b,sum,l,i,j,k;
	scanf("%d %d",&n,&K);
	for(i=0;i<K;i++){
		scanf("%d %d",&a,&b);
		box[a]=b;
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			for(k=1;k<=3;k++){
				dp[i][j][k]=0;
			}
		}
	}
	for(i=1;i<=3;i++){
		if(box[1]==0||box[1]==i){
			dp[1][i][1]=1;
		}
	}
	for(i=1;i<=3;i++){
		if(box[2]==0||box[2]==i){
			for(j=1;j<=3;j++){
				dp[2][i][j]=dp[1][j][1];
			}
		}
	}
	for(i=3;i<=n;i++){
		for(j=1;j<=3;j++){
			if(box[i]==0||box[i]==j){
				for(k=1;k<=3;k++){
					for(l=1;l<=3;l++){
						if(!(j==k&&j==l)){
							dp[i][j][k]+=dp[i-1][k][l];
						}
					}
					dp[i][j][k]%=10000;
				}
			}
		}
	}
	sum=0;
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++){
			sum+=dp[n][i][j];
		}
	}
	sum%=10000;
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 2688
a=input()
if a[0] is not a[2] or a[0] is not a[3]:
    if a[0] == a[1] and a[2] == a[3]:
        print('Yes')
    elif a[0] == a[3] and a[2] == a[1]:
        print('Yes')    
    elif a[0] == a[2] and a[3] == a[1]:
        print('Yes')
    else:
        print('No')
 
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
    
#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;

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

int32_t main(){
    int n;
    cin >> n;
    vector<int> v(3, 0);
    REP(i, n){
        int a;
        cin >> a;

        if(a%4==0){
            v[2]++;
        }
        else if(a%2==0){
            v[1]++;
        }
        else{
            v[0]++;
        }
    }
    
    if(v[2]<v[0]-1){
        cout << "No" << endl;
        return 0;
    }

    if(v[2]==v[0]-1 && v[1]!=0){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;

int N,A,x[51];

int main() {
  cin >> N >> A;
  rep(i,N) cin >> x[i];
  ll sum = 0;
  rep(_,N) {
    ll d = _ + 1;
    ll MAX = 50 * d + 1;
    vector<vector<ll> > dp(d+1,vector<ll>(MAX,0));
    dp[0][0] = 1;
    rep(i,N) {
      for(int j=d-1;j>=0;--j) {
	rep(k,MAX) {
	  if( dp[j][k] == 0 ) continue;
	  if( j + 1 <= d && k + x[i] <= d * A ) {
	    dp[j+1][k+x[i]] += dp[j][k];
	  }
	}
      }
    }
    sum += dp[d][d*A];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1232
#include<iostream>
#include<algorithm>
using namespace std;
int N,M;
long K,A[2<<17],B[2<<17];
main()
{
	cin>>N>>M>>K;
	long S=0;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		S+=A[i];
	}
	for(int i=0;i<M;i++)cin>>B[i];
	int ans=0;
	int j=0;
	for(int i=N;i>=0;i--)
	{
		if(i<N)S-=A[i];
		while(j<M&&S+B[j]<=K)
		{
			S+=B[j++];
		}
		if(S<=K)ans=max(ans,j+i);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char * argv[]) {
    int N;
    cin >> N;
    vector<pair<int, int>> X(N);
    for (auto & x : X)
        cin >> x.first >> x.second;

    std::sort(X.begin(), X.end(), [](auto a, auto b){
        return a.second < b.second;
    });

    int64_t used = 0;
    bool can = true;
    for (int i = 0; i < N; ++i) {
        used += X[i].first;
        if (used > X[i].second) {
            can = false;
        }
    }

    cout << (can ? "Yes" : "No") << endl;

    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);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if(m == 0) {
            System.out.println("0 0");
            return;
        }
        String[][] p = new String[m][2];
        for(int i=0; i<m; i++) {
            p[i][0] = sc.next();
            p[i][1] = sc.next();
        }
        boolean[] acA = new boolean[n+1];
        int [] waA = new int[n+1];
        int wa = 0;
        int ac = 0;
        for(int i=0; i<m; i++) {
            int a = Integer.parseInt(p[i][0]);
            if(acA[a]) continue;
            if("WA".equals(p[i][1])) {
                waA[a]++;
            }else {
                ac++;
                wa += waA[a];
                acA[a] = true;
            }
        }
        System.out.println(ac + " " + wa);
    }
}

Measured memory_bytes: 71188
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int a;
    cin >> a;
    if(a == 1) cout << "Hello World";
    else{
        int m, s;
        cin >> m >> s;
        cout << m + s;
    }
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int n;
vector<pair<int,int>> T[100000];

lint dist[100000];

void dfs(int u,int p=-1,lint d=0){
	dist[u]=d;
	for(auto e:T[u]){
		int v=e.first,c=e.second;
		if(v!=p) dfs(v,u,d+c);
	}
}

int main(){
	cin>>n;
	rep(i,n-1){
		int u,v,c; cin>>u>>v>>c; u--; v--;
		T[u].emplace_back(v,c);
		T[v].emplace_back(u,c);
	}

	int q,k; cin>>q>>k; k--;

	dfs(k);

	rep(_,q){
		int x,y; cin>>x>>y; x--; y--;
		cout<<dist[x]+dist[y]<<endl;
	}

	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1e9+7;
using namespace std;
using ll = long long;

int main() {
	ll n, ans = 0;
	cin >> n;
	vector<ll> a(n), b(n), c(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end());
	rep(i,n) cin >> b[i];
	sort(b.begin(), b.end());
	rep(i,n) cin >> c[i];
	sort(c.begin(), c.end());

	for (int i = 0; i < n; i++) {
		ll L = -1 , R = n;

		while (abs(L - R) > 1) {
			int mid = (L + R) / 2;
			if (a[mid] < b[i]) L = mid;
			else R = mid;
		}
		ll down = L;

		L = -1; R = n;

		while (abs(L - R) > 1) {
			int mid = (L + R) / 2;
			if (c[mid] > b[i]) R = mid;
			else L = mid;
		}
		ll up = R;
		ans += (down + 1) * (n - up);
	}
	cout << ans << endl;
	return 0;
}

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

#define M 1000001
#define L 14

char g_H[M][L];

int getChar(char);
long long getKey(char str[]);
int h1(int);
int h2(int);
int find(char str[]);
int insert(char str[]);

int main(){
  int i,n;
  char str[L],com[9];
  for(i = 0; i < M; i++) g_H[i][0] = '\0';

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%s %s",com,str);

    if(com[0] == 'i') insert(str);
    else{
      if(find(str)) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}

int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;

  for(i = 0; i < strlen(str); i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return key % M;
}

int h2(int key){
  return 1 + (key % (M - 1));
}

int find(char str[]){
  long long key, i, h;

  key = getKey(str);
  for(i = 0;; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(g_H[h], str) == 0) return 1;
    else if(strlen(g_H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;

  key = getKey(str);
  for(i = 0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(g_H[h], str) == 0) return 1;
    else if(strlen(g_H[h]) == 0){
      strcpy(g_H[h], str);
      return 0;
    }
  }
  return 0;
}



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

int main()
{
	int n;
	cin>>n;
	int k;
	int ans=0;
	int st=1;
	for(int i=0;i<n;i++)
	{
		cin>>k;
		if(k==st)
		{
			st++;
		}
		else
		{
			ans++;
		}
	}
	if(ans==n)
		cout<<"-1"<<"\n";
	else
		cout<<ans<<"\n";
}

Measured memory_bytes: 256
#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 all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string x;
   cin >> x;
   stack<char> st;
   st.push(x[0]);
   for (int i = 1; i < x.size(); i++) {
      if (st.size() != 0 && st.top() == 'S' && x[i] == 'T') {
         st.pop();
      } else {
         st.push(x[i]);
      }
   }
   int ans = st.size();
   cout << ans << endl;
   return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef pair<int,int> pii;
const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n,m,w,t;
    cin >> n >> m >> w >> t;
    map<string,int> mp;
    vector<int> v(m),p(m),l(n),x(n),y(n);
    vector<vector<string>> r(n);
    vector<vector<int>> q(n);
    rep(i,0,m){
        string s;
        cin >> s >> v[i] >> p[i];
        mp[s]=i;
    }
    rep(i,0,n){
        cin >> l[i] >> x[i] >> y[i];
        r[i].resize(l[i]);
        q[i].resize(l[i]);
        rep(j,0,l[i]) cin >> r[i][j] >> q[i][j];
    }

    vector<int> dist((1<<n)-1);
    vector<vector<int>> vis((1<<n)-1);
    rep(i,1,1<<n){
        bitset<7> bs(i);
        vector<int> perm,min_perm;
        rep(j,0,n) if(bs[j]) perm.push_back(j);
        dist[i-1]=inf;
        do{
            int d=0,prev_x=0,prev_y=0;
            for(int pos:perm){
                d+=abs(x[pos]-prev_x)+abs(y[pos]-prev_y);
                prev_x=x[pos];
                prev_y=y[pos];
            }
            d+=abs(prev_x)+abs(prev_y);
            if(dist[i-1]>d){
                dist[i-1]=d;
                min_perm=perm;
            }
            vis[i-1]=min_perm;
        }while(next_permutation(perm.begin(),perm.end()));
    }

    vector<int64_t> dp1((1<<n)-1);
    rep(k,0,(1<<n)-1){
        vector<int> dp(w+1);
        for(int pos:vis[k]){
            rep(i,0,l[pos]){
                int idx=mp[r[pos][i]];
                int weight=v[idx],diff=p[idx]-q[pos][i];
                if(diff<=0) continue;
                rep(j,0,w+1){
                    if(j-weight<0) continue;
                    dp[j]=max(dp[j],dp[j-weight]+diff);
                }
            }
        }
        dp1[k]=dp[w];
    }

    vector<int64_t> dp2(t+1);
    rep(i,0,t+1){
        rep(j,0,(1<<n)-1){
            int i_=i+dist[j];
            if(i_>t) continue;
            dp2[i_]=max(dp2[i_],dp2[i]+dp1[j]);
        }
    }
    cout << dp2[t] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3336
import sys
sys.setrecursionlimit(10**5+1)

N,M = map(int,input().split())
nodes = [[] for _ in range(N)]

for _ in range(M):
  x,y = map(int,input().split())
  nodes[x-1].append(y-1)
  
dp = [-1]*N

def judge(index):
  if dp[index] != -1:
    return dp[index]
  else:
    edges = 0
    for i in nodes[index]:
      edges = max(edges, 1+judge(i))
    dp[index] = edges
    return edges

answer = 0
for i in range(N):
  answer = max(answer, judge(i))
print(answer)

Measured memory_bytes: 63616
//Volume2-0222
import java.util.Scanner;

class Main {

    //declare
    private static final int       MAX = 10000001;
    private static       boolean[] prm = new boolean[MAX];
    private static       int    [] twn = new int    [MAX];

    public static void main(String[] arg){

        initialize();

        //input
        Scanner sc = new Scanner(System.in);
        int n;
        while((n = sc.nextInt()) != 0){

            //output
            System.out.println(twn[n]);
        }
    }

    private static void initialize(){

        //Creation of a prime number table.
        for(int i=0;i<MAX;i++){prm[i] = true;}
        prm[0] = false;
        prm[1] = false;
        for(int i=4;i<MAX;i+=2){prm[i] = false;}
        for(int i=3;i<MAX;i+=2){
            if(!prm[i]){continue;}
            for(int k=i*2;k<MAX;k+=i){
                prm[k] = false;
            }
        }

        //The table of a quadruplets prime number is created.
        int twin = -1;
        for(int i=13;i<MAX;i++){
            if(prm[i] && prm[i-2] && prm[i-6] && prm[i-8]){
                twin = i;
            }
            twn[i] = twin;
        }
    }
}

Measured memory_bytes: 75280
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007 //1000000000000000003
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct edge{ll to, cost;}; //edgeパラメータ
typedef pair<ll,ll> P;
struct graph{
  ll N; //ノードの個数
  vector<vector<edge> > G; //G[辺の元]((.to辺の先,.costコスト),...)
  vector<ll> d; // dist[n] = ノードnまでのの重み
  vector<ll> parent;

  graph(ll n){ //グラフ生成時
    N = n;
    G.resize(N); //Edge情報
    d.resize(N); //Node情報,ans
    parent.resize(N);
    rep(i,N){d[i] = INF;}
  }

  void add_edge(ll s, ll t, ll cost){
    G[s].emplace_back((edge){t, cost});
  }

  ll dijkstra(ll s, ll goal){
    rep(i,N){d[i] = INF;}
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que; //ansが小さい順に出る
    que.push(P(0,s)); // P < ans , Node >
    while(!que.empty()){
      P p = que.top(); que.pop(); //pに <ans,Node> 入れる
      ll v = p.second; //vに Node 入れる
      if(d[v] < p.first) continue; //すでに良い数値が入っているならパス
      rep(i,G[v].size()){
        edge& E = G[v][i];
        if(d[E.to] > d[v] + E.cost){ //更新するなら
          d[E.to] = d[v]+ E.cost;
          parent[E.to] = v; //親を記録,goalから遡れば道順
          que.push(P(d[E.to], E.to));
        }
      }
    }
    return d[goal];
  }
};

void Main(){

  int N;

  cin>>N;

  vector<tuple<int,int,int>> tp;

  rep(i,N){
    rep(j,N){
      int a; cin>>a;
      if(i==j or i>j) continue;
      tp.emplace_back(a,i,j);
    }
  }

  SORT(tp);

  graph g(N);
  ll ans=0;

  for(auto& x:tp){
    int x0=get<0>(x);
    int x1=get<1>(x);
    int x2=get<2>(x);

    ll dist=g.dijkstra(x1,x2);
    if(x0==dist) continue;
    if(x0>dist){
      cout<< -1 <<"\n";
      return;
    }
    else{
      g.add_edge(x1,x2,x0);
      g.add_edge(x2,x1,x0);
      ans+=x0;
    }
  }

  cout<< ans<<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

int main () {
  int n;
  cin >>n;
  vector<int>a(n);
  for (int i=0;i<n;i++){
    cin >>a[i];
  }
  sort(a.begin(),a.end());
  cout <<a[a.size()-1]-a[0]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	string s;
	cin >> s;
	string dream = "dream", dreamer = "dreamer", erase = "erase", eraser = "eraser";
	int index = (int)s.size();
	bool flag = 0;
	while (index != 0 and !flag){
		int i = (int)dream.size();
		if (index >= i){
			if (s.substr(index-i, i) == dream){
				index -= i;
				continue;
			}
		}
		i = (int)dreamer.size();
		if (index >= i){
			if (s.substr(index-i, i) == dreamer){
				index -= i;
				continue;
			}
		}
		i = (int)erase.size();
		if (index >= i){
			if (s.substr(index-i, i) == erase){
				index -= i;
				continue;
			}
		}
		i = (int)eraser.size();
		if (index >= i){
			if (s.substr(index-i, i) == eraser){
				index -= i;
				continue;
			}
		}

		flag = 1;
	}

	if (flag) cout << "NO" << endl;
	else cout << "YES" << endl;
}


Measured memory_bytes: 512