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

#define pb push_back
#define Inv(x) ((ll)fac[x - 1] * inv[x] % mod) 

using namespace std;

typedef long long ll;

const int mod = 924844033, N = 8e5 + 10;
int a[N], b[N], rev[N];
int n, cnt[N], size[N];
int fac[N], inv[N];
vector<int> G[N];

int C(int n, int m) {
	if(n < m) return 0;
	return (ll)fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int qpow(int a, int x) {
	int ret = 1;
	while(x) {
		if(x & 1) ret = (ll)ret * a % mod;
		x >>= 1, a = (ll)a * a % mod;
	}
	return ret;
}

void dfs(int x) {
	size[x] = 1;
	for(auto v : G[x])
		if(!size[v]) {
			dfs(v);
			size[x] += size[v];
		}
	if(size[x] - n)
		++ cnt[size[x]], ++ cnt[n - size[x]];
}

void NTT(int n, int *a, int fh) {
	for(int i = 0; i < n; ++ i)
		if(i < rev[i]) 
			swap(a[i], a[rev[i]]);
	for(int limit = 2; limit <= n; limit <<= 1) {
		int Wn = qpow(fh == 1 ? 5 : Inv(5), (mod - 1) / limit), W = 1;
		for(int j = 0; j < n; j += limit, W = 1)
			for(int i = j; i < j + (limit >> 1); ++ i, W = (ll)W * Wn % mod) {
				int a1 = a[i], a2 = (ll)a[i + (limit >> 1)] * W % mod;
				a[i] = (a1 + a2) % mod, a[i + (limit >> 1)] = (a1 - a2 + mod) % mod;
			}
	}
	if(fh == -1) 
		for(int i = 0; i < n; ++ i)
			a[i] = ll(a[i]) * Inv(n) % mod;
}

int main() {
//	freopen("AGC005F.in", "r", stdin);
//	freopen("AGC005F.out", "w", stdout);
	int x, y, limit = 1, k = 0;
	scanf("%d", &n);
	fac[0] = inv[0] = 1;
	for(int i = 1; i <= N - 5; ++ i) 
		fac[i] = (ll)fac[i - 1] * i % mod;
	inv[N - 5] = qpow(fac[N - 5], mod - 2);
	for(int i = N - 5; i >= 1; -- i) 
		inv[i - 1] = (ll)inv[i] * i % mod;
	for(int i = 1; i <= n; ++ i) {
		scanf("%d%d", &x, &y);
		G[x].pb(y), G[y].pb(x);	
	}
	dfs(1);
	for(int i = 0; i <= n; ++ i) 
		a[i] = (ll)cnt[i] * fac[i] % mod;
	for(int i = 0; i <= n; ++ i)
		b[i] = inv[i];
	reverse(b, b + n + 1);
	while(limit <= (n << 1)) 
		limit <<= 1, ++ k;
	for(int i = 0; i < limit; ++ i)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (k - 1));
	NTT(limit, a, 1), NTT(limit, b, 1);
	for(int i = 0; i < limit; ++ i)
		a[i] = (ll)a[i] * b[i] % mod;
	NTT(limit, a, -1);
	//for(int i = 0; i < limit; ++ i)
	//	printf("%d ", a[i]);
	for(int i = (n << 1) - 1; i >= n; -- i) {
		int k = (n << 1) - i;
		printf("%d ", (((ll)n * C(n, k) - (ll)a[k + n] * inv[k]) % mod + mod) % mod);
	}
	return 0;
}


Measured memory_bytes: 55936
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			int n = sc.nextInt();
			int p = sc.nextInt();
			if(n==0 || p==0) {
				break;
			}
			
			int[] point = new int[n];
			int target = 0;
			int bowl = p;
			int cnt = 0;
			
			for(;;) {
				if(bowl != 0) {
					point[target] ++;
					bowl --;
				} else {
					bowl = point[target];
					point[target] = 0;
				}
				
				if(point[target] == p) {
					break;
				} else {
					if(target == n-1) {
						target = 0;
					} else {
						target ++;
					}
				}
			}
			System.out.println(target);
		}
		
		
	}
}

Measured memory_bytes: 26832
#include <bits/stdc++.h>
 
using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
 
template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }
 
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
 
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}
 
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif
 
const int MAX = 100010;
int n;
vector<int> d[MAX];
// PII dfs(int v,int par){
//   PII res = {SZ(d[v]) == 1,0};
//   for(int el:d[v])if(el!=par){
//     PII pom = dfs(el,v);
//     res.SE = min(res.SE + pom.FI, pom.SE + res.FI);
//     res.FI += pom.FI;
//   }
//   return res;
// }
int il[MAX];
void dfs(int v, int par){
  debug(v,par);
  for(int el:d[v])if(el!=par){
    if(SZ(d[el]) != 2){
      il[el]++;
      return;
    }else{
      dfs(el,v);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  R(i,n-1){
    int a,b;
    cin >> a >> b;
    d[a].PB(b);
    d[b].PB(a);
  }
  R(i,n){
    if(SZ(d[i]) == 1){
      dfs(i,-1);
    }
  }
  
  int res = 0;
  R(i,n){
    res += max(0ll,il[i]-1);
  }
  cout << max(res,1ll) << "\n";
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second

using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;

    n = n*(n-1)/2;
    m = m*(m-1)/2;

    cout<<n+m;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
const int MOD = 1000000007;
const int INF = 1001001001;
const ll LINF = 9223372036854775807;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    struct Edge {
        int from, to;
        ll cost;
        Edge (int from_, int to_, ll cost_) {
            from = from_;
            to = to_;
            cost = cost_;
        }
    };
    int from, to;
    ll cost;
    vector<Edge> e;
    rep(i,m) {
        cin >> from >> to >> cost;
        from--; to--;
        e.emplace_back(from, to, -cost);
    }

    vector<ll> dp(n,LINF);
    int s = 0;
    dp[s] = 0;

    rep(i,n+n) {
        rep(j,m) {
            if (dp[e[j].from] == LINF) continue;
            else if (dp[e[j].to] > dp[e[j].from] + e[j].cost) {
                if (e[j].to == n-1 && i > n-1) {
                    cout << "inf" << endl;
                    return 0;
                }
                dp[e[j].to] = dp[e[j].from] + e[j].cost;
            }
        }
    }
    
    cout << -dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define ll long long int
#define si(x)    scanf("%d",&x)
#define sl(x)    scanf("%lld",&x)
#define ss(s)    scanf("%s",s)
#define pi(x)    printf("%d\n",x)
#define pl(x)    printf("%lld\n",x)
#define ps(s)    printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>    pii;
typedef pair<ll, ll>    pl;
typedef vector<int>        vi;
typedef vector<ll>        vl;
typedef vector<pii>        vpii;
typedef vector<pl>        vpl;
typedef vector<vi>        vvi;
typedef vector<vl>        vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
const int mod = 1000000007;
//=======================

int arr[100005], n;
int dp[100005];

int frog(int i)
{
    if(i == n-1)
        return 0;

    if(dp[i] != -1)
        return dp[i];

    int left = abs(arr[i] - arr[i+1]) + frog(i+1);

    int right = INT_MAX;
    // taking right first as INT_MAX so that it won't affect the minimum value 
    // when we return the min of (left, right);
    // checking the condition so that i don't go out of bound.

    if(i+2 < n)
    {
         right = abs(arr[i] - arr[i + 2]) + frog(i+2);
    }

    return dp[i] = min(left, right); 
}
void solve() {
     cin>>n;

     memset(dp, -1 , sizeof(dp));

     rep(i, 0, n)
     cin>>arr[i];

     cout<<frog(0)<<endl;


}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    solve();

    return 0;
}


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

long long L;
int N;
vector<long long> X;

long long Dist(int Left, int Right) {
	if (Left <= Right) {
		return X[Right] - X[Left];
	}
	else {
		return X[Right] + L - X[Left];
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> L >> N;
	X.resize(N + 2);
	X[0] = 0, X[N + 1] = L;
	for (int i = 1; i <= N; i++) cin >> X[i];
	long long NOW = 0, MAX = 0;
	int LP = 0, RP = N, LM = N, RM = N;
	for (int i = 0; i < N * 2; i++) {
		NOW += Dist(LP, RP);
		NOW -= Dist(LM, RM);
		if (i % 2 == 0) LP == 0 ? LP = N : LP--;
		RP == 0 ? RP = N : RP--;
		LM == 0 ? LM = N : LM--;
		if (i % 2 == 1) RM == 0 ? RM = N : RM--;
		if (MAX < NOW) MAX = NOW;
	}
	cout << MAX << endl;
}

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

#define mp make_pair
typedef pair<int,int> pii;
vector<int> vec[111111];
int id[111111];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int n,k;

int main()
{
	scanf("%d",&n);
	memset(id,-1,sizeof id);
	int x,y;
	for(int i=0;i<n-1;i++)
		scanf("%d %d",&x,&y),x--,y--,vec[x].push_back(y),vec[y].push_back(x);
	scanf("%d",&k);
	int v,p;
	for(int i=0;i<k;i++)
		scanf("%d %d",&v,&p),v--,id[v]=p,pq.push(mp(p,v));
	while(!pq.empty())
	{
		int tp=pq.top().second;pq.pop();
		for(int i=0;i<vec[tp].size();i++)
		{
			int to=vec[tp][i];
			if(id[to]==-1)
			{
				id[to]=id[tp]+1;
				pq.push(mp(id[to],to));
			}
			else if(abs(id[to]-id[tp])!=1)
			{
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	for(int i=0;i<n;i++)
		printf("%d\n",id[i]);
	return 0;
}

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

const int MOD=(int)1e9+7;
const int MAX=1000100;
long long fac[MAX],finv[MAX],inv[MAX];
//テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
//二項係数の計算
long long COM(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0)  return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  COMinit();
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);
  
  vector<int> count_ma(1e6+1,0);
  for(int i=0;i<N;i++){
    int a=A.at(i);
    for(int j=2;j*j<=a;j++){
      int count=0;
      while(a%j==0){
        a/=j;
        count++;
      }
      count_ma.at(j)=max(count_ma.at(j),count);
    }
    count_ma.at(a)=max(count_ma.at(a),1);
  }
  long long ans=0;
  for(int i=0;i<N;i++){
    ans+=inv[A.at(i)];
    ans%=MOD;
  }
  for(int i=2;i<count_ma.size();i++){
    for(int j=0;j<count_ma.at(i);j++){
      ans*=i;
      ans%=MOD;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 27648
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

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

    double n = 0;
    REP(i, N)
    {
        auto a = i + 1;
        if (a % 2 != 0)
            n++;
    }

    cout << n / N << endl;
}

Measured memory_bytes: 888
//Create Time: 2020-02-18 19:26:26
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <functional>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <ctime>
#include <utility>
#include <complex>
#include <cassert>
#include <climits>
#include <iterator>
#include <tuple>
using namespace std;
#define snuke(i,x) for (__typeof((x).begin()) i = (x).begin(); i != (x).end(); ++i)
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,n,a) for (int i=(n)-1;i>=(a);i--)
// #define OUT(x) std::cout<<(#x)<<":"<<(x)<<std::endl
// #define TST(x) std::cout<<(#x)<<":"<<(x)<<" "
#define OUT(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);OUT_TST("\n",_it,args);}
#define TST(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);OUT_TST("",_it,args);}
#define SZ(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define unq(x) sort(all(x)),(x).erase(unique(all(x)),(x).end())
#define mem(f,x) memset((f), (x), sizeof(f))
#define clr(f) mem(f,0)
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define DEBUG
void OUT_TST(string s,istream_iterator<string> it) {cerr<<s;}
template<typename T, typename... Args> void OUT_TST(string s,istream_iterator<string> it,T a,Args... args){cerr<<*it<<"="<<a<<" ";OUT_TST(s,++it,args...);}
template<class T> void rd(T&ret){ret=0;bool ok=0,u=0;for(;;){int c=getchar();if(c>='0'&&c<='9')ret=(ret<<3)+(ret<<1)+c-'0',ok=1;else if(c=='-')u=1;else if(ok){if(u)ret*=-1;return;}}}
long long powmod(long long p,long long n,long long mod){long long ret=1;for(;n;n>>=1){if(n&1)ret=ret*p%mod;p=p*p%mod;}return ret;}
template <class T> bool chmin(T& a, const T &b) {return b < a? a = b, 1: 0;}
template <class T> bool chmax(T& a, const T &b) {return b > a? a = b, 1: 0;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef tuple<int,int,int> tp;
/****head****/
const int N=5e6+7;
const ll mod=998244353;
int an[N];
int main(){
    int n; scanf("%d",&n);
    int m=n/2;
    an[0]=1;
    rep(i,1,m+1){
        an[i] = an[i-1] * (m-i+1ll) % mod * powmod(i,mod-2,mod) % mod;
    }
    ll pw=1;
    per(i,m+1,1){
        an[i]=an[i]*pw%mod;
        pw=pw*2%mod;
    }
    an[m+1]=0;
    per(i,m+1,1){
        an[i]=(an[i]+an[i+1])%mod;
    }
    ll c=1,p2=1,sum=0;
    sum=an[1];
    rep(i,1,m){
        c = c * (m-i+1ll) % mod * powmod(i,mod-2,mod) % mod;
        p2 = p2 * 2 % mod;
        sum+=c * p2 % mod * an[i+1] % mod;
        sum%=mod;
    }
    sum = sum * 2 % mod;
    int ans=(powmod(3,n,mod) + mod - sum) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19712
def nC2(n):
    if n <= 1:
        return 0
    return n * (n - 1) // 2

N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: x - 1, A))

A_count = [0] * N
for a in A:
    A_count[a] += 1

combis = [0] * N
for i, a in enumerate(A_count):
    combis[i] = nC2(a)

combis_m1 = [0] * N
for i, a in enumerate(A_count):
    combis_m1[i] = nC2(a-1)

total_sum = sum(combis)
for a in A:
    print(total_sum - combis[a] + combis_m1[a])


Measured memory_bytes: 108712
from collections import Counter
n=int(input())
A=list(map(int,input().split()))

B,C=[],[]
for i,j in enumerate(A):
    B.append(i+j+1)
    C.append((i+1)-j)

B,C=Counter(B),Counter(C)
ans=0
for i,j in B.items():
    ans +=j*C[i]
print(ans)

Measured memory_bytes: 166796
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String result = "No";
		String[] chars = line.split(" ");
		int a,b,c;
		a = Integer.parseInt(chars[0]);
		b = Integer.parseInt(chars[1]);
		c = Integer.parseInt(chars[2]);
		if(c >= a && c <= b){
			result = "Yes";
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


struct Edge {
    ll to;
    ll weight;
    Edge(ll t, ll w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;


typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d;

void warshall_floyd(int n) { // nは頂点数
    for (int i = 0; i < n; i++)      // 経由する頂点
        for (int j = 0; j < n; j++)    // 開始頂点
            for (int k = 0; k < n; k++)  // 終端
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
    int n,m; cin >> n >> m;
    Graph G(n);
    vector<vector<int>> keiro(n, vector<int>(n, -1));

    d = Matrix(n, vector<int>(n, INF));
    for (int i = 0; i < n; i++) d[i][i] = 0;
    rep(i, m) {
        int a,b,c; cin >> a >> b >> c;
        a--;
        b--;
        G[a].emplace_back(b,c);
        G[b].emplace_back(a,c);
        d[a][b] = c;
        d[b][a] = c;
        keiro[a][b] = i;
        keiro[b][a] = i;
    }

    warshall_floyd(n);

    vector<bool> use(m, false);
    rep(i, n) for(Edge e : G[i]) {
        int u = e.to;
        if(d[i][u] == e.weight) use[keiro[i][u]] = true;
    }

    int ans = 0;
    rep(i, m) if(!use[i]) ans++;

    cout << ans << endl;

    return 0;
}



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

int main()
{

    int n,m;
    cin>>n>>m;

    vector<string> v[n+100];
    if(m==0)
    {
        cout<<0 << ' ' <<0<<endl;
    }
    else
    {
        for(int i=0; i<m; i++)
        {
            int t;
            string c;
            cin>>t;
            cin>>c;
            v[t-1].push_back(c);
        }


        int wa=0;
        int ac=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<v[i].size();j++)
            {
                if(v[i][j]=="AC")
                {
                    ac++;
                    wa+=j;
                    break;
                }


            }
        }

        cout<<ac<<' '<<wa<<endl;
    }




}



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

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int N, i, j;
	scanf("%d", &N);
	int *C = (int *)malloc(sizeof(int) * (N - 1));
	int *S = (int *)malloc(sizeof(int) * (N - 1));
	int *F = (int *)malloc(sizeof(int) * (N - 1));
	int *ans = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N - 1; i++){
		scanf("%d%d%d", &C[i], &S[i], &F[i]);
		ans[i] = 0;
	}
	ans[N - 1] = 0;
	for(i = 0; i < N - 1; i++){
		for(j = i; j < N - 1; j++){
			ans[i] = max(S[j], ((ans[i] + F[j] - 1) / F[j]) * F[j]);
//			printf("%d\n", ans[i]);
			ans[i] += C[j];
//			printf("(i, j) = (%d, %d):%d\n", i, j, ans[i]);
		}
	}
	for(i = 0; i < N; i++){
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<vector<char>> v(h + 2, vector<char> (w + 2));
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> v[i][j];
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(v[i][j] == '.'){
                int cnt = 0;
                cnt += v[i + 1][j + 1] == '#';
                cnt += v[i + 1][j] == '#';
                cnt += v[i + 1][j - 1] == '#';
                cnt += v[i + 0][j + 1] == '#';
                cnt += v[i + 0][j - 1] == '#';
                cnt += v[i - 1][j + 1] == '#';
                cnt += v[i - 1][j] == '#';
                cnt += v[i - 1][j - 1] == '#';
                v[i][j] = cnt + '0';
            }
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cout << v[i][j];
        }
        cout << '\n';
    }
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

Int dp[401][401];

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n + 1, 0);
    for (Int i = 0; i < n; i++) {
        cin >> a[i + 1];
    }
    for (Int i = 0; i < n; i++) {
        a[i + 1] += a[i];
    }
    for (Int l = 1; l < n; l++) {
        for (Int i = 0; i + l < n; i++) {
            //cout << i << " " << i + l << endl;
            Int mi = INF;
            for (Int j = i; j < i + l; j++) {
                Int x = min(mi, dp[i][j] + dp[j + 1][i + l]);
                x += a[i + l + 1] - a[j + 1];
                x += a[j + 1] - a[i];
                mi = min(mi, x);
            }
            dp[i][i + l] = mi;
            //dump(mi);
        }
    }
    dump(dp[0][n - 1]);
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    long long n,k,ans;
    cin>>n>>k;
    ans=n%k;
    ans=min(ans,abs(ans-k));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
N,A,B,C,D = map(int,input().split())
S = str(input())
E = max(C,D)
AE = S[A:E]
BD = S[B-2:D+1]
if "##" in AE:
  print("No")
elif C > D and "..." not in BD:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
typedef long long ll;
const int INF = 1e+9+7;

int main(){
    int N;
    cin >> N ;
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    
    int cnt=0;
    int tmp=0;
    bool flag;
    while(tmp<N){
        flag=true;
        tmp=0;
        rep(i,N){
            if(h[i]>0){
                h[i]--;
                if(flag){
                    cnt++;
                    flag=false;
                }
            }else{
                tmp++;
                flag=true;
            }
        }
        
    }

    cout << cnt << endl;
        
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
public class Main{
  public static int[] A;
  
  public static int[]dp;
  
  public static int solve(int i, int N){
   	 if(i == N) return 0;
     if(dp[i]!=-1) return dp[i];
     int cost =0;
     if( (i+1)<=N){
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     }
     if( (i+2)<=N){
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     }
    dp[i] = cost;
    return cost;
  }
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    
    int N = s.nextInt();
    A = new int[N];
    dp = new int[N];
    Arrays.fill(dp, -1);
    
    for(int i=0;i<N;i++){
     	A[i]=s.nextInt(); 
    }
    
    System.out.println(solve(0,N-1));
  }
}

Measured memory_bytes: 62672
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

int main() {
  int l, r;
  cin >> l >> r;
  if (r - l > 3000) return puts("0"), 0;
  int ans = INT_MAX;
  for (int i = l; i < r; i++) {
    for (int j = i + 1; j <= r; j++) {
      LL tmp = 1LL * i * j % 2019;
      if (tmp < ans) ans = tmp;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2000005;
int a[N],n;
double ans;
void fr(int &num){
	num=0;char c=getchar();int p=1;
	while(c<'0'||c>'9') c=='-'?p=-1,c=getchar():c=getchar();
	while(c>='0'&&c<='9') num=num*10+c-'0',c=getchar();
	num*=p;
}
int main(){
	fr(n),n<<=1;
	for(int i=1;i<=n;i++) fr(a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++) ans+=1.0*(i-1)*a[i]/(n-1);
	printf("%.10lf\n",ans);
	return 0;
}


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

using namespace std;

#define FOR(i,a,b)  for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n)    FOR(i,0,n)
#define ALL(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>
#define vP          vector<P>
#define vvP         vector<vP>

int main(){
    int q;cin>>q;
    vector<char> prime(100001);
    REP(i,100001){
        prime[i]='1';
    }
    prime[0]=prime[1]='0';
    for(int i=2;2*i<=100000;i++){
        prime[2*i]='0';
    }
    for(int i=3;i*i<=100000;i+=2){
        if(prime[i]=='0'){
            continue;
        }
        prime[i]='1';
        for(int j=2;i*j<=100000;j++){
            prime[i*j]='0';
        }
    }
    vi query(100001);
    FOR(i,1,100001){
        query[i]+=query[i-1];
        if(prime[i]=='1' and prime[(i+1)/2]=='1'){
            query[i]++;
        }
    }
    REP(i,q){
        int l,r;cin>>l>>r;
        cout<<query[r]-query[l-1]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 1152
A,B,C = (int(num) for num in input().split())

if A>B:
    par1= A
    A=B
    B=par1

if B>C:
    par2 = B
    B=C
    C=par2
    
if A==5 and B==5 and C==7:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 2940
//k_tourist
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define mx 500005
#define non __builtin_popcount
#define ml map<ll, ll> 
#define uml unordered_map<ll, ll>
#define ms map<string , ll> 
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define pl pair<ll, ll>
#define vl vector<ll>
#define vll vector<pl>
#define tpl pair<ll, pl>
#define vlll vector<tpl>
#define vs vector<string>
#define pb push_back
#define mk make_pair
#define M_PI 3.14159265358979323846
#define endl '\n'
#define fst ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define inf ((ll)1e18 + 1)
#define bs binary_search
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define pow powr
#define rep(i,a,b)  for (i=(a);i<(b);i++)
#define nrep(i,a,b) for (i=(a);i>(b);i--)
using namespace std;
 
bool isp[mx];
 
void sv(){
 
	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}
 
ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

void bta_de_yarr(){
    
	ll k, x, i,j;
    cin>>k>>x;

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

int main(){
    fst
	ll t;
    t= 1;
	//cin>>t;
    while(t--){
        bta_de_yarr();
    }
    return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<ll>>;

ll n;
vector<ll> fri[100100];
int color[100100];

void dfs(int r, int c){
  stack<ll> s;
  s.push(r);
  color[r] = c;
  while(!s.empty()){
    int u = s.top(); s.pop();
    rep(i, 0, fri[u].size()){
      int v = fri[u][i];
      if(color[v] == -1){
        color[v] = c;
        s.push(v);
      }
    }
  }
}

void assignColor(){
  int id = 1;
  rep(i, 0, n) color[i] = -1;
  rep(u, 0, n){
    if(color[u] == -1) dfs(u, id++);
  }
}

int main() {
  ll m; cin >> n >> m;
  
  rep(i, 0, m){
    ll a, b; cin >> a >> b;
    fri[a].push_back(b);
    fri[b].push_back(a);
  }

  assignColor();

  ll q; cin >> q;
  rep(i, 0, q){
    ll a, b; cin >> a >> b;
    if(color[a] == color[b]) puts("yes");
    else puts("no");
  }

  return 0;
}



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

int main() {
	int a, b, x;
	cin >> a >> b >> x;
	string res = "NO";
	for (int i = 0;i <= b;i++) {
		if (a + i == x)res = "YES";
	}
	cout << res << endl;
}



Measured memory_bytes: 256
a = "S" + input() + "E"
b = [0] * len(a)
le = 0
ri = 0
for i in range(len(a)):
    if a[i] != a[i-1] and i > 1:
        if a[i] == "L" and a[i-1] == "R":
            le = i - 1
        else:
            cr = (le - 1) - ri + 1
            cl = (i - 1) - le
            b[le] = (cr + 1) // 2 + cl // 2
            b[le+1] = cr + cl - b[le]
            ri = i-1
b.pop(0)
b.pop()
print(" ".join(map(str, b)))



Measured memory_bytes: 10660
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> //required
//#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define lb long double
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
//using namespace __gnu_pbds;
ll dp[3010][3010];
int main(){
    IOS;
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n + 1][m + 1];
    memset(a, 0, sizeof(a));
    ll x, y, v;
    loop(i, 0, k){
        cin >> x >> y >> v;
        debug(x, y, v);
        a[x][y] = v;
    }

    loop(i, 1, n + 1){
        vector<ll> maxi(4);
        loop(j, 1, m + 1){
            maxi[0] = max(maxi[0], dp[i - 1][j]);
            vector<ll> new_maxi(4);
            loop(k, 0, 4){
                if(k == 0)
                    new_maxi[k] = maxi[k];
                else
                    new_maxi[k] = max(maxi[k], maxi[k - 1] + a[i][j]);
                dp[i][j] = max(dp[i][j], new_maxi[k]);
            }
            maxi = new_maxi;
            debug(i, j, maxi, dp[i][j]);
        }
    }

    cout << dp[n][m] << endl;
}

Measured memory_bytes: 144552
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fori(i,s,n) for(int i=s;i<=n;i++)
#define ford(j,s,n) for(int i=n;i>=s;i--)
#define pb push_back
#define TEST int t; cin>>t; for(int T=1;T<=t;T++)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,a,b,f=0;
    cin>>n;
    fori(i,-120,120){
    	fori(j,-120,120)
    	{	if(pow(i,5)-pow(j,5)==n){
    			f=1; a=i; b=j; break;
    		}
    	}
    	if(f==1) break;
    }
    cout<<a<<" "<<b;
    return 0;
}


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

int main(){
    int a[3];
    for(int i=0; i<3; i++) cin >> a[i];
    sort(a, a+3);
    int ans = abs(a[1] - a[0]) + abs(a[2] - a[1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 100, MAXI = N, D = 10;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 100, flag = 1;
//     cout << tc << "\n";
//     while (tc--)
//     {
    	
//     	int n = rand()%D + 1, m = rand()%D + 1;

//     	n = m = 100;

//     	cout << n << " " << m << "\n";

//     	for(int i=1;i<=n;i++)
//     	{
//     		for(int j=1;j<=m;j++)
//     		{
//     			cout << (char)(rand()%2 + '0');
//     		}
//     		cout << "\n";
//     	}

//      	cout << "~\n";
//     }
 
//     return 0;
// }
 
 
 
 
 
 
 
 
//---------------------------------------------//
 
 
 
/*
#define int long long 
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 */ 
 
 
 
 
 
 
//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 100005


int a[N][3], n, dp[N][3];

int MEM(int ind, int take)
{
	if(ind>n)
		return 0;

	int ans = dp[ind][take];

	if(ans!=-1)
		return ans;

	ans = a[ind][take];

	if(take==1)
		ans += max(MEM(ind+1, 0), MEM(ind+1, 2));
	else if(take==2)
		ans += max(MEM(ind+1, 0), MEM(ind+1, 1));
	else
		ans += max(MEM(ind+1, 1), MEM(ind+1, 2));

	return dp[ind][take] = ans;
}


// // Driver code to test above functions
int32_t main()
{
   
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

   	memset(dp, -1, sizeof dp);

   	cin >> n;

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

   	cout << max(MEM(1, 0), max(MEM(1, 1), MEM(1, 2)));
   	
   	
    
    return 0;
 
} 


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":	" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

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

int main() {
  string s; cin>>s;
  string t; cin>>t;
  int sl = s.size();
  int tl = t.size();

  int ans = sl;
  for (int i=0; i<sl-tl+1; i++) {
    int tmp = tl;
    for (int j=0; j<tl; j++) {
      if (s[i+j] == t[j]) tmp--;
    }
    mins(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


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

using ll = long long;
using ld = long double;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    int ans = 0;
    int sc = 0;
    REPS(c, s) {
        if (c == 'S') sc++;
        else {
            if (sc > 0) sc--;
            else ans++;
        }
    }
    cout << ans + sc << EOL;
}


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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

ll gcd(ll a, ll b)
{
	return (b == 0 ? a : gcd(b, a % b));
}

ll lcm(ll a, ll b)
{
	return (a * b) / gcd(a, b);
}

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

	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b) << '\n';
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=[0]*N
B=[0]*N
pen=0
for i in range(M):
  p,S=input().split()
  if S=="AC":
    A[int(p)-1]=1
  elif S=="WA" and A[int(p)-1]==0:
    B[int(p)-1] += 1
penalty=[A[i]*B[i] for i in range(N)]
print(sum(A),sum(penalty))

Measured memory_bytes: 5528
main = do
  (a:b:c:x:y:xs) <- map read . words <$> getLine
  putStrLn . show $ solve a b c x y

solve a b c x y = (min x y) * (min (a+b) (c*2)) 
                + (min (if x>y then a else b) (c*2)) * (abs (x-y))

Measured memory_bytes: 508
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int main() {
  int a[8];
  rep(i,8) cin>>a[i];
  int s = accumulate(a, a+4, 0), t = accumulate(a+4, a+8, 0);
  cout << max(s,t) << endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll n, m, ans=0;
  cin >> n >> m;
  ll imos[100001];
  REP(i, 100001) { imos[i] = 0; }

  REP(i, m) {
    ll l, r;
    cin >> l >> r;
    imos[--l]++;
    imos[r]--;
  }
  ll cnt = 0;
  REP(i, n) {
    cnt += imos[i];
    if (cnt == m) ans++;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4400
import sys
from collections import deque

A,B = map(int,input().split())
ask = lambda x,y: print('?',x,y, flush=True)

if A <= B:
  print('Impossible', flush=True)
  sys.exit()

N = A+B
candidates = deque(range(N), N)

while len(candidates) > 2:
  x,y = candidates.pop(), candidates.pop()
  ask(x,y)
  if input() == 'Y':
    candidates.appendleft(y)

god = candidates[0]
result = []
for i in range(N):
  ask(god,i)
  result.append(input() == 'Y')

print('!', ''.join(str(int(s)) for s in result), flush=True)

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

long gcd(long n, long m) {
	if (n == 0)return m;
	if (n < m)swap(n, m);
	return gcd(n % m, m);
}

int main() {
	int N; cin >> N;
	string s[110];
	int p[110];
	int a[110];
	for (int i = 0; i < N; i++){
		cin >> s[i] >> p[i];
		a[i] = i+1;
	}
	for (int i = 0; i < N; i++)for (int j = i + 1; j < N; j++) {
		if (s[i].compare(s[j]) >0) {
			swap(s[i], s[j]);
			swap(p[i], p[j]);
			swap(a[i], a[j]);
		}
		else if (s[i].compare(s[j]) == 0){
			if (p[i] < p[j]) {
				swap(p[i], p[j]);
				swap(a[i], a[j]);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << a[i] << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int total = n*(l-1)+n*(n+1)/2;
        if (0<l)total-=l;
        else if (-n>=l)total-=l+n-1;
        System.out.println(total);

    }
}


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

int main() {
    string S, T;
    int ans = 0;
    cin >> S >> T;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != T[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	const int n = s.size();
	int answer = 0, h = 0, t = n - 1;
	while(h < t){
		int d = 0;
		while(h < t && s[h] == 'x'){ ++h; ++d; }
		while(h < t && s[t] == 'x'){ --t; --d; }
		if(s[h] != s[t]){
			answer = -1;
			break;
		}else if(s[h] != 'x'){
			answer += abs(d);
		}
		++h; --t;
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 512
#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;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k, n ;
  cin >> k >> n ;
  vector<ll> num(n) ;
  vector<ll> ans(n) ;
  REP(i,n){
    cin >> num[i] ;
  }
  ll a = 0 ;
  REP(i,n){
    if(i==n-1){
      ans[i] = k - num[i] + num[0] ;
    }
    else{
      ans[i] = num[i+1] -num[i] ;
    }
  }
  sort(ALL(ans)) ;
  REP(i,n-1){
    a += ans[i] ;
  }
  cout << a <<endl ;
  
  
  
  
  return 0 ;
}



Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define input() for(int i=0;i<n;i++)cin>>a[i];
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}

signed main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
	endre;
}

Measured memory_bytes: 764