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

int main() {
	int n,co=0;
	long long ans = 0;
	cin >> n;
	vector<int> da(n),me(0);
	for (int i = 0;i < n;i++) {
		cin >> da[i];
		if (da[i] < 0)
			co++;
		if (da[i] < 0) {
			me.push_back(-da[i]);
			ans -= da[i];
		}
		else {
			me.push_back(da[i]);
			ans += da[i];
		}
	}
	sort(me.begin(), me.end());
	if (me.size() > 1) {
		if (co % 2 == 0)
			cout << ans << endl;
		else
			cout << (long long)ans - me[0]*2 << endl;
	}
	else
		cout << ans << endl;
}

Measured memory_bytes: 1276
#include<iostream>
using namespace std;
int main(void){
  int a,b,c,d;
 cin >> a >> b >> c >> d;
  if(abs(a-c) <= d || abs(a-b) <= d && abs(b-c) <= d){
    cout << "Yes";
  }else{
    cout << "No";
  }
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i,c=1;
    for(i=0;i<n-1;i++)
    {
        if(s[i]!=s[i+1]) c++;
    }
    cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 3772
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define int long long
#ifdef ONLINE_JUDGE
const int maxn = 3e5 + 10;
#else
const int maxn = 1e5 + 10;
#endif
using namespace std;
int N, X, arr[maxn];
signed main()
{
    ios::sync_with_stdio(false);
    cin >> N >> X;
    for (ri i = 1; i <= N; ++i) {
        cin >> arr[i];
    }
    arr[++N] = X;
    sort(arr + 1, arr + 1 + N);
    vector<int> v;
    for (ri i = 2; i <= N; ++i) {
        v.push_back(arr[i] - arr[i - 1]);
    }
    int gcd = v[0];
    for (ri i = 1; i < v.size(); ++i) {
        gcd = __gcd(gcd, v[i]);
    }
    cout << gcd << endl;
    return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int H, W;

int main() {
  scanf("%d%d", &H, &W);
  // true: 黒, false: 白
  vector<vector<bool>> a(H, vector<bool>(W, false));
  // true: 黒を含む, false: 全部白
  vector<bool> col(W, false), row(H, false);

  for (int h = 0; h < H; ++h) {
    string buf;
    cin >> buf;
    for (int w = 0; w < W; ++w) {
      if (buf[w] == '#') {
        a[h][w] = true;
        col[w] = true;
        row[h] = true;
      }
    }
  }

  for (int h = 0; h < H; ++h) {
    if (!row[h]) continue;
    for (int w = 0; w < W; ++w) {
      if (!col[w]) continue;
      if (a[h][w]) printf("#");
      else printf(".");
    }
    printf("\n");
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

void dfs(int count, vector<int> &vec, int j, vector<int> s, vector<vector<int>> &ret) {
	if (count == s.size()) {
		ret.push_back(s);
		return;
	}

	for (int i = j; i < vec.size(); ++i) {
		vector<int> buf;
		buf = s;
		buf.push_back(vec[i]);
		dfs(count, vec, i, buf, ret);
	}

}

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<tuple<int, int, int, int>> vec(Q);
	for (int i = 0; i < Q; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		vec[i] = make_tuple(a, b, c, d);
	}

	vector<int> A;
	for (int i = 1; i <= M; ++i) {
		A.push_back(i);
	}

	vector<int> s;
	vector<vector<int>> ret;
	dfs(N, A, 0, s, ret);

	int maxScore = INT_MIN;
	for (size_t t = 0; t < ret.size(); ++t) {
		int score = 0;
		for (int i = 0; i < Q; ++i) {
			int a = get<0>(vec[i]), b = get<1>(vec[i]), c = get<2>(vec[i]), d = get<3>(vec[i]);
			int Aa = (ret[t][a - 1] - 0x30);
			int Ab = (ret[t][b - 1] - 0x30);
			if (Ab - Aa == c) {
				score += d;
			}
		}
		maxScore = max(maxScore, score);
	}

	cout << maxScore << endl;
	return 0;
}

Measured memory_bytes: 9800
program main
  implicit none
  integer :: N
  character(len=50) :: S
  integer :: out, i
  read(*,*) N
  read(*,*) S
  out = 0
  do i = 1,N
     if ( S(i:i+2) == 'ABC' ) out = out + 1
  end do
  write(*,'(i0)') out
  stop
end program main


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

using namespace std;

int main() {
	string S, T;
	cin >> S >> T;
	string ans = "No";
	for (int i = 0; i < S.length(); i++) {
		if (S == T) {
			ans = "Yes";
			break;
		}
		S = S.back() + S.substr(0, S.length() - 1);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int n,A[50];
struct P{
	double x;
	double y;
}; 
void print(struct P p){
	printf("%.8f %.8f\n",p.x,p.y);
}
void koch(int n,struct P p1,struct P p2){
	if(n==0)
		return;
	double th = M_PI * 60.0 / 180.0;
	struct P s,u,t;
	s.x=(2.0*p1.x+1.0*p2.x)/3.0;
	s.y=(2.0*p1.y+1.0*p2.y)/3.0;
	t.x=(1.0*p1.x+2.0*p2.x)/3.0;
	t.y=(1.0*p1.y+2.0*p2.y)/3.0;	
	u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
	
	koch(n-1,p1,s);
	print(s);
	koch(n-1,s,u);
	print(u);
	koch(n-1,u,t);
	print(t);
	koch(n-1,t,p2);
}

int main() {
	struct P a,b;
	int n;
	
	scanf("%d",&n);
	
	a.x=0;a.y=0;
	b.x=100;b.y=0;
	
	print(a);
	koch(n,a,b);
	print(b);
	
	return 0;
}

Measured memory_bytes: 2732
program main
integer(8) :: n,i,s
integer, allocatable :: x(:),a(:)
read(*,*)n
allocate(a(n),x(n))
read(*,*)(a(i),i=1,n)
s = sum(a)
do i = 2,n-1,2
s = s - 2*a(i)
end do
x(1) = s

do i = 2,n
x(i) = 2*a(i-1) - x(i-1)
end do
write(*,*)x
end program main

Measured memory_bytes: 3328
#include<stdio.h>
int main(void){
int N, K, sum=0;
scanf("%d%d", &N, &K);
int h[N];
for(int i=0;i<N;i++){
scanf("%d", &h[i]);
if(h[i]>=K){
    sum+=1;
  }
}
printf("%d", sum);
return 0;
}

Measured memory_bytes: 512
# coding: utf-8
# Here your code !


def latte():
    return int(input())

while True:
    x=y=0
    n=latte()
    if n==0 :break
    for i in range(n):
        a,b=map(int,input().strip().split())
        if a>b:
            x+=a+b
        elif b>a:
            y+=a+b
        else :
            x+=a
            y+=b
    
    print(x,y)
    
    

Measured memory_bytes: 7604
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL X,Y,A,B,C;cin >> X >> Y >> A >> B >> C;
    vector<LL> p(A);
    vector<LL> q(B);
    vector<LL> r(C);
    rep(i,A)cin >> p[i];
    rep(i,B)cin >> q[i];
    rep(i,C)cin >> r[i];

    priority_queue<LL> P;
    priority_queue<LL> Q;
    priority_queue<LL> R;
    rep(i,A)P.push(p[i]);
    rep(i,B)Q.push(q[i]);
    rep(i,C)R.push(r[i]);
    priority_queue<LL,vector<LL>,greater<LL>> Pr;
    priority_queue<LL,vector<LL>,greater<LL>> Qr;

    rep(i,X){
        LL tmp = P.top();
        P.pop();
        Pr.push(tmp);
    }
    rep(i,Y){
        LL tmp = Q.top();
        Q.pop();
        Qr.push(tmp);
    }

    LL ans = 0;

    while(true){
        LL a,b,c;
        a = Pr.top();
        b = Qr.top();
        if(R.empty())break;
        c = R.top();

        if(a >= c && b >= c)break;
        else{
            if(c - a > c - b){
                R.pop();
                Pr.pop();
                Pr.push(c);
            }
            else{
                R.pop();
                Qr.pop();
                Qr.push(c);
            }
        }
    }

    while(!Pr.empty()){
        ans += Pr.top();
        Pr.pop();
    }
    while(!Qr.empty()){
        ans += Qr.top();
        Qr.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 7156
import java.util.*;

class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		char[] c=s.next().toCharArray();

		int[] a=new int[n];
		for(int i=n-1;i>=1;--i){
			a[i-1]=1<<f(i,c);
			if(i<n-1)
				a[i-1]|=a[i];
		}

		int[] r=new int[100];

		for(int i=0;i<n;++i){
			for(int j=i+1;j<n;++j){
				r[f(i,c)*10+f(j,c)]|=a[j];
			}
		}

		int q=0;
		for(int i:r)
			q+=Integer.bitCount(i);
		System.out.println(q);
	}

	private static int f(int i,char[] c){
		return c[i]-'0';
	}
}


Measured memory_bytes: 24148
from collections import *
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    c = Counter()
    m = 0
    S = [input() for i in range(N)]
    for s in S:
        c[s] += 1
        m = max(m, c[s])

    ans = sorted([k for k, v in c.items() if v == m])
    print('\n'.join(ans))
if __name__ == '__main__':
    main()

Measured memory_bytes: 38364
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int x,y,z;
	static int[][] board;
	static int[] v;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true){
			x = sc.nextInt();
			y = sc.nextInt();
			z = sc.nextInt();
			if(x+y+z==0)break;
			ans=0.0;
			v=new int[x];
			for(int i=0;i<x;i++){
				v[i]=sc.nextInt();
			}
			 board=new int[y+1][2];
			for(int i=0;i<z;i++){
				int n = sc.nextInt();
				int e = sc.nextInt();
				int a = sc.nextInt();
				if(e==3)a*=-1;
				board[n][0]=e;
				board[n][1]=a;
				
			}
			double[][] dp=new double[y+1][10000];
			for(int i=0;i<y+1;i++){
				Arrays.fill(dp[i], 0);
			}
			dp[0][0]=1.0;
			for(int i=0;i<y;i++){
				int e = board[i][0];
				int a = board[i][1];
				for(int j=0;j<dp[i].length;j++){
					for(int k=0;k<x;k++){
						int next=i+v[k];
						if(next>=y)next=y;
						double p =dp[i][j]/(double)x; 
						if(e==0){
							dp[next][j]+=p;
						}
						else if(e==1){
							next+=a;
							if(next>=y)next=y;
							dp[next][j]+=p;
						}
						else{
							int m = j+a;
							if(m>=10000)m=9999;
							if(m<0)m=0;
							dp[next][m]+=p;
						}
						
					}
				}
			}
//			rec(0,0,1.0);
			for(int i=0;i<dp[0].length;i++){
				ans += dp[dp.length-1][i] * i;
//				System.out.println(i+" "+dp[dp.length-1][i]);
			}

//			System.out.println(dp[1][0]+" "+1.0/x);
//			System.out.println((int)(ans+0.000000001));
			System.out.println((int)(ans));
		}
			
	}
	static double ans = 0.0;

	public static void rec(int a,int b,double kakuritu){
		if(a>=y){
			ans+=(double)b*kakuritu;
			return;
		}
		for(int i=0;i<x;i++){
			int next=a+v[i];
			double p = 1.0/x;
			
			if(board[a][0]==0){
				rec(next,b,kakuritu*p);
			}
			else if(board[a][0]==1){
				rec(next+board[a][1],b,kakuritu*p);
			}
			else{
				rec(next,Math.max(0,b+board[a][1]),kakuritu*p);
			}
			
		}
		return;
		
	}
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

#define CONTAINS(v, x) (find(v.begin(), v.end(), x) != v.end())

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> swi[m];
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int h;
      cin >> h;
      swi[i].push_back(h - 1);
    }
  }
  vector<int> v(m);
  for (int i = 0; i < m; i++) cin >> v[i];

  // mは電球の数！！

  int ans = 0;
  for (int k = 0; k < (1 << n); k++) {  // bit全探索
    vector<int> count(n);               // どこの電球のスイッチが何個点いているか
    for (int i = 0; i < n; i++) {       // i番目のビットが立っているかを見ます
      if (k & (1 << i)) {               // i番目のスイッチがオンなら
        for (int j = 0; j < m; j++) {
          if (CONTAINS(swi[j], i)) {
            count[j]++;
          }
        }
      }
    }

    bool tento = true;
    // 全て点いているか確認
    for (int i = 0; i < m; i++)
      if (count[i] % 2 != v[i]) tento = false;

    ans += tento;
  }

  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int MOD = 998244353;

map<string, int> dp;

int solve(string s) {
    if (dp.count(s)) return dp[s];
    int ans = 0;
    if (s.empty()) {
        dp[s] = 1;
        return 1;
    }
    if (s[0] == '0') {
        ans = solve(s.substr(1, s.length()));
    } else {
        ans = 2 * solve(s.substr(1, s.length())) % MOD;
    }
    int n = s.length();
    for (int len = 1; len < n; len++) {
        string go = s.substr(0, len);
        for (int iter = 1; iter * len <= n; iter++) {
            string add = s.substr((iter - 1) * len, len);
            for (int k = 0; k < add.size(); k++) {
                if (add[k] == '0') {
                    go[k] = '0';
                }
            }
            if (iter >= 2) {
        //        cerr << go << "  "<< s.substr(iter*len, n) << endl;
                ll godp = 1LL * solve(go) * solve(s.substr(iter * len, n)) % MOD;
                ans = (ans + godp) % MOD;
            }
        }
    }
    dp[s] = ans;
    return ans;
}
int main()
{
#ifdef AZINO777
    freopen("in", "r", stdin);
#endif
    string s;
    cin >> s;
    cout << solve(s) << endl;
    return 0;
}

Measured memory_bytes: 5632
#include<cstdio>
#include<cstring>
typedef long long LL;
const int md=1e9+7,N=16384;
int fac[N],iv[N],n,c[5002],dp[5002],g[5002],h[5002],s[5002];
char v[N];
inline int C(int n,int m){return(LL)fac[n]*iv[m]%md*iv[n-m]%md;}
inline int pow(int a,int b){
	int ret=1;
	for(;b;b>>=1,a=(LL)a*a%md)if(b&1)ret=(LL)ret*a%md;
	return ret;
}
void PW(int b,int n){
	static int A[5002];
	*dp=1;
	for(;b;b>>=1){
		if(b&1){
			memset(A,0,sizeof A);
			for(int i=0;i<=n;++i)for(int j=0;j<=i;++j)
			A[i]=(A[i]+(LL)dp[j]*c[i-j])%md;
			memcpy(dp,A,sizeof A);
		}
		memset(A,0,sizeof A);
		for(int i=0;i<=n;++i)for(int j=0;j<=i;++j)
		A[i]=(A[i]+(LL)c[j]*c[i-j])%md;
		memcpy(c,A,sizeof A);
	}
}
int main(){
	scanf("%d%s",&n,v);
	int L=strlen(v),k=n-L>>1;
	for(int i=*fac=1;i<=2*n;++i)fac[i]=(LL)fac[i-1]*i%md;
	iv[2*n]=pow(fac[2*n],md-2);
	for(int i=2*n-1;~i;--i)iv[i]=(i+1LL)*iv[i+1]%md;
	for(int i=0,w=1;i<=k;++i,w=w*2>=md?w*2-md:w*2)
	c[i]=(LL)C(2*i,i)*iv[i+1]%md*fac[i]%md*w%md;
	PW(L+1,k);
	h[0]=g[0]=1;
	for(int i=1;i<=2*k+1;++i){
		memset(s,0,sizeof s);
		for(int j=1;j<=2*k+1;++j)s[j]=g[j-1]*2%md;
		for(int j=0;j<2*k+1;++j)s[j]=(s[j]+g[j+1])%md;
		s[0]=(s[0]+g[0])%md;
		h[i]=s[0];
		memcpy(g,s,sizeof s);
	}
	int ans=0;
	for(int i=0;i<=k;++i){
		int sy=n-2*i-L;
		int ch=(sy==0)?1:h[sy-1];
		ans=(ans+(LL)ch*dp[i])%md;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String args[] ){
		Scanner sc =new Scanner(System.in);
		int n =sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(n*a <b) {
			System.out.println(n*a);
			
		} else {
			System.out.println(b);
		}
	}

}


Measured memory_bytes: 23252
#pragma region GNUC
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#pragma endregion

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;
#pragma region Math
// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}

template<class T>
T pow(T x,int n){
	T mul = x;
	T ans = (T)1;
	while(n){
		if(n&1){
			ans *= mul;
		}
		mul *= mul;
		n >>= 1;
	}
	return ans;
}
#pragma endregion //math

void solve(){
	int N,K,X,Y;
	cin >> N >> K >> X >> Y;
	int ans = 0;
	if( N>=K ){
		ans = X*K + Y*(N-K);
	}else{
		ans = X*N;
	}
	cout << ans;
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


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

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    int N , R;
    cin >> N >> R;
    if(N < 10){
        cout << R + 100 * (10 - N);
        return 0;
    }
    else{
         cout << R;
         return 0;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <list>
#include <stack>
#include <queue>
using namespace std;

typedef list<int> L;
typedef pair <int,int> P;
typedef vector<int> V;
typedef queue<P> Q;
typedef stack<int> S;
typedef map<string,int> M;

int W, H;
const int MAX = 31;
const int INF = 99999;
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
int ds[] = {1, 2, 4, 8};

int bfs(int s[MAX][MAX]) {
    Q q;
    q.push(P(0, 0));
    int d[MAX][MAX];
    for (int i = 0; i < MAX; i++)
        for (int j = 0; j < MAX; j++)
            d[i][j] = INF;
    d[0][0] = 1;

    while (q.size()) {
        int x = (q.front()).first, y = (q.front()).second;
        q.pop();

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && d[nx][ny] == INF && (s[x][y] & ds[i]) == 0) {
                q.push(P(nx, ny));
                d[nx][ny] = d[x][y] + 1;
            }
        }
    }

    return d[H - 1][W - 1] != INF ? d[H - 1][W - 1] : 0;
}

int main()
{
    while (cin >> W >> H, H) {
        int s[MAX][MAX] = {};
        for (int i = 0; i < H; i++) {
            for (int j = 1; j < W; j++) {
                int wall; cin >> wall;
                if (wall == 1) {
                    s[i][j] |= 1;
                    s[i][j - 1] |= 4;
                }
                if (j == 1)
                    s[i][j - 1] |= 1;
                else if (j == W - 1)
                    s[i][j] |= 4;
            }
            for (int j = 0; j < W; j++) {
                int wall;
                if (i < H - 1) cin >> wall;
                else wall = 1;
                if (wall == 1) {
                    s[i][j] |= 2;
                    s[i + 1][j] |= 8;
                }
                if (i == 0)
                    s[i][j] |= 8;
            }
        }
        cout << bfs(s) << endl;;

    }

    return 0;
}

Measured memory_bytes: 1216
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve1():
    x = input()

    cnt_S = 0
    cnt_T = 0
    res = 0
    i = 0
    while i < len(x):
        if x[i] == "S":
            cnt_S += 1
            i += 1

        elif x[i] == "T" and cnt_S != 0:
            while i < len(x) and x[i] == "T":
                cnt_T += 1
                i += 1
            res += min(cnt_S, cnt_T) * 2
            cnt_S -= min(cnt_S, cnt_T)
            cnt_T = 0
        else:
            i += 1

    print(len(x) - res)


def resolve2():
    x = input()
    n = len(x)

    stack = 0
    res = 0
    for i in range(n):
        if x[i] == "S":
            stack += 1
        elif stack > 0:
            stack -= 1
            res += 1

    print(n - res * 2)


if __name__ == '__main__':
    resolve2()


Measured memory_bytes: 3500
#include<stdio.h>
void selectionsort(int a[],int N);//??¢??°??£?¨?
static int cnt=0;//???????????°????¨????
int main(){
  int N;
  scanf("%d",&N);
  int a[N];
  for(int i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  selectionsort(a,N);//??¢??°????????????
  int j=0;
  for(int i=0;i<N;i++){//???????????????
    if(j++>0)printf(" ");
    printf("%d",a[i]);
  }
  printf("\n");
  printf("%d\n",cnt);
}
void selectionsort(int a[],int N){//???????????????
  int minj=0;
  for(int i=0;i<N;i++){//???????°???????????´??????????????????°?????§????´?????????????
    minj=i;
    for(int j=i;j<N;j++){
      if(a[j]<a[minj]){
        minj=j;
      }
    }
    if(i!=minj){//i==minj???????°???????????´?????????????????????§????????????????????????
      int temp=a[i];
      a[i]=a[minj];
      a[minj]=temp;
      cnt++;//?????????????????§?????????????????????
    }
  }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    n++;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    int g=0;
    for(int i=1;i<n;i++)
        g=__gcd(g,v[i]-v[i-1]);
    cout<<g<<"\n";
    return 0;
}


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    queue<char> q;
    for (char c : s) q.push(c);
    vector<string> candidate;
    while (!q.empty()) {
        char c = q.front();
        q.pop();
        string t = "";
        t += c;
        if (!candidate.empty() && candidate.back() == t) {
            if (q.empty()) {
                break;
            } else {
                char c2 = q.front();
                q.pop();
                t += c2;
            }
        }
        candidate.push_back(t);
    }
    cout << candidate.size() << endl;
}


Measured memory_bytes: 10996
n = int(input())
a, b = map(int , input().split())
p = list(map(int, input().split()))
group_a = len([i for i in p if i <= a])
group_b = len([i for i in p if i > a and i <= b])
group_c = len([i for i in p if i > b])
print(min(group_a, group_b, group_c))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define mod 998244353LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 100000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pii a, pii b)//true for a before b
{
	if(a.S < b.S)
		return 1;
	if(a.S > b.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;

ll a[N];

void solve()
{
	int n, i;
	ll sm = 2, la = 2;
	cin >> n;
	fo(i,1,n+1)
		cin >> a[i];
	if(a[n] != 2)
	{
		cout << -1 << '\n';
		return;
	}
	for(i = n-1; i > 0; i--)
	{
		sm = ((sm+a[i]-1LL)/a[i])*a[i];
		la = ((la+a[i+1]-1LL)/a[i])*a[i];
		if(sm > la)
		{
			cout << -1 << '\n';
			return;
		}
	}
	la += (a[1] - 1LL);
	cout << sm << " " << la << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand(clock());

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(3);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case " << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

lint solve(lint n, lint a, lint b){
    if(!((b - a) & 1LL)){
        return (b - a) >> 1;
    }

    lint res = a - 1LL + b - a;
    chmin(res, n - b + b - a);
    chmin(res, a - 1LL + 1LL + ((b - a) >> 1));
    chmin(res, n - b + 1LL + ((b - a) >> 1));

    return res;
}

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

    lint n, a, b;
    cin >> n >> a >> b;

    cout << solve(n, a, b) << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    ll n;
    cin>>n;
    ll sum=0;
    rep(i,n){
        if((i+1)%3!=0&&(i+1)%5!=0){
            sum+=i+1;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;

  cout << n*(n-1)/2 << endl;
}


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

using namespace std;
static const int N=100;
static const int INFTY = (1 << 21);
int n, M[N][N];
int d[N];
void bfs(int s) {
	queue<int> q;
	q.push(s);
	for (int i = 0; i < n; i++)d[i] = INFTY;
	d[s] = 0;
	int u;
	while (!q.empty()) {
		u = q.front(); q.pop();
		for (int v = 0; v < n; v++) {
			if (M[u][v] == 0)continue;
			if (d[v] != INFTY)continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
	}
}


int main()
{
	int u, k, v;
	cin >> n;
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)M[i][j] = 0;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;
			M[u][v]=1;
		}
	}
	bfs(0);
    return 0;
}



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


int main(){
    int n;
    cin >> n;
    int sum=0;
    int ma=0;
    rep(i,n){
        int p;
        cin >> p;
        sum+=p;
        ma=max(p,ma);
    }
    sum-=ma/2;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = list(map(int, input().split()))
ans = 0
sum_n = (n+1)*n/2

for i in range(k, n+2):
    tmp_b = (i)*(i-1)/2
    tmp_a = sum_n - (n-i+1)*(n-i)/2
    ans += tmp_a - tmp_b + 1
print(int(ans)%(10**9+7))


Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long long L,R;
  cin>>L>>R;
  long long Min=2018;
  if(R-L<2019){
    for(long long i=L; i<R; i++){
for (long long j=i+1; j<=R; j++){
  Min=min(Min,(i*j)%2019);
}}
    printf("%lld",Min);
  }
  else{
    cout<<0<<endl;}
}
      


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
	ll N, W;
	cin >> N >> W;
	vll w, v;
	ll i, j, k, m;
	for (i = 0; i < N; i++){
		ll wi, vi;
		cin >> wi >> vi;
		w.push_back(wi);
		v.push_back(vi);
	}
	vll c(4, 0);
	vll v0, v1, v2, v3;
	for (i = 0; i < N; i++){
		if (w[i] - w[0] == 0){
			c[0]++;
			v0.push_back(v[i]);
		}
		if (w[i] - w[0] == 1){
			c[1]++;
			v1.push_back(v[i]);
		}
		if (w[i] - w[0] == 2){
			c[2]++;
			v2.push_back(v[i]);
		}
		if (w[i] - w[0] == 3){
			c[3]++;
			v3.push_back(v[i]);
		}
	}
	sort(v0.begin(), v0.end());
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	sort(v3.begin(), v3.end());
	ll ans = 0;
	for (i = 0; i <= c[0]; i++){
		for (j = 0; j <= c[1]; j++){
			for (k = 0; k <= c[2]; k++){
				for (m = 0; m <= c[3]; m++){
					if (w[0] * i + (w[0] + 1)*j + (w[0] + 2)*k + (w[0] + 3)*m <= W){
						ll anstmp = 0;
						for (ll l = 0; l < i; l++){
							anstmp += v0[c[0] - l - 1];
						}
						for (ll l = 0; l < j; l++){
							anstmp += v1[c[1] - l - 1];
						}
						for (ll l = 0; l < k; l++){
							anstmp += v2[c[2] - l - 1];
						}
						for (ll l = 0; l < m; l++){
							anstmp += v3[c[3] - l - 1];
						}
						ans = max(ans, anstmp);
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
T=str(bin(K))
S=len(T)-2
A = list(map(int,input().split()))
lst=[[0 for e in range(N+1)] for f in range(S)]
for i in range(1,N+1):
 lst[0][i]=A[i-1]
for j in range(1,S):
 for i in range(1,N+1):
  lst[j][i]=lst[j-1][lst[j-1][i]]
ans=1
for k in range(S):
 if int(T[k+2])==1:
  ans=lst[S-1-k][ans]
print(ans)

Measured memory_bytes: 217248
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        a: u32,
        b: u32
    }
    for i in 1..4 {
        if i != a && i != b {
            println!("{}", i);
            return;
        }
    }
}
/* vim:set foldmethod=marker: */


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

int main(){
	int n;
	cin >> n;
	map<string, int> T;
	for(int i=0; i< n;i++){
		string buf;
		cin >> buf;
		auto target = T.find(buf);
		if(target == T.end()){
			T.insert(make_pair(buf,1));
		}
	}
	cout << T.size() << endl;
	return 0;
}


Measured memory_bytes: 19132
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
    if(a%b==0)  return b;
    else    return gcd(b,a%b);
}
 
long long lcm(long long a,long long b){
    return a*b/gcd(a,b);
}
int main(){
  long long a,b;
  cin >> a >> b;
  cout <<lcm(a,b);
  return 0;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9

int main() {
	int r;
	cin >> r;
	cout << 3 * pow(r, 2) << endl;
	return 0;
}

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


int main()
{
    /*A
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    */
    ll x;
    cin>>x;
    ll count1 = x/500;
    x=x-500*count1;
    ll count2 = x/5;
    cout<<count1*1000+count2*5<<endl;
    return 0;

}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

class UnionFind {
public:
    struct Node {
        long long parent, rank, weight;
        Node() = default;
        Node(const long long& _parent,
             const long long& _rank,
             const long long& _weight = 0) :
            parent(_parent),
            rank(_rank),
            weight(_weight) { }
    };

    std::vector<Node> node;

    UnionFind(const long long& num_node) :
        node(num_node) {
        for(long long i = 0; i < num_node; i++) {
            node[i].parent = i;
        }
    }

    long long searchAndZipRoot(const long long& x) {
        if(node[x].parent == x) {
            return x;
        }
        else {
            auto r = searchAndZipRoot(node[x].parent);
            node[x].weight += node[node[x].parent].weight;
            return node[x].parent = r;
        }
    }

    long long calcWeight(const long long& x) {
        searchAndZipRoot(x);
        return node[x].weight;
    }

    void unite(const long long& x,
               const long long& y,
               const long long& weight = 0) {
        auto rx = searchAndZipRoot(x);
        auto ry = searchAndZipRoot(y);
        if(rx != ry) {
            auto yw = weight + calcWeight(x) - calcWeight(y);
            if(node[rx].rank < node[ry].rank) {
                std::swap(rx, ry);
                yw *= -1;
            }
            node[ry].parent = rx;
            node[ry].weight = yw;
            if(node[rx].rank == node[ry].rank) {
                node[rx].rank++;
            }
        }
    }

    long long calcDiff(const long long& x,
                       const long long& y) {
        return std::abs(calcWeight(x) - calcWeight(y));
    }

    template<class... A>
    bool checkWhetherRootIsSame(const A&... nodes) {
        auto node_list = std::initializer_list<long long>{nodes...};
        if(node_list.size() < 2) return false;
        auto v = searchAndZipRoot(*node_list.begin());
        for(size_t i = 1; i < node_list.size(); i++) {
            if(v != searchAndZipRoot(*(node_list.begin() + i))) return false;
        }
        return true;
    }
};

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

    int N, M;
    std::cin >> N >> M;

    UnionFind tree(N);

    string ans = "Yes";
    REP(i, M) {
        int l, r, d;
        std::cin >> l >> r >> d;
        l--; r--;

        if(!tree.checkWhetherRootIsSame(l, r)) {
            tree.unite(r, l, d);
        }
        else {
            if(tree.calcDiff(l, r) != d) {
                ans = "No";
                break;
            }
        }
    }

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

    return 0;
}


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

int main() {
    ull N, D;
    cin >> N >> D;
    ull D2 = D * D;
    ull cnt = 0;
    vector<vector<ull>> XY(N, vector<ull>(2));
    for (int i=0; i<N; i++) {
        cin >> XY[i][0] >> XY[i][1];
        if (XY[i][0] * XY[i][0] + XY[i][1] * XY[i][1] <= D2) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 14340
import numpy as np


a, b, h, m = map(int, input().split())
theta = np.abs(((h+m/60) * 5 / 60 - m / 60) * 2 * np.pi)
theta = min(theta, 2 * np.pi - theta)
d = np.sqrt(a ** 2 + b ** 2 - 2 * a * b * np.cos(theta))
print(d)


Measured memory_bytes: 27160
let n = stdin.ReadLine() |> int

let ary =
    stdin.ReadLine().Split()
    |> Array.map uint32
    |> Array.sort

let ans =
    match n with
    | x when x < 3 -> 0
    | _ ->
        seq {
            for i in 0 .. (n - 3) do
                for j in (i + 1) .. (n - 2) do
                    for k in (j + 1) .. (n - 1) -> ary.[i], ary.[j], ary.[k]
        }
        |> Seq.filter (fun (lenI, lenJ, lenK) ->
            ((lenI < lenJ) && (lenJ < lenK))
            && (lenI + lenJ > lenK))
        |> Seq.length

printfn "%d" ans


Measured memory_bytes: 35752
import numpy as np
N,W = map(int,input().split())

dp = np.full(N*10**3+1, W+1, dtype = np.int64)
dp[0] = 0

for i in range(N):
    w,v = map(int,input().split())
    np.minimum(dp[:-v]+w, dp[v:], out = dp[v:])

for i in range(N*10**3+1):
    if dp[i] <= W:
        ans = i
print(ans)


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

using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0; i<N; i++)
    cin >> A[i];
  //ここまで入力

  //数字intが紙に書かれているかどうかをboolで表す
  map<int, bool> m;
  
  //与えられた数字があれば消す
  //なければ書く
  for(int i=0; i<N; i++)  
    m[A[i]-1 ] = !m[A[i]-1];

  //紙に書かれているものの数を数える
  int count = 0;
  for(auto map : m)
    if(map.second == true)
      count++;

  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  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;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(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;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

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

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

int X;
void solve() {
  cin >> X;
  long long ans = 0;
  while(true){
    if(X >= 500){
      X -= 500;
      ans += 1000;
    } else{
      break;
    }
  }
  while(true){
    if(X >= 5){
      X -= 5;
      ans += 5;
    } else{
      break;
    }
  }
  cout << ans <<endl;
}

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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 1e5 )+10;
const int MOD  = int( 1e9 )+7;
const int oo   = INT_MAX;

int n, m;
int arr[ MAXN ];
bool ok[ MAXN ];

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( ".in", "r", stdin );
    //freopen( ".out", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif

  while( cin >> n >> m ) {
    for( int i = 0; i < n; ++i ) {
      arr[ i ] = 1;
      ok[ i ] = false;
    }
    ok[ 0 ] = true;
    for( int i = 0; i < m; ++i ) {
      int u, v; cin >> u >> v; --u; --v;
      ok[ v ] |= ok[ u ];
      arr[ u ]--; arr[ v ]++;
      if( arr[ u ] == 0 ) {
        ok[ u ] = false;
      }
    }
    int ans = 0;
    for( int i = 0; i < n; ++i ) {
      ans += ok[ i ];
    }
    cout << ans << '\n';
  }

  return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 1000
using namespace std;
char a[N][N];
int sum[26];
int n,m;
struct node{
	int x,y;
}d[4];
int main(){
	scanf("%d %d",&n,&m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			char c;
			scanf(" %c",&c);
			sum[c-'a']++;
		}
	bool bz=1;
	for (int i=1;i<=(n+1)/2&&bz;i++)
		for (int j=1;j<=(m+1)/2&&bz;j++){
			int tot=1;
			d[0].x=i,d[0].y=j;
			if (n-i+1!=i)d[tot].x=n-i+1,d[tot].y=j,++tot;
			if (m-j+1!=j)d[tot].x=i,d[tot].y=m-j+1,++tot;
			if (n-i+1!=i&&m-j+1!=j)d[tot].x=n-i+1,d[tot].y=m-j+1,++tot;
			int x=-1;
			for (int k=0;k<26;k++)
				if (tot<=sum[k]&&(x<0||sum[x]>sum[k]))x=k;
			if (x==-1){
				bz=0;
				break;
			}
			sum[x]-=tot;
			for (int k=0;k<tot;k++)
				a[d[k].x][d[k].y]=x+'a';
		}
	if (!bz){
		printf("No");
	}else{
			printf("Yes");
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




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

Measured memory_bytes: 256
<?php


fscanf(STDIN, "%d %d %d", $a, $b, $x);

$soko = $a * $a;
$d = $soko * $b;
$half = $d / 2;

if($x >= $half){
    $sa = $d - $x;
    $h = $sa / $soko * 2;

    $tan = $h / $a;

    $atan = rad2deg(atan($tan));
}else{
    $h = $x / ($a * $b) * 2;
    $tan = $b / $h;
    $atan = rad2deg(atan($tan));
}

echo sprintf("%.9f",$atan);

Measured memory_bytes: 4732
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	int now=0,mx=0,h;
	cin>>h;
	int t;
	For(i,1,n-1){
		cin>>t;
		if(t>h){
			now=0;
		}
		else{
			now++;
			mx=max(mx,now);
		}
		h=t;
	}
	cout<<mx<<"\n";
	return 0;
}





























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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
#define int ll

void no() {
	cout << "No";
	exit(0);
}

void read() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) no();

	if (4 * a * b >= (c - a - b) * (c - a - b)) no();
	cout << "Yes";
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

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

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

  int ans = 0;
  for(int i=0; i<=A; i++) {
    for(int j=0; j<=B; j++) {
      for(int k=0; k<=C; k++) {
        if(500*i+100*j+50*k==X) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256