akhauriyash/Code-Regression huggingface dataset:
import sys
K=int(input())
if K%2==0 or K%5==0:
    print('-1')
    sys.exit()
i=1
K=9*K
ans=10-K

while(1):
    if 7*(ans-1)%K==0:
        print(i)
        sys.exit()
    i+=1
    ans=ans*10%K

Measured memory_bytes: 9092
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

num2alpha = lambda c: chr(c+64)

N = int(input())

anls = []
while N >= 1:
    ch = N%26
    if ch ==0:
        ch = 26
    anls.append(num2alpha(ch).lower())
    N = int((N-ch)/26)
anls = anls[::-1]
print(''.join(anls))


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

using namespace std;

int main() {
    int n, point_taro = 0, point_hanako = 0;
    cin >> n;
    string taro, hanako;
    for (int i = 0; i < n; ++i) {
        cin >> taro >> hanako;
        if (taro.compare(hanako) == 0) {
            point_taro++;
            point_hanako++;
        } else if (taro.compare(hanako) > 0) {
            point_taro += 3;
        } else {
            point_hanako += 3;
        }
    }
    cout << point_taro << ' ' << point_hanako << endl;
    return 0;
}


Measured memory_bytes: 3212
s=str(input())
if s[0]==s[1]:
    if s[0]!=s[2] and s[2]==s[3]:
        print('Yes')
    else:
        print('No')
elif s[0]==s[2]:
    if s[0]!=s[3] and s[1]==s[3]:
        print('Yes')
    else:
        print('No')
elif s[0]==s[3]:
    if s[0]!=s[1] and s[1]==s[2]:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3064
// selection sort

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int minj;
    int cnt = 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) {
            cnt++;
            swap(a[i], a[minj]);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << a[i];
        if (i != n - 1) cout << " ";
    }
    cout << endl;
    cout << cnt << endl;

    return 0;
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

char s[20];
int n, c;

int main() {
	n = readStr(s);
	for (int i = 0; i < n; ++i) {
		c += s[i] == 'x';
	}
	printStr(c <= 7 ? "YES" : "NO");
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;


void solve(){
    int n;
    cin >> n;
    double l = n/3.0;
    double ans = l*l*l;

    printf("%.12lf\n", ans);
}

int main(){
    //int t; cin >> t;
    //while(t--) solve();

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;

double p, q;
int a, n;

int func(double v, int st, int x, int d){
	int ret = 0;
	for(int i = st;;i++){
		if(i*x > a) break;
		if(v+1.0/i + EPS > p/q && v+1.0/i < p/q+EPS) ret++;
		else if(v+1.0/i < p/q && d < n-1){
			ret += func(v+1.0/i,i,i*x,d+1);
		}
	}
	return ret;
}

void solve(){
	cout << func(0,1,1,0) << endl;
}

int main(){
	while(true){
		cin >> p >> q >> a >> n;
		if(p == 0 && q == 0 && a == 0 && n == 0) break;
		solve();
	}
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int sum = 0;
  rep(i, 5) {
    int a; cin >> a;
    sum += a;
  }

  cout << 15 - sum << endl;
}


Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,i;
	cin>>a>>b>>c;
	i=a/1;
	while(a<=99999)
	{
		if(a%b==c){
		cout<<"YES"<<endl;
		return 0;
		}
		a=a+i;
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC optimize "-O3"
# define int long long
  
using namespace std;
  
const int N = 1e4 + 7;
const int mod = 1e9 + 7;

void solve() {
	int k, a, b;
	cin >> k >> a >> b;
	for ( int i = a; i <= b; i++ ) {
		if ( i % k == 0 ) {
			cout << "OK\n";
			return;
		}
	}

	cout << "NG";
}

int32_t main() {
	speed;
	int T = 1;
	// cin >> T;
	while ( T-- ) {
		solve();
	}
}

Measured memory_bytes: 3688
//YA TOH WOH AAGE SE LEGA YA PHIR PICHE SE
// TOH BAS USKA MAXIMUM NIKALNA HAI
// DP[I][J] MAXIMUM OF X-Y IN THE SUBARRAY FROM I TO J
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff first
#define ss second
#define eb emplace_back
#define MP make_pair
#define pb push_back
#define pf push_front
#define ins insert
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define tr(c,it) for(auto it=c.begin();it!=c.end();it++)
#define fr(i,n) for(lli i=0;i<(n);i++)
#define inc(i,a,b) for(lli i=a;i<=b;i++)
#define dec(i,a,b) for(lli i=a;i>=b;i--)
#define fr2(i,n) for(int i=0;i<(n);i++)
#define inc2(i,a,b) for(int i=a;i<=b;i++)
#define dec2(i,a,b) for(int i=a;i>=b;i--)
#define ymin(a,b)  (a=min((a),(b)))
#define ymax(a,b)  (a=max((a),(b)))
#define sz(x) (lli)(x).size()
#define error(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... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr<< *it << " = " << a << endl;
	err(++it, args...);
}

typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<lli,lli> plli;
typedef vector<lli> vlli;
typedef vector<int> vi;
//typedef  vector<vector<lli> >ncr(1001,vector<lli>(1001,0))
typedef vector<plli> vplli;
long long MOD=1000000009;
#define addm(x,y) (x+y>=MOD? (x+y-MOD):(x+y))
lli n;
lli a[3001];
lli dp[3001][3001];
lli vis[3001][3001];
lli solve(lli i,lli j)
{
	if(vis[i][j])
		return dp[i][j];
	vis[i][j]=true;
	if(i==j)
		return dp[i][j]=a[i];
	
	return dp[i][j]=max(a[i]-solve(i+1,j),a[j]-solve(i,j-1));
}
int main()
{
	// 	#ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS
	// clock_t start,end;
	// start=clock();
	// int t;
	// cin>>t;
	// for(int i=1;i<=t;i++)
	// {
	// 	cout<<"Case #"<<i<<": ";
	// 	solve();

	// }
	
	
	cin>>n;
	
	for(int i=0;i<n;i++)
		cin>>a[i];
	//mset(dp,-MOD*MOD);
	mset(dp,false);
	cout<<solve(0,n-1)<<endl;
	//cout<<dp[0][n-1]<<endl;
	
	// end=clock();
	
	// double time_taken=double(end-start)/double(CLOCKS_PER_SEC);
	// cout<<fixed<<setprecision(10)<<time_taken<<" sec"<<endl;
	
}


Measured memory_bytes: 120276
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<deque>
using namespace std;
const int maxn = 1000000 + 10;
 
int n, ans = 0;
char a[maxn], b[maxn];
deque <int> q;
 
int main() {
  scanf("%d", &n);
  scanf("%s%s", a + 1, b + 1);
  q.push_back(n + 1);
  for(int i = n, j = n + 1, del = 0;i >= 1;i --) {
    int tmp = j;
    while(j && (j > i || a[j] != b[i])) j --;
    if(!j) {
      puts("-1");
      return 0;
    }
    if(tmp == j) {
      while(!q.empty() && q.back() - del >= i) q.pop_back();
      q.push_back(i + del);
    }
    else {
      del ++;
      if(i != j) {
        ans = max(ans,(int)q.size());
        q.push_front(j + del);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 6272
# coding=utf-8
from __future__ import division
from math import sqrt


def main():
    d = input()
    x = map(int, raw_input().split())
    y = map(int, raw_input().split())
    z = [x - y for x, y in zip(x, y)]
    print sum([abs(w) for w in z])
    print sqrt(sum([w ** 2 for w in z]))
    print sum([abs(w) ** 3 for w in z]) ** (1 / 3)
    print max([abs(w) for w in z])


if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
/****************************************************************************************************************************************************/

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define MOD 1000000007
/********************************************************************************************************************************************************/


const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
/*********************************************************************************************************************************************************/
const ll mx=1e5+3;
ll t,n,w[mx][4];
ll dp[mx][4];
ll ks(ll i,ll we)
{
    if(i>n)
        return 0;
    if(dp[i][we]!=-1)
        return dp[i][we];
    ll c=0;
    for(int j=1; j<4; j++)
    {
        if(j!=we)
        {
            c=max(c,w[i][we]+ks(i+1,j));
        }
    }
    return dp[i][we]=c;
}

int main()
{
    optimize();
    for(int i=0; i<mx; i++)
    {
        for(int j=0; j<=4; j++)
            dp[i][j]=-1;
    }
    w[0][0]=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<4; j++)
            cin>>w[i][j];
    }
    cout<<ks(0,0)<<endl;

    return 0;
}






Measured memory_bytes: 17620
#include <iostream>
#include <string>
#include <algorithm>

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

  std::string S;
  std::cin >> S;

  int f = 0, m = 0;
  for (int i = 0; i < S.size(); i++) {
    auto c = S[i];
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
      f++;
    } else {
      f = 0;
    }
    m = std::max(f, m);
  }

  std::cout << m << std::endl;

  return 0;
}


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

int main(void)
{
    int N;
    float x[10];
    string u[10];
    float k = 380000.0;

    cin >> N;
    float sum = 0;
    for (int i = 0; i < N; ++i)
    {
        cin >> x[i] >> u[i];

        if (u[i] == "BTC")
        {
            sum += k * x[i];
        }
        else 
        {
            sum += x[i];
        }
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main (){

	long long int r;	
	scanf("%lld", &r);
	long long int a1[r];
	long long int a2 = 1;
	long long int max = 1000000000000000000;
	long long int hasil ;
	
	for(int j=0;j<r;j++){
		scanf("%lld", &a1[j]);
	}
	
	for(int h=0;h<r;h++){
	
		if(a1[h]==0){
			printf("0\n");
			return 0;
		}
	}
	for(int i=0;i<r;i++){
		if(a1[i]<=max/a2){	
		a2*= a1[i];	
		}else{
		printf("-1\n");
		return 0;
		}
	}
	
	printf("%lld\n", a2);

	return 0;
}

Measured memory_bytes: 2444
n,l = map(int, input().split())

a = [0] * n

for i in range(n):
    a[i] = l + i

total = sum(a)

ap = 100 * 2000

tmp = 0
for i in range(n):
    tmp = total - a[i]
    if abs(total - tmp) < ap:
        ap = abs(total - tmp)
        ans = tmp

print(ans)

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

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

int main(void){
    cin >> h >> w;
    vector<string> f(h);
    for(int i = 0; i < h; i++) cin >> f[i];
    vector<vector<int>> t(h, vector<int>(w, -1));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(f[i][j] == '.'){
                t[i][j] = 0;
                for(int k = 0; k < 8; k++){
                    int nx = i+dx[k];
                    int ny = j+dy[k];
                    if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
                    if(f[nx][ny] == '#') t[i][j]++;
                }
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(t[i][j] == -1) cout << '#';
            else cout << t[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3580
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, A, B = map(int, input().split())

    if not (B - A) % 2:
        ans = (B - A) // 2
    else:
        ans = min(A - 1, N - B)
        ans += (B - A + 1) // 2
    print(ans)


main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	int n, mp;
	cin >> n >> mp;
	int a = 0, b = 0;
	map<int, int> m;
	for(int i = 0; i < mp; i++) {
		int p;
		string s;
		cin >> p >> s;
		if(s == "AC" && m[p] <= 0) {
			a++;
			b -= m[p];
			m[p] = 1;
		}
		else if(m[p] <= 0) {
			m[p]--;
		}
	}
	cout << a << " " << b;

	return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		for(;;) {
		int a=scan.nextInt();
		if(a==0) {
			break;
		}
		double ans=0;
		int b[]=new int[a];
		double sum=0;
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
			sum+=b[i];
		}
		double hei=sum/a;
		for(int i=0;i<a;i++) {
			ans+=Math.pow(b[i]-hei,2);
		}
		ans=Math.sqrt(ans/a);
		System.out.println(ans);
	}
		}
}


Measured memory_bytes: 31480
#include <bits/stdc++.h>
#define int long long int
using namespace std;

#define int long long int
#define REP(i, n) for (int i(0); i < n; ++i)
#define REQ(i, a, b) for (int i(a); i <= b; ++i)


signed main(){
	int a,b,k,c;
	cin >> a>> b >> k;
	cout << max((long long)0,a-k) << " " <<  max((long long)0,b-max(k-a,(long long)0));
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){

    int S, h, m, s;
    scanf("%d\n", &S);
    
    h = S / 3600;
    S = S % 3600;
    
    m = S / 60;
    S = S % 60;
    
    s = S;
    
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>
int main(void)
{
  double a,b,c,d,e,f,x,y;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF)
  {
    y=(c*d-f*a)/(b*d-e*a);
    x=(c-b*y)/a;
    printf("%.3lf %.3lf\n",x,y);
  }
}

Measured memory_bytes: 1808
import heapq

class Adjlist_weighted():

    def __init__(self, nodes, edges = None):
        self.nodes = nodes
        lis = [{} for i in range(nodes)]
        if edges is not None:
            for edge in edges:
                lis[edge[0]][edge[1]] = edge[2]
        self.edges = lis

    def add_edge(self, edge):
        self.edges[edge[0]][edge[1]] = edge[2]
        self.edges[edge[1]][edge[0]] = edge[2]
        return self

    def next_edges(self,x):
        return self.edges[x]

class Min_span_tree():

    def __init__(self, graph):
        min_span_tree = Adjlist_weighted(graph.nodes)
        searched_nodes = [False]*graph.nodes
        start = 0
        heap = [(0, start, start)]
        total_length = 0
        while heap:
            (cost, now, prev) = heapq.heappop(heap)
            if not searched_nodes[now]:
                searched_nodes[now] = True
                if (now, prev) != (start, start):
                    min_span_tree.add_edge((prev, now, cost))
                cand = graph.next_edges(now)
                total_length += cost
                for next in cand:
                    if not searched_nodes[next]:
                        heapq.heappush(heap, (cand[next], next, now))
        self.min_span_tree = min_span_tree
        self.total_length = total_length
    

(V, E) = tuple(map(int, input().split(" ")))
graph = Adjlist_weighted(V)
for _ in range(E):
    graph.add_edge(tuple(map(int, input().split(" "))))
mst = Min_span_tree(graph)
print(mst.total_length)


Measured memory_bytes: 33668
N, M = map(int, input().split())
S = []
for i in range(M):
    S.append(tuple(map(int, input().split())))

S = sorted(S, key=lambda x: x[1])
res = 1
cur = S[0][1]
for i in range(M):
    if S[i][0] < cur:
        continue
    cur = S[i][1]
    res += 1

print(res)


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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n;
vl h;
int main() {
    cin>>n;
    h.resize(n+1);

    ll hmax = 0;
    REP(i,n){
        cin>>h[i];
    }
    h[n] = 1e9; //max

    REP(i,n){
        if( h[i]-1 > h[i+1] || (hmax-1) > h[i]){
            cout << "No" << endl;
            return 0;
        }
        if(h[i] > hmax ) hmax = h[i];
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x,d,p,ans;
int main(){
	scanf("%lld%lld%lld",&n,&x,&d),p=d/abs(__gcd(x,d));
	if(!d)return printf("%d",x==0?1:n+1),0;
	if(d<0)x=-x,d=-d;
	for(ll i=0;i<=n;i++){
		ll l=i*(i-1)-n*(n-1)/2,r=(n-1)*n/2-(n-i)*(n-i-1);
		ll l1=(i-p)*(i-p-1)-n*(n-1)/2-2*x*p/d,r1=n*(n-1)/2-(n-i+p)*(n-i+p-1)-2*x*p/d;
		if(r<l1 or l>r1 or i<p)ans+=(r-l)/2+1;
		else{
			if(l<=l1 and l1<=r)ans+=(l1-l)/2;
			if(l<=r1 and r1<=r)ans+=(r-r1)/2;
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define LL long long
using namespace std; 
const int maxn = 20;
int h,w;
string s[maxn];
string t[maxn];
map<string, vector<int> >mp;
map<string, int> mp2;
int main()
{
  //  freopen("input.txt", "r", stdin);
    cin >> h >> w;
    for(int i = 0; i < h; i++) {
        cin >> s[i];
        t[i] = s[i];
        sort(t[i].begin(), t[i].end());
    }
    for(int i = 0; i < h; i++){
        mp[t[i]].pb(i);
        t[i].clear();
    }
    int cnt2 = 0, cnt1 = 0;
    if(h&1){
        int odd;
        for(auto p : mp){
            int sz = p.se.size(); 
            if(sz % 2 == 1){
                cnt1++;
                odd = p.se[sz-1];
                p.se.pop_back();
            }
            else cnt2++;
        }
        if(cnt1 != 1){
            puts("NO");
            return 0;
        }
        t[h/2] = s[odd];
    }
    int head = 0, tail = h-1;
    for(auto p : mp){
        int front, back;
       
        for(front = 0, back = p.se.size()-1; front < back; front++, back--){
            t[head++] = s[p.se[front]];
            t[tail--] = s[p.se[back]];
        }
    }
    for(int i = 0; i < w; i++){
        string temp1, temp2;
        for(int j = 0; j < h; j++) temp1 += t[j][i];
        temp2 = temp1;
        reverse(temp2.begin(), temp2.end());

        if(mp2.find(temp1) != mp2.end()){
            mp2[temp1]++;

        }

        else if(mp2.find(temp2) != mp2.end()){
            mp2[temp2]++;

        }

        else mp2[temp1] = 1;
    }
    cnt1 = cnt2 = 0;
    string ispail;
    for(auto p : mp2){

        if(p.se % 2) {cnt1++; ispail = p.fi;}
        else cnt2++;
    }

    if(w % 2 == 0){
        if(cnt1 != 0){

            puts("NO");
            return 0;
        }
        else{
            puts("YES");
            return 0;
        }
    }
    else{
        if(cnt1 == 1){
            head = 0, tail = ispail.length()-1;
            while(head < tail){
                if(ispail[head] != ispail[tail]){
                    puts("NO");
                    return 0;
                }
                head++,tail--;
            }
            puts("YES");
        }
        else{
            puts("NO");
            return 0;
        }
    }
    return 0;
}

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

typedef pair<int, int> P;
typedef pair<P, P> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int DX[4] = {-1, 0, 1, 0};
int DY[4] = {0, -1, 0, 1};

int H, W, K;
int SX, SY;
char A[800][800];
bool D[800][800];
//bool D[800][800][500];
set<P> used[800][800];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> H >> W >> K;
  rep(i, H) {
    rep(j, W) {
      char c;
      cin >> c;
      A[j][i] = c == '#';
      if (c == 'S') SX = j, SY = i;
    }
  }
  /*
  rep(x, W) {
    rep(y, H) {
      rep(k, 500) {
        D[x][y][k] = INF;
      }
    }
  }
  */
  queue<P2> q;
  q.push(P2(P(SX, SY), P(K, 0)));
  for (int steps=1; steps<500; steps++) {
    queue<P2> nq;
    //cout<<"steps="<<steps<<"\n";
    while (!q.empty()) {
      int x = q.front()._1._1, y = q.front()._1._2,
          moves = q.front()._2._1, brks = q.front()._2._2;
      q.pop();
      //cout<<"("<<x<<","<<y<<") move="<<moves<<", brks="<<brks<<" ("<<steps<<")\n";

      nq.push(P2(P(x, y), P(min(W*H, K), min(450, brks+K))));
      if(x==0||x==W-1||y==0||y==H-1) {
        cout << steps << "\n";
        return 0;
      }

      if (moves > 0) {
        rep(k, 4) {
          int nx = x+DX[k], ny = y+DY[k];
          if (nx<0||nx>=W||ny<0||ny>=H) continue;
          int nb = brks;
          if (A[nx][ny]) {
            if (nb == 0) continue;
            nb--;
          }
          if (D[nx][ny]) continue;
          D[nx][ny] = true;
          auto p = P2(P(nx, ny), P(moves-1, nb));
          if (used[nx][ny].find(P(moves-1,nb)) != used[nx][ny].end()) continue;
          used[nx][ny].insert(P(moves-1, nb));
          q.push(P2(P(nx, ny), P(moves-1, nb)));
        }
      }
    }
    swap(q, nq);
  }
  return 1;
}


Measured memory_bytes: 50176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		sc.close();
		if(S <= W) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}


	}
}

Measured memory_bytes: 35672
A, B, Q = map(int, input().split())
S = [0] * A
T = [0] * B
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
def lr_find(x, Y):
  if x < Y[0]:
    return [0, Y[0]]
  if x >= Y[-1]:
    return [Y[-1], 0]
  l, r = 0, len(Y) - 1
  while r - l > 1:
    m = (l + r) // 2
    if x < Y[m]:
      r = m
    else:
      l = m
  return [Y[l], Y[r]]
for q in range(Q):
  x = int(input())
  D = [lr_find(x, S), lr_find(x, T)]
  ans = 10 ** 12
  for i in range(8):
    s = D[0][i % 2]
    t = D[1][(i // 2) % 2]
    if s and t:
      dist = abs(s - t) + abs(x - [s, t][(i // 4) % 2])
      ans = min(dist, ans)
  print(ans)

Measured memory_bytes: 66264
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    ll a,b,k;
    cin >> a >> b;
    cin >> k;
    if(a>=k) a-=k;
    else{
        
        b = b-(k-a);
        if(b<0) b=0;
        a=0;
    }
    cout << a << " " << b;
}   

Measured memory_bytes: 256
import sys
import copy
import collections

# 素因数分解の結果をlistで返す
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    n = int(input())
    n_prime = prime_factorize(n)
    unique_n_prime = []
    unique_n_prime = [x for x in n_prime if x not in unique_n_prime and not unique_n_prime.append(x)]

    ans = 0
    ans += len(unique_n_prime)

    unique_c = collections.Counter(unique_n_prime)

    c = collections.Counter(n_prime)
    c = c - unique_c
    t = 1
    while len(c) > 0:
        for _ in range(t):
            c = c - unique_c
        ans += len(c)
        c = c - unique_c
        t += 1

    print(ans)



if __name__ == '__main__':
    main()

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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    rep(i, N + 1) {
        if (i*i > N) break;
        ans = max(i*i, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int bitArray[] = new int[n];

		int k = sc.nextInt();

		int mask[] = new int[k];
		for(int i = 0; i < k; i++) {
			mask[i] = sc.nextInt();
		}

		for(int i = 0; i < Math.pow(2, n); i++) {
			int temp = i;
			for(int j = 0; temp > 0; j++) {
				bitArray[j] =  temp % 2;
				temp /= 2;
			}

			boolean flag = false;  //bitArrayがmaskに当てはまっていなかったら反転
			for(int j = 0; j < k; j++) {
				if(bitArray[mask[j]] == 0) {
					flag = true;
					break;
				}
			}

			if(!flag) {
				System.out.print(i + ":");  //順列のインデックス
				for(int j = 0; j < n; j++) {
					if(bitArray[j] == 1) System.out.print(" " + j);
				}
			}
			if(!flag) System.out.println();
		}
	}

}



Measured memory_bytes: 64084
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; 
typedef long long int ll;
#define ull unsigned long long int
#define all(a) a.begin(),a.end()s
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define hell 1000000007
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define pb push_back
#define MAX 10000001
int main()
{
    ll n;
    cin>>n;
    ll a[200001]{0},inp[n];
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        inp[i]=x;
        a[x]++;
    }
    ll ans = 0;
    for(ll i=0;i<200001;i++)
    {
        ans = ans + (a[i]*(a[i]-1))/2;
    }
    for(ll i=0;i<n;i++)
    {
        ll fans = ans;
        fans = fans - (a[inp[i]]*(a[inp[i]]-1))/2;
        fans = fans + ((a[inp[i]]-1)*(a[inp[i]]-2))/2;
        cout<<fans<<endl;
    }

}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    int n;
    cin>>n;
    int a[n];
    vector<int>rev,nor;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i%2==0)nor.push_back(a[i]);
        else rev.push_back(a[i]);
    }
    if(n%2==0){
        reverse(rev.begin(),rev.end());
        for(int i=0;i<rev.size();i++)cout<<rev[i]<<" ";
        for(int i=0;i<nor.size();i++)cout<<nor[i]<<" ";
    }else{
        reverse(nor.begin(),nor.end());
        for(int i=0;i<nor.size();i++)cout<<nor[i]<<" ";
        for(int i=0;i<rev.size();i++)cout<<rev[i]<<" ";
    }
}


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

int main() {
  int N; int p[11];
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> p[i];
  int sum = 0, max = 0;
  for (int i = 0; i < N; ++i) {
    sum += p[i];
    if (p[i] > max) max = p[i];
  }
  int res = sum - max / 2;
  cout << res << endl;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N){
    int answer = 0;
    stack<int> s;
    ll n = 0, cntSum = 0;
    vector<int> cnt(10);
    s.push(0);
    while (!s.empty()) {
        ll current = s.top();
        s.pop();
        if (current>=0) {
            if (current!=0 && cntSum<10) {
                n += current * pow(10,cntSum);
                cnt[current]++;
                cntSum++;
            }

            if (n <= N && cnt[3]>0&&cnt[5]>0&&cnt[7]>0) answer++;

            if (n <= N) {
                for (const int j : {-3,3,-5,5,-7,7}) {
                    s.push(j);
                }
            }
        } else if (current<0) {
            cntSum--;
            cnt[-current]--;
            n -= -current * pow(10,cntSum);
        }
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

H,W = map(int, input().split())
HW = []
for i in range(H):
    HW.append(list(map(int, input().split())))

ans = []
for i in range(H):
    for j in range(W):
        # 該当マスが奇数
        if HW[i][j] % 2 != 0:
            if i != 0:
                if HW[i-1][j] % 2 != 0:
                    HW[i-1][j] += 1
                    HW[i][j] -= 1
                    ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i-1+1) + ' ' + str(j+1))
                    continue
            if j != 0:
                if HW[i][j-1] % 2 != 0:
                    HW[i][j-1] += 1
                    HW[i][j] -= 1
                    ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i+1) + ' ' + str(j-1+1))
                    continue
            if i != H-1:
                if HW[i+1][j] % 2 != 0:
                    HW[i+1][j] += 1
                    HW[i][j] -= 1
                    ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i+1+1) + ' ' + str(j+1))
                    continue
            # 最終的に周り全部偶数でも右隣りに移動
            if j != W-1:
                HW[i][j+1] += 1
                HW[i][j] -= 1
                ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i+1) + ' ' + str(j+1+1))
            # 右端だったら次の行(最終行以外)
            else:
                if i != H-1:
                    HW[i+1][j] += 1
                    HW[i][j] -= 1
                    ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i+1+1) + ' ' + str(j+1))

# 操作回数から出力
print(len(ans))
for s in ans:
    print(s)

Measured memory_bytes: 16364
#include <iostream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;


void solve(vector<uint64_t>& heights, size_t& count)
{
    bool flag  = false;

    for(size_t i = 0; i < heights.size(); i++)
    {
        if (! flag && heights[i] > 0) {
            flag = true;
            heights[i]--;
            count++;
            continue;
        }

        if (flag && heights[i] > 0) {
            heights[i]--;
            continue;
        }

        if (flag && heights[i] <= 0) {
            return solve(heights, count);
        }
    }

    if (flag) {
        // 全ての要素が1以上だった場合.
        return solve(heights, count);
    }

    return;
}

void test_max_case()
{
    vector<uint64_t> heights(100, UINT64_MAX);
    for(size_t i = 0; i < 100; i++)
    {
        if (i % 2 == 0) {
            heights[i] = 100;
        } else {
            heights[i] = 0;
        }
    }

    size_t count = 0;
    solve(heights, count);

    cout << count << endl;
}

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

    //test_max_case();

    size_t n = 0;
    cin >> n;
    assert(1 <= n && n <= 100);

    vector<uint64_t> heights(n, UINT64_MAX);
    for(size_t i = 0; i < n; i++)
    {
        uint64_t height = 0;
        cin >> height;
        assert(0 <= height && height <= 100);
        heights[i] = height;
    }

    size_t count = 0;
    solve(heights, count);

    cout << count << endl;

    return 0;
}

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

int main(){
    ll N; cin >> N;
    vector<ll> V(N); for(int i = 0; i < N; i++) cin >> V[i];
    sort(V.begin(), V.end());
    ll ans = V[N-1];
    ll cnt = 1;

    for(int i = N-2; i >= 0; i--){
        if(cnt == N-1) break;
        ans += V[i];
        cnt++;
        if(cnt == N-1) break;
        ans += V[i];
        cnt++;
        if(cnt == N-1) break;
    }
    cout << ans << endl;

}


Measured memory_bytes: 4836
CON_TYPE = 26
# 問題文の入力
D = gets.to_i
C = gets.split.map(&:to_i)
S = []
D.times do |d|
    S.push(Array.new(gets.split.map(&:to_i)))
end

def calc_one_day(open_type, lasts, day)
    sat_day = 0
    # puts "open_type: #{open_type}"
    CON_TYPE.times do |type|
        if(open_type == type)
            sat_day += S[day][type]
            lasts[type] = day
            # puts "sat_day: #{sat_day}"
            # puts "#{type.to_s} held. sat+=#{S[d][type]}"
        else
            sat_day -= C[type] * (day - lasts[type])
            # puts "sat-=#{C[type] * (d - lasts[type])}"
        end
    end
    sat_day
end

def calc_score(arg_array)
    opens = []
    D.times do |d|
        opens.push (arg_array[d].to_i - 1)
    end

    # 得点計算
    sat_list = [0]
    sat = 0
    lasts = Array.new(CON_TYPE, -1)
    D.times do |d|
        sat += calc_one_day(opens[d], lasts, d)
        sat_list.push sat
    end
    sat_list[1..-1] # 最初は0
end

# puts calc_score([1,17,13,14,13])

# 貪欲法
opens = []
lasts = Array.new(CON_TYPE, -1)
D.times do |d|
    max_sat = -99999999999
    max_type = -1
    CON_TYPE.times do |type|
        sat = calc_one_day(type, lasts, d )
        if max_sat < sat
            max_sat = sat
            max_type = type
        end
    end
    opens.push (max_type+1)
end
# puts "SCORE:"
# puts( calc_score(opens) )
# puts "ANS:"
puts opens


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

int main() {
  int n; cin >> n;
  
  int ans = 0;
  
  vector<int> v(n);
  for(int i = 0; i < n; i++){
    int temp; cin >> temp;
      v.at(i) = temp;
  }
  for(int i = 0; i < n; i++){
    int c; cin >> c;
    if(v.at(i) - c > 0) ans += v.at(i) - c;
  }
  
  
  cout << ans << endl;
  
}

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

int main(){
    int N;
    long long M = 0, A = 0, R = 0, C = 0, H = 0;
    long long sum;
    string S;
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> S;
        if (S[0] == 'M') M++;
        else if (S[0] == 'A') A++;
        else if (S[0] == 'R') R++;
        else if (S[0] == 'C') C++;
        else if (S[0] == 'H') H++;
    }
    sum += M * A * R;
    sum += M * A * C;
    sum += M * A * H;
    sum += M * R * C;
    sum += M * R * H;
    sum += M * C * H;
    sum += A * R * C;
    sum += A * R * H;
    sum += A * C * H;
    sum += R * C * H;

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;
const int INF = 1 << 30;

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

    int n = x.size();
    stack<char> st;
    
    rep(i, n) {
        if (x[i] == 'S') st.push(x[i]);
        else {
            if (!st.empty()) {
                if (st.top() == 'T') st.push(x[i]);
                if (st.top() == 'S') st.pop();
            }
            else {
                st.push(x[i]);
            }
        }
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 644
#include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define Rep(i,n) REP(i,0,n)
typedef long long ll;
     
int N,K;
int D[10];
int main(){
    cin>>N>>K;
    Rep(i,K){
        cin>>D[i];
    }
    while(1){
        int M=N;
        bool ok1=true;
        while(M>0){
            int a=M%10;
            bool ok=true;
            Rep(i,K){
                if(a==D[i]){
                    ok=false;
                }
            }
            if(ok){
                M/=10;
            }
            else{
                ok1=false;
                break;
            }
        }
        if(ok1) break;
        else{
            N++;
        }
    }
    cout<<N<<endl;
    return 0;
}

Measured memory_bytes: 256
def triangle(a, b, c):
    if a+b > c and b+c > a and c+a > b:
        if a**2 == b**2 + c**2:
            return 0
        elif a**2 < b**2 + c**2:
            return 1
        elif a**2 > b**2 + c**2:
            return 2
    else:
        return 3

ans = [0] * 3
while True:
    try:
        a, b, c = sorted(map(int, input().split()))[::-1]
        ans[triangle(a, b, c)] += 1
    except:
        break
print(sum(ans), *ans)



Measured memory_bytes: 5600
#include<cstdio>
using namespace std;
const int MAXN=20+3;
int n;
int v[MAXN],c[MAXN];
int dif[MAXN];
int ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&v[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&c[i]);
	}
	for(int i=1;i<=n;i++){
		dif[i]=v[i]-c[i];
	}
	for(int i=1;i<=n;i++){
		if(dif[i]>0){
			ans+=dif[i];
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6+100;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dominance true
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

string s;

int main(){
    migmig
    cin >> s;
    if(s[0] != 'h'){
        dokme("No");
    }
    if(s.size() %2){
        dokme("No")
    }
    for (int i = 0 ; i < s.size() ; i ++){
        if(i%2){
            if(s[i]!='i'){
                dokme("No")
            }

        }
        else{
            if(s[i]!='h'){
                dokme("No")
            }
        }
    }
    cout << "Yes";
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.
//kuxtal jach uts chuchul u u páajtal máak jach táaj meyajilo'ob le castigadas tumen ch'aik descansos.


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

using namespace std;

int main() {
    string s;
    cin >> s;
    for (int i = s.size() / 2 - 1; i >= 1; --i) {
        if (s.substr(0, i * 2) == s.substr(0, i) + s.substr(0, i)) {
            cout << i * 2 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
const int mxN=1e9;
const ll mod = 1e9+7;


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

    vector<ll> v(n);

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

    ll dp[n][n][2];

    for(int i=0;i<n;i++){
        dp[i][i][0] = v[i];
        dp[i][i][1] = 0;
    }

    for(int i=1;i<n;i++){
        for(int j=0;j+i<n;j++){
            if(dp[j+i][j+i][0]+dp[j][j+i-1][1]>dp[j][j][0]+dp[j+1][j+i][1]){
                dp[j][j+i][0]=dp[j+i][j+i][0]+dp[j][j+i-1][1];
                dp[j][j+i][1]=dp[j][j+i-1][0];
            }
            else{
                dp[j][j+i][0]=dp[j][j][0]+dp[j+1][j+i][1];
                dp[j][j+i][1]=dp[j+1][j+i][0];
            }
        }
    }

    cout<<dp[0][n-1][0]-dp[0][n-1][1];
}

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

using namespace std;
int cnt[100000];
int main(){
    int n, m,mx=0;
    cin >> n;
    long long a[n];
    deque <int > v;
    for(int i = 0 ;i < n;i++){
        cin >> a[i];
        cnt[a[i]]++;
        mx = max(cnt[a[i]], mx);
        a[i]--;
        cnt[a[i]]++;
        mx = max(cnt[a[i]], mx);
        a[i] += 2;
        cnt[a[i]]++;
        mx = max(cnt[a[i]], mx);
    }
    cout << mx;


    return 0;
}

Measured memory_bytes: 1408
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

inline int popcount(lint n) {
	n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555);
	n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333);
	n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f);
	n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff);
	n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff);
	n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff);
	return n;
}

int main() {

	lint N;
	string X;
	cin >> N >> X;

	lint cnt = 0;
	for (int i = 0; i < N; i++) {
		if (X[i] - '0') cnt++;
	}
	DMP(X, cnt);

	if (cnt == 0) {
		for (int i = 0; i < N; i++) {
			cout << 1 << "\n";
		}
		return 0;
	}

	vector<lint> remp(N), remm(N);
	lint rp = 1, rm = 1;
	for (int i = 0; i < N; i++) {
		remp[i] = rp;
		remm[i] = rm;
		rp <<= 1;
		rm <<= 1;
		rp %= cnt + 1;
		if (cnt != 1) rm %= cnt - 1;
	}
	DMP(remp, remm);

	lint sump = 0, summ = 0;
	reverse(remp.begin(), remp.end());
	reverse(remm.begin(), remm.end());
	for (int i = 0; i < N; i++) {
		if (X[i] - '0') (sump += remp[i]) %= cnt + 1;
		if (X[i] - '0' && cnt != 1) (summ += remm[i]) %= cnt - 1;
	}
	DMP(summ, sump);

	vector<lint> st(N);
	for (int i = 0; i < N; i++) {
		if (X[i] - '0') {
			if (cnt == 1) {
				st[i] = -1;
				continue;
			}
			st[i] = summ;
			st[i] -= remm[i];
			st[i] += cnt - 1;
			st[i] %= cnt - 1;
		}
		else {
			st[i] = sump;
			st[i] += remp[i];
			st[i] %= cnt + 1;
		}
	}

	for (int i = 0; i < N; i++) {
		if (st[i] < 0) {
			cout << 0 << "\n";
			continue;
		}
		int ans = 1;
		while (st[i]) {
			int p = popcount(st[i]);
			if (p == 0) break;
			st[i] %= p;
			ans++;
		}
		cout << ans << "\n";
	}

	return 0;
}



Measured memory_bytes: 8344