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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  string S; cin >> S;
  string result = "Yes";
  if (N%2==1) result = "No";
  else {
    rep(i,N/2) if (S[i]!=S[i+N/2]) result = "No";
  }
  cout << result << endl;
  return 0;
}

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

i = 0
while i < n:
    if i == 0:
        if s1[i] == s2[i]:
            a = 3
            i += 1
            pre = 0
        else:
            a = 6
            i += 2
            pre = 1
    else:
        if pre == 0:
            a *= 2
            if s1[i] == s2[i]:
                i += 1
            else:
                pre = 1
                i += 2
        elif pre == 1:
            if s1[i] == s2[i]:
                pre = 0
                i += 1
            else:
                a *= 3
                i += 2

print(a%1000000007)

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

int h, w, n;

void show(vector<string> &grid)
{
	for (auto &s : grid){
		cout << s << endl;
	}
	puts("");
}

int cntw(vector<string> &grid, int i, int j)
{
	char c = grid[i][j];
	int res = 0;
	for (; j < w && grid[i][j] == c; j++){
		res++;
	}
	return res;
}

int cnth(vector<string> &grid, int i, int j)
{
	char c = grid[i][j];
	int res = 0;
	for (; i < h && grid[i][j] == c; i++){
		res++;
	}
	return res;
}

void drop(vector<string> &grid)
{
	for (int i = 1; i < h; i++){
		for (int j = 0; j < w; j++){
			if (grid[i][j] == '.') continue;
			for (int p = i; p > 0; p--){
				if (grid[p - 1][j] == '.'){
					swap(grid[p - 1][j], grid[p][j]);
				}
				else break;
			}
		}
	}
}

bool check(vector<string> &grid)
{
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (grid[i][j] != '.') return false;
		}
	}
	return true;
}

bool solve(vector<string> grid)
{	
	while (true){
		drop(grid);
		//show(grid);
		vector<vector<int>> f(h, vector<int>(w, 0));
		bool update = false;
		
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (grid[i][j] == '.') continue;
				int cnt = cntw(grid, i, j);
				if (cnt >= n){
					update = true;
					for (int k = 0; k < cnt; k++){
						f[i][j + k] = 1;
					}
				}
				cnt = cnth(grid, i, j);
				if (cnt >= n){
					update = true;
					for (int k = 0; k < cnt; k++){
						f[i + k][j] = 1;
					}
				}
			}
		}
		
		if (!update) return check(grid);
		
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (f[i][j]) grid[i][j] = '.';
			}
		}
	}
}

int main()
{
	cin >> h >> w >> n;
	vector<string> grid(h);
	for (int i = h - 1; i >= 0; i--){
		cin >> grid[i];
	}
	
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w - 1; j++){
			swap(grid[i][j], grid[i][j + 1]);
			if (solve(grid)){
				puts("YES");
				return 0;
			}
			swap(grid[i][j], grid[i][j + 1]);
		}
	}
	
	puts("NO");
}

Measured memory_bytes: 1208
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;

int main() {
  int64_t N, av, tot;
  cin >> N;
  cout << N * (N - 1) / 2 << endl;
}


Measured memory_bytes: 3188
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
		int N = int.Parse(Console.ReadLine());
		int[] a = new int[N];
		int[] b = new int[N];

        for(var i = 0; i < N; i++)
		{
			string[] input = Console.ReadLine().Split(' ');
			a[i] = int.Parse(input[0]);
			b[i] = int.Parse(input[1]);
		}

		int over = 0;
		int sum = 0;
		List<Tuple<int, int>> list = new List<Tuple<int, int>>();
        for(var i = 0; i < N; i++)
		{
			list.Add(new Tuple<int, int>(a[i], b[i]));
		}

		list.Sort((c, d) => c.Item2 - d.Item2);
        for(var i = 0; i < N; i++)
		{
			sum += list[i].Item1;
			if (sum > list[i].Item2)
			{
				over++;
				break;
			}

		}
		if (over > 0) { Console.WriteLine("No"); }
		else { Console.WriteLine("Yes"); }
	}
}





Measured memory_bytes: 27044
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
string s;
long long k;
void solve() {
    cin >> s >> k;
    for (long long i = 0; i < min((long long)s.length(), k); i++) {
        int tmp;
        tmp = stoi(s.substr(i, 1));
        if (tmp > 1) {
            printf("%d\n", tmp);
            return;
        }
    }
    printf("%d\n", 1);
    return;
}
//逆元を求める関数
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(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=100000007,MAX=305;
const ll INF=1LL<<60;

ll dp[MAX][MAX],cost[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W;cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++) cin>>S[i];
    
    ll ans=0;
    
    for(int k=0;k<W-1;k++){
        
        for(int i=0;i<=H;i++){
            for(int j=0;j<=H;j++){
                dp[i][j]=INF;
                cost[i][j]=INF;
            }
        }
        
        for(int i=0;i<=H;i++){
            cost[i][0]=0;
            cost[0][i]=0;
            dp[i][0]=0;
            dp[0][i]=0;
        }
        
        for(int i=1;i<=H;i++){
            for(int j=1;j<=H;j++){
                if(S[i-1][k]==S[j-1][k+1]) cost[i][j]=cost[i-1][j-1]+1;
                else cost[i][j]=cost[i-1][j-1];
            }
        }
        
        for(int i=1;i<=H;i++){
            for(int j=1;j<=H;j++){
                dp[i][j]=min({dp[i][j],dp[i-1][j]+cost[i][j],dp[i][j-1]+cost[i][j]});
            }
        }
        
        ans+=dp[H][H];
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 1920
# n = int(input())
a,b = map(int,input().split())
# A = list(map(int,input().split()))
# An = [list(map(int,input().split())) for i in range(n)]

if 13 <= a:
    print(b)
elif 6<= a <= 12:
    print(int(b/2))
else:
    print(0)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int WA[105000];
    bool AC[105000];
    int N,M;
    cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;
    for(int i = 1; i <= N; i++) {
        WA[i] = 0;
        AC[i] = false;
    }

    while(M--) {
        int p;
        string S;
        cin >> p >> S;
        if(AC[p]) continue;
        if(S == "AC") {
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        } else if(S == "WA") {
            WA[p]++;
        }
    }
    cout << ACnum << " " << WAnum << endl;


        
}

Measured memory_bytes: 768
import itertools
import math
import numpy as np
N, D = list(map(int, input().split()))

X = []
for i in range(N):
  X.append(list(map(int,input().split())))
  
select = list(itertools.combinations(X,2))
ans = 0

#距離を求める。
for i ,j in select:
  i = np.array(i)
  j = np.array(j)
  u = i - j
  dist = np.linalg.norm(u)
  
#整数かどうかの判断  
  if dist.is_integer():
    ans += 1
  else:
    pass
  
print(ans)

Measured memory_bytes: 12392
n = int(input())
a = []
xy = []
for i in range(n):
    a += [int(input())]
    xy += [[list(map(int,input().split())) for i in range(a[i])]]
honest = []
for i in range(2 ** n):
    flag = 0
    for j in range(n):
        if (i >> j)&1 == 1: #j番目は正直であるとき
            for person_state in xy[j]:
              if (i >> (person_state[0]-1) & 1) != person_state[1]:
                  flag = 1 #矛盾が生じるとflagを立てる
                  break
    if flag == 0:
        honest += [bin(i)[2:].count("1")]
print(max(honest))

Measured memory_bytes: 9136
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <algorithm>
#include <ctime>  
using namespace std;  
char S[105][105];  
int xx[]={0,-1,0,1};  
int yy[]={-1,0,1,0};  
int N,M;  
clock_t start,finish; 
void dfs(int x,int y,char temp_c){              //同种水果再dfs，因此加上一个参数代表水果种类  
    int i,j,temp_x,temp_y;  
    S[x][y]='.';  
    for(i=0;i<4;i++)  
    for(j=0;j<4;j++){  
        temp_x=x+xx[i];  
        temp_y=y+yy[i];  
        if(S[temp_x][temp_y]!=temp_c||temp_x<0||temp_x>=N||temp_y<0||temp_y>=M)  
        continue;  
        dfs(temp_x,temp_y,temp_c);  
    }  
}  
int main(){ 
	start = clock();
    int i,j,sum;  
    while(cin>>N>>M&&(N||M)){  
        sum=0;  
        for(i=0;i<N;i++)  
        for(j=0;j<M;j++)  
        cin>>S[i][j];  
        for(i=0;i<N;i++)  
        for(j=0;j<M;j++)  
        if(S[i][j]!='.'){  
        dfs(i,j,S[i][j]);  
        sum++;  
        }  
        printf("%d\n",sum);  
    }
	finish = clock();
	//cout << finish-start   << "/" << CLOCKS_PER_SEC  << " (s) "<< endl;  
    return 0;  
}  


Measured memory_bytes: 3732
#include <cstdio>
#include <utility>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n';)s+=c;return s;}
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;if((c=gcu())=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i, n) for(int i{},i##_e{n};i<i##_e;i++)

struct d {int c, a;};

int main() {
	int D {in}, N {in};
	vector<int> T(D);
	array<vector<int>, 61> W {};
	vector<vector<d>> dp(D);
	for (int &i: T)
		i = in;
	times (i, N)
		for (int j {in}, e {in}, c {in}; j <= e; j++)
			W[j].push_back(c);
	for (int i: W[T[0]])
		dp[0].push_back({i, 0});
	for (int i: range(1, D))
		for (int j: W[T[i]]) {
			int a {};
			for (d k: dp[i - 1])
				a = max(a, abs(j - k.c) + k.a);
			dp[i].push_back({j, a});
		}
	int r {};
	for (d i: dp.back())
		r = max(r, i.a);
	outl(r);
}


Measured memory_bytes: 2788
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define range(i,a,b) for(int i = (a);i <= (b);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
#define vi vector<int>
#define vl vector<long long>
#define vd vector<double>
#define vp vector<pair<int,int> >
#define ll long long
#define pi pair<int,int>
#define popcnt(x) __builtin_popcountll(x)
#define LSOne(x) ((x) & (-(x)))
#define xx first
#define yy second
#define PQ priority_queue
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prp(p) cerr << "(" << (p).first << " ," << (p).second << ")";
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
using namespace std;

vi L;
int n;

int main(){
	#ifdef HOME
		freopen("in.in", "r", stdin);
	#endif
	scanf("%d",&n);
	map<int,int> cnt;
	loop(i,n) {
		int x; scanf("%d",&x);
		cnt[x]++;
	}
	int mx = 0,mx2 = 0;
	for(auto ptr = cnt.rbegin();ptr != cnt.rend();ptr++){
		if(ptr->second >= 2) {
			mx = ptr->xx;
			break;
		}
	}
	cnt[mx] -= 2;
	for(auto ptr = cnt.rbegin();ptr != cnt.rend();ptr++){
		if(ptr->second >= 2) {
			mx2 = ptr->xx;
			break;
		}
	}
	cnt[mx2]--;
	cout << mx*1LL*mx2 << endl;
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  int i,s=0,d;
  i=a.size();
  for(d=0;d<i;d++){
      if(a[d]!=b[d])s+=1;
  }
  cout<<s;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

  reverse(S.begin(), S.end());
  for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

  bool can = true;
  for (int i = 0; i < S.size();) {
    bool can2 = false;
    for (int j = 0; j < 4; ++j) {
      string d = divide[j];
      if (S.substr(i, d.size()) == d) {
        can2 = true;
        i += d.size();
      }
    }
    if (!can2) {
      can = false;
      break;
    }
  }

  if (can) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

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

#define UN unsigned
#define ll long long
#define mod 1000000007
#define pii pair<int, int>
#define pb push_back
//~ #define x first
//~ #define y second
const int N = 1e7 + 1;

int main(void) {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n = 0;
	cin >> n;
	vector<int> d(N, 2);
	ll ans = 1;
	for(int i=2; i<=n; i++){
		ans += 1LL * d[i] * i;
		for(int j=2; j*i <= n; j++) {
			d[i*j]++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 42240
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
  int a, b, c, d;
  cin >> a >> b;
  c=b-a;
  d=(c*(c+1))/2;
  cout << d-b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const double EPS = 1e-10;

int main(void)
{
    int N;
    double D;
    cin >> N >> D;

    int cnt = 0;
    double X, Y;
    double sum;
    for (int i = 0; i < N; i++)
    {
        cin >> X >> Y;
        sum = sqrt(pow(X, 2) + pow(Y, 2));
        if (sum <= D)
        {
            // printf("ans : %lf %lf\n", X, Y);
            cnt++;
        }
    }
    cout << cnt << endl;
    return (0);
}

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

int main() {
  int64_t b;

  while (cin >> b, b) {
    for (int d = 100001; d > 0; --d) {
      int64_t a = (2 * b + d - d * d) / (2 * d);
      if (a <= 0) continue;
      if ((a + d) * (a + d - 1) - a * (a - 1) == 2 * b) {
        cout << a << " " << d << endl;
        break;
      }
    }
  }
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define vi vector<int>
#define ppi pair<int,pi>
#define ld long double
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << end
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define f(i, begin, end) for (__typeof(end) i = (begin); i != (end) ; i += 1 - 2 * ((begin) > (end)))
#define nl cout<<"\n";
#define endl "\n"
#define par(a,n) f(i,0,n) cout<<a[i]<<" "; nl
//void prt(int x) {cerr << x;}
#define vv(n,m) vector <vector <int> > v(n, vector <int> (m));

#define er(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... brgs>
void err(istream_iterator<string> it, T a, brgs... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);	
}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef pair<int,int> pii;
typedef vector<pii> vpii;
const int mod = 1000000007;
const int N = 3e5;

// int kadane(int*a, int n);
// bool isPrime(int n);
// int mpow(int a, int b);

int cmp(int a, int b){
  return a>b;
}

void solve(){
  int n;
  cin>>n;
  cout<<n+n*n+n*n*n<<endl;

}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--)
    solve();
        
}

int mpow(int a, int b){ /* pow(a, b) % m */
  int m=mod;
  int x=1;
  while (b>0){
    if (b&1){
      x=(x * a) % m;
    }
    a=(a*a) % m; /* compute the next power of 2 */
    b>>=1; /* this is equivalent to b = floor(b / 2) */
  }
  return x;
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
} 

int kadane(int*a, int n){
    int max_so_far = INT_MIN, max_ending_here = 0;
    f(i,0,n){
        max_ending_here+=a[i];
        max_so_far = max(max_so_far, max_ending_here);
        if(max_ending_here<0) max_ending_here=0;
    }
    return max_so_far;
}

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

int main(){
  string s;
  cin >> s;
  int n=s.size();
  int a=0,b=0,c=0;
  for(int i=0;i<n;i++){
    if(s[i]=='a') a++;
    else if(s[i]=='b') b++;
    else c++;
  }
  if(abs(a-b)<2&&abs(a-c)<2&&abs(c-b)<2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n; cin >> n;
    ll A[100100];
    ll S = 0;
    ll ans[100100];
    for(int i=1;i<=n;i++){
        cin >> A[i];
        S += A[i];
    }
    ll sum = 0;
    for(int i=2;i<=n-1;i+=2) sum += A[i];
    ans[1] = S - 2*sum;
    for(int i=2;i<=n;i++) ans[i] = 2*A[i-1] - ans[i-1];

    for(int i=1;i<=n;i++){
        if(i > 1) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2944
def qsimulator(s, a, b):
	paas = 0
	bpaas = 0
	aflg = True
	bflg = True
	total = a + b
	res = []
	for i in s:
		if i == 'c':
			res.append("No")
		elif i == 'a':
			if aflg and paas < total:
				paas += 1
				res.append("Yes")
			else:
				aflg = False
				res.append("No")
		else:
			if bflg and paas < total and bpaas < b:
				paas += 1
				bpaas += 1
				res.append("Yes")
			else:
				bflg = False
				res.append("No")
	return res
n, a, b = map(int, input().split())
s = input()
ans = qsimulator(s, a, b)
for i in ans:
	print(i)

Measured memory_bytes: 9952
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto a = readln.split.to!(int[]);

    auto cnt = new int[](8);
    int ov;
    foreach (i ; 0 .. N) {
        if (a[i] >= 3200) {
            ov++;
        }
        else {
            auto k = a[i] / 400;
            cnt[k]++;
        }
    }

    auto mn = cnt.count!"a > 0";
    auto mx = mn + ov;

    if (mn == 0) {
        writeln(1, " ", ov);
        return;
    }
    
    writefln("%s %s", mn, mx);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())

void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}

int gcd(int x,int y){
    return __gcd(x,y);
}

void test_case(){
    int n;
    cin>>n;
    lld sum=0;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            for(int k=1;k<=n;++k){
                sum+=gcd(i,gcd(j,k));
            }
        }
    }
    test(sum);
}

int main(){
    fastio;
    file();
    int T=1;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
    //     cout<<"Case #"<<nr<<": ";
		test_case();
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<ll> A(N), cnt(N + 1, 0), check(N + 1, 0);
    rep(i, N) {
        cin >> A[i];
        cnt[A[i]]++;
    }

    ll ans = 0;
    rep(i, N) {
        if (check[A[i]] == 0) {
            ans += (cnt[A[i]] * (cnt[A[i]] - 1)) / 2;
            check[A[i]] = 1;
        }
    }

    rep(i, N) {
        if (cnt[A[i]] == 1) {
            cout << ans << endl;
        }
        else {
            ll st = cnt[A[i]] - 1;
            ll o = (cnt[A[i]] * (cnt[A[i]] - 1)) / 2;
            ll n = (st * (st - 1)) / 2;
            cout << ans - (o - n) << endl;
        }
    }

    return 0;
}

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

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

    pair<ll, ll> points[N];
    vector<ll> x_points, y_points;
    rep(i, 0, N)
    {
        ll x, y;
        cin >> x >> y;
        points[i] = make_pair(x, y);
        x_points.push_back(x);
        y_points.push_back(y);
    }

    sort(x_points.begin(), x_points.end());
    sort(y_points.begin(), y_points.end());

    ll ans = 5000000000000000000;
    rep(i, 0, N)
    rep(j, i + 1, N)
    rep(k, 0, N)
    rep(l, k + 1, N)
    {
        ll x_min = x_points[i];
        ll x_max = x_points[j];
        ll y_min = y_points[k];
        ll y_max = y_points[l];

        int cnt = 0;
        rep(m, 0, N)
        if (x_min <= points[m].first and points[m].first <= x_max)
        if (y_min <= points[m].second and points[m].second <= y_max)
            cnt++;

        if (cnt >= K)
            ans = min(ans, (y_max - y_min) * (x_max - x_min));
        // if (cnt >= K)
        //     cout << x_min << ' ' << x_max << ' ' << y_min << ' ' << y_max << ' ' << cnt << ' ' << (y_max - y_min) * (x_max - x_min) << ' ' << k << endl;
    }

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

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

#define tnum long long

#define loop(i,end) for(int i = 0; i < end; i++)

tnum *inputNumbers(tnum num) {
	tnum *ret;
	ret = (tnum *)malloc(num * sizeof(num));
	loop(i, num) {
		scanf("%lld", &ret[i]);
	}
	return ret;
}


/*main code*/


int main(int argc, char *argv[]) {
	tnum l;
	tnum res;
	double r;

	scanf("%lld", &l);
	
	r = l * l * l / 27.0;

	printf("%.10f", r);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
ll x[16],y[16],p[16];
vector<int> a;
vector<ll> ans;

void dfs(const vector<vector<ll>> &dx, const vector<vector<ll>> &dy) {
    if (a.size() == n) {
        int cnt = 0;
        ll xmask = 0, ymask = 0;
        rep(i,n) {
            if (a[i] == 1) {
                ++cnt;
                xmask |= (1ll << i);
            }
            if (a[i] == 2) {
                ++cnt;
                ymask |= (1ll << i);
            }
        }

        ll tmp = 0;
        rep(i,n) {
            ll res = LINF;
            if (a[i] == 0) {
                chmin(res, dx[xmask][i]);
                chmin(res, dy[ymask][i]);
                tmp += res*p[i];
            }
        }
        chmin(ans[cnt], tmp);
        return;
    }

    rep(i,3) {
        a.push_back(i);
        dfs(dx,dy);
        a.pop_back();
    }
    return;
}

int main(int argc, char const *argv[]) {
    scanf("%d", &n);
    ans.assign(n+1, LINF);
    rep(i,n) scanf("%lld %lld %lld", x+i,y+i,p+i);

    vector<vector<ll>> dx((1<<n), vector<ll>(n, LINF));
    vector<vector<ll>> dy((1<<n), vector<ll>(n, LINF));
    for (int bit = 0; bit < (1<<n); ++bit) {
        vector<int> X{0},Y{0};
        rep(i,n) if (bit & (1<<i)) {
            X.push_back(x[i]);
            Y.push_back(y[i]);
        }

        vector<ll> p(n);
        rep(i,n) if (!(bit & (1<<i))) {
            ll tmp = LINF;
            for (auto &&e: X) chmin(dx[bit][i], abs(e-x[i]));
            for (auto &&e: Y) chmin(dy[bit][i], abs(e-y[i]));
        }
    }

    dfs(dx,dy);


    for (auto &&e: ans) cout << e << '\n';

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const long long INF = 1e18;


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int n,m,l; cin >> n >> m >> l;
	vector<vector<ll> > adj(n,vector<ll>(n,INF));

	int from,to,weight;
	for(int i = 0; i < m; ++i){
		cin >> from >> to >> weight;
		--from;--to;
		adj[from][to] = weight;
		adj[to][from] = weight;
	}

	for(int k = 0; k < n; ++k){
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				if(adj[i][k] < INF && adj[k][j] < INF){
					adj[i][j] = min(adj[i][j],adj[i][k]+adj[k][j]);
				}
			}
		}
	}

	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			if(adj[i][j] <= l){
				adj[i][j] = 1;
			}
			else adj[i][j] = INF;
		}
	}

	for(int k = 0; k < n; ++k){
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				if(adj[i][k] < INF && adj[k][j] < INF){
					adj[i][j] = min(adj[i][j],adj[i][k]+adj[k][j]);
				}
			}
		}
	}

	int q; cin >> q;

	for(int i = 0; i < q; ++i){
		cin >> from >> to;
		--from;
		--to;
		if(adj[from][to] < INF){
			cout << adj[from][to]-1 << "\n";
		}
		else cout << "-1\n";
	}


    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int n,m,sum=0,ans=0,x;
  cin>>n>>m;
  int a[n]={};
  r(i,m){
    cin>>x;
    x--;
    a[x]=1;
  }
  r(i,n){
    if(!a[i])a[i]=1,sum++;
    else{
      ans=max(ans,sum);
      break;
    }
  }
  sum=0;
  for(int i=n-1;i>=0;i--){
    if(!a[i])a[i]=1,sum++;
    else{
      ans=max(ans,sum);
      break;
    }
  }
  int p=0;
  r(i,n){
    if(!a[i])p++;
    else{
      ans=max(ans,(p+1)/2);
      p=0;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3488
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int _;
  cin >> _;
  while(_--){
    ll A,B;
    cin >> A >> B;
    if(A == B){
      cout << (A-1)*2 << "\n";
      continue;
    }
    ll ok=0,ng=(ll)inf*10;
    while(ng-ok > 1){
      ll mid = (ng+ok)/2;
      ll now = (mid+1)/2 * (mid+1-(mid+1)/2);
      if(now < A*B){
        ok = mid;
      }else{
        ng = mid;
      }
    }
    cout << ok-1 << "\n";
  }
  return 0;
}

Measured memory_bytes: 3668
import sys
N = int(input())
A = list(map(int,input().split()))

for i in range(len(A)):
	if A[i] % 2 == 0:
		# 偶数
		if A[i] % 3 == 0 or A[i] % 5 == 0:
			pass
		else:
			print('DENIED')
			sys.exit()

print('APPROVED')

Measured memory_bytes: 3060
//#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main() {
	int n, m, sum = 0;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a; cin >> a;
		sum += a;
	}
	cout << ((n - sum) >= 0 ? n - sum : -1) << endl;;
}

Measured memory_bytes: 3628
import numpy as np
N = int(input())
Matrix = np.zeros((9, 9), dtype=np.int64)

for n in range(N + 1):
    if not n % 10:
        continue
    string = str(n)
    first = int(string[0])
    last = int(string[-1])
    Matrix[first - 1][last - 1] += 1

print((Matrix * Matrix.T).sum())


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

int main(){
    int r,g,b;
    cin >> r >> g>>b;
    if((r*100+g*10+b)%4 == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<map> 
using namespace std;
int a[100005];
map<int,int>mp;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		mp[a[i]]++;
	}
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		if(mp[a[i]]<a[i])
		{
			sum+=mp[a[i]];
		}
		else
		{
			sum+=mp[a[i]]-a[i];
		}
		mp[a[i]]=0;
		//printf("%d\n",sum);
	}
	printf("%d\n",sum);
	return 0;
}

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

#define endl '\n'
#define PI acos(-1.0)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	
	ull n;
	cin >> n;
	
	ull sum = 0;
	for(ull i = 1; i <= n; ++i) {
		if(i % 3 != 0 && i % 5 != 0) {
			sum += i;
		}
	}
	
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=1e5+7;
int ans=0;
int k;
int vis[50][maxn];
void dfs(int sum,int rem)
{
    if(sum>ans) return;
    if(vis[sum][rem]) return;
    if(!rem&&sum) ans=min(ans,sum);
    vis[sum][rem]=1;
    for(int j=0;j<10;j++)
    {
        if(sum==0&&j==0) continue;
        dfs(sum+j,(rem*10+j)%k);
    }
}
int main()
{
    cin>>k;
    int tmp=k;
    while(tmp)
    {
        ans+=tmp%10;
        tmp/=10;
    }
    dfs(0,0);
    print(ans);
}

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

typedef long long int ll;
ll powk(ll a, ll n){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll cnt = 0, x, k = 0;
    cin >> x;

    vector<pair<ll,bool>> ps(100100);
    for(ll i = 0;i < ps.size();i++){
        ps[i].first = i;
        ps[i].second = true;
    }
    vector<ll> p(1);
    p[0] = 2;

    while(p[k] * p[k] <= 100100){
        for(ll i = 2;i < ps.size();i++){
            if(ps[i].first % p[k] == 0){
                ps[i].second = false;
            }
        }
        for(ll i = p[k] + 1;i < ps.size();i++){
            if(ps[i].second){
                p.push_back(i);
                k++;
                break;
            }
        }
    }

    for(ll i = 0;i < p.size();i++){
        if(p[i] >= x){
            cout << p[i]<<endl;
            return 0;
        }
    }

    for(ll i = 0;i < ps.size();i++){
        if(ps[i].second && ps[i].first >= x){
            cout << ps[i].first;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
from itertools import combinations
from collections import Counter

while True:
    N, M = map(int, input().split())
    if N == M == 0:
        break

    L = [0]
    C = [0]
    x = 0
    y = 0
    count = 0
    
    for i in range(N):
        l = int(input())
        x += l
        L.append(x)

    dL = Counter([max(x1, x2) - min(x1 ,x2) for (x1, x2) in combinations(L, 2)])

    for i in range(M):
        c = int(input())
        y += c
        C.append(y)
    for y1, y2 in combinations(C, 2):
        dy = max(y1,y2)-min(y1,y2)
        if dy in dL:
            count += dL[dy]


    print(count)

Measured memory_bytes: 79516
#include<bits/stdc++.h>
using namespace std;
int main(){
	int A,N;
	cin>>N>>A;
	if(N%500==0)
		cout<<"Yes"<<endl;
	else if(N%500<=A)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
X= input()
T_count=X.count("T")
S_count=X.count("S")
T_removed=0
i=0
ans=0
while i<len(X):
    if X[i]=="T":
        if T_removed>0:
            T_removed -=1
        else:
            T_count -= 1
            ans+=1
    elif X[i]=="S":
        if T_count:
            T_count-=1
            T_removed+=1
        else:
            ans+=1
    i+=1
print(ans)


Measured memory_bytes: 3500
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

vector<int> minfactor(1000001,-1);
vector<bool> isprime(1000001,true);

void init(void) {
    // osa_k method
    isprime[0] = false; isprime[1] = false;
    minfactor[1] = 1;
    for (int i=2;i<=1000000;i++) {
        if (isprime[i]) {
            minfactor[i] = i;
            for (int j=2*i;j<=1000000;j+=i) {
                isprime[j] = false;
                minfactor[j] = i;
            }
        }
    }
}

multiset<int> prime(ll X) {
    multiset<int> res;
    int i = minfactor[X];
    while (X > 1) {
        res.insert(i);
        X /= i;
        i = minfactor[X];
    }
    return res;
}

vector<int> lcm(vector<int> A, multiset<int> B) {
    vector<int> res1;
    // 最小公倍数は A と B の和集合
    set_union(A.begin(),A.end(),B.begin(),B.end(),inserter(res1, std::end(res1)));
    // multiset<int> res2(res1.begin(),res1.end());
    return res1;
}

ll div(vector<int> V, multiset<int> X) {
    vector<int> D;
    // 割り算は A と B の差集合
    set_difference(V.begin(),V.end(),X.begin(),X.end(),inserter(D,D.end()));
    // for (auto itr: X) {
    //     V.erase(lower_bound(V.begin(),V.end(),itr));
    // }
    ll res = 1;
    for (auto itr: D) {
        res *= itr;
        res %= MOD;
    }
    return res;
}

int main(void) {
    int N;
    vector<ll> A(10010);
    cin >> N;
    for (int i=0;i<N;i++) cin >> A[i];
    init();
    // cout << "init" << endl;

    vector<multiset<int>> M(N);
    for (int i=0;i<N;i++) M[i] = prime(A[i]);
    // cout << "prime" << endl;
    // for (int i=0;i<N;i++) {
    //     cout << A[i] << endl;
    //     for (auto itr: M[i]) {
    //         cout << "\t" << itr.first << ": " << itr.second << endl;
    //     }
    // }
    vector<int> V(M[0].begin(),M[0].end());
    for (int i=1;i<N;i++) V = lcm(V,M[i]);
    // cout << "lcm" << endl;
    sort(V.begin(),V.end());
    ll res = 0;
    for (int i=0;i<N;i++) {
        res += div(V,M[i]);
        res %= MOD;
    }
    // cout << "div" << endl;
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 8448
#include <stdio.h>
int main(){
	int n,a,b,c,d;
	int e,f;
	int g,h;
	int i,j;
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	scanf("%d%d",&c,&d);
	e=n%a;
	f=n%c;
	
	if(e>0){
		g=n/a+1;
		h=g*b;
	}
	else{
		g=n/a;
		h=g*b;
	}
	
	if(f>0){
		i=n/c+1;
		j=i*d;
	}
	else{
		i=n/c;
		j=i*d;
	}
	
	if(h>j){
		printf("%d\n",j);
	}
	else if(h<j){
		printf("%d\n",h);
	}
	else{
		printf("%d\n",j);
	}
		
	return 0;
}


Measured memory_bytes: 2128
L = int(input())
a=[int(input()) for i in range(L)]
if L == 1:
    print(0)
    exit()

#累積和
rightsum = [0]*(L+1)
leftsum = [0]*(L+1)
for i in range(1,L+1):
    rightsum[i] = rightsum[i-1]+a[i-1]
    leftsum[i] = leftsum[i-1]+a[L-i]

#Re:戻ってくる Go:戻ってこなくてもよい
Reright = [0]
Goright = [0]
for i in range(L):
    if a[i] == 0:
        Goright.append(min(rightsum[i+1],1+min(Goright[-1],Reright[-1])))
        Reright.append(min(rightsum[i+1],2+Reright[-1]))
    else:
        Goright.append(min(rightsum[i+1],(a[i]+1)%2+min(Goright[-1],Reright[-1])))
        Reright.append(min(rightsum[i+1],a[i]%2+Reright[-1]))
        
Releft = [0]
Goleft = [0]
for i in range(L):
    if a[L-1-i]==0:
        Releft.append(min(leftsum[i+1],2+Releft[-1]))
        Goleft.append(min(leftsum[i+1],1+min(Goleft[-1],Releft[-1])))
    else:
        Goleft.append(min(leftsum[i+1],(a[L-1-i]+1)%2+min(Goleft[-1],Releft[-1])))
        Releft.append(min(leftsum[i+1],a[L-1-i]%2+Releft[-1]))
        
#候補cand
cand = []
for i in range(L+1):
    p1 = Reright[i]
    p2 = min(Reright[i],Goright[i])
    q1 = Releft[L-i]
    q2 = min(Releft[L-i],Goleft[L-i])
    cand.append(min(p1+q2,p2+q1))
    
print(min(cand))
    

Measured memory_bytes: 69576
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int n;

vector<pair<ll,ll> > data;
vector<pair<ll,pii> > s;
int main(){
	cin>>n;
	rep(i,n){
		ll a,b;
		cin>>a>>b;
		data.pb(mp(a,b));
		s.pb(mp(a,mp(0,i)));
		s.pb(mp(b,mp(1,i)));
	}
	sort(all(s));
	int mark[114514]={0};
	int acnt=0,bcnt=0;
	ll ans=0;
	rep(i,n){
		mark[s[i].second.second]=1;
		if(s[i].second.first)acnt++;
		else bcnt++;
		ans+=s[i].first;
	}
	bool check=true;
	rep(i,n){
		if(mark[i]==0)check=false;
	}
	if(check){
		if(acnt==n||bcnt==n){
			cout<<ans<<endl;
		}else{
			int num=s[n-1].second.second;
			int num2=s[n].second.second;
			if(num==num2){
				ans=min(ans-s[n-2].first+s[n].first,ans-s[n-1].first+s[n+1].first);
			}else{
				ans=ans-s[n-1].first+s[n].first;
			}
			cout<<ans<<endl;
		}
	}else{
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 7652