akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define MAXN (ll) 1e5 + 6ll
ll dp[MAXN];
int main()
{
  ll n, h[MAXN];
  cin >> n;
  for(ll i = 0; i < n; i++) cin >> h[i];
  for(ll i = 0+1; i < n; i++) dp[i] = (ll)1e18;
  for(ll i = 0; i < n; i++)
  {
    dp[i+1] = min(dp[i+1], dp[i] + llabs(h[i] - h[i+1]));
    dp[i+2] = min(dp[i+2], dp[i] + llabs(h[i] - h[i+2]));
  }
  cout << dp[n-1] << '\n';
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pil;
vector<pil> vec;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, x, y;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y;
        vec.push_back(pil(i, pll(x, y)));
    }
    long double dis = 0;
    for (int i = 1; i < vec.size(); ++i) {
        dis += sqrt(pow(vec[i].second.first - vec[i - 1].second.first, 2) + pow(vec[i].second.second - vec[i - 1].second.second, 2));
    }
    while (next_permutation(vec.begin(), vec.end())) {
        for (int i = 1; i < vec.size(); ++i)        
            dis += sqrt(pow(vec[i].second.first - vec[i - 1].second.first, 2) + pow(vec[i].second.second - vec[i - 1].second.second, 2));
    }
    long double d = 1;
    for (int i = 1; i <= n; ++i)
        d *= i;
    cout << fixed << setprecision(10) << dis / d << '\n';
    return 0;   
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main() {
    ll a, b;
    cin >> a >> b;
    auto mp = prime_factor(gcd(a, b));
    cout << 1 + mp.size() << "\n";
    return 0;
}

Measured memory_bytes: 3604
a, b, k = map(int, input().split())
def divide(n):
	divisors = []
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n//i)
	return divisors

aa = set(divide(a))
bb = set(divide(b))
c = aa & bb
cc = list(c)
cc.sort(reverse = True)
print (cc[k-1])

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

bool is_ok(int a, int b, int c){
    if(a < b && b < c){
        return true;
    }
    return false;
}

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

    int a = A;
    int b = B;
    int c = C;
    int i=0;
    while(i<K){
        if(a >= b){
            b*=2;
        }else{
            break;
        }
        i++;
    }

    while(i<K){
        if(b >= c){
            c*=2;
        }else{
            break;
        }
        i++;
    }

    if(is_ok(a,b,c)){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 3620
N, M = map(int,input().split())
SC = [-1]*(N+1)
ans = [0]*N
for _ in range(M):
    s,c = map(int,input().split())
    if SC[s] != -1 and SC[s] != c:
        print(-1)
        exit()
    SC[s] = c
flg = 1
if N == 1:
    st = 10**(N-1) -1
else:
    st = 10**(N-1)
for i in range(st,10**N):
    s = str(i)
    for j in range(1,N+1):
        if SC[j] == -1:
            continue
        if SC[j] != int(s[j-1]):
            flg = 0
            break
    if not flg:
        flg = 1
        continue
    if flg:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a*n,b) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int a[300000],b[300000],c[300000],d[300000],e[300000]={0};
int main()
{
	int n,m,u,j,k,i,flag=0,temp=0,pick=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	{
	scanf("%d%d",&a[i],&b[i]);
	if(a[i]==1)
	temp=1;
	if(b[i]==n)
	pick=1;
    }
    if(temp==1&&pick==1)
    {
	for(i=1,u=0,j=0;i<=m;i++)
	{
		if(a[i]==1)
		c[++u]=b[i];
		if(b[i]==n)
		d[++j]=a[i];
	}
	/*for(i=1;i<=u;i++)
	printf("%d  \n",c[i]);
	for(i=1;i<=j;i++)
	printf("%d ",d[i]);*/
	for(i=1;i<=u;i++)
	e[c[i]]++;
	for(i=1;i<=j;i++)
	e[d[i]]++;
	for(i=1;i<=250000;i++)
	{
		if(e[i]>=2)
		{
			flag=1;
			break;
		}
	}
	if(flag)
	printf("POSSIBLE\n");
	else
	printf("IMPOSSIBLE\n");
    }
    else
    printf("IMPOSSIBLE\n");
	return 0;
 } 

Measured memory_bytes: 4224
import sys
import collections

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, W = map(int, readline().split())
items = []
for i in range(N):
    w, v = map(int, readline().split())
    items.append((w, v))


def solve():
    dp = collections.defaultdict(lambda: -1)
    dp[0] = 0
    for i in range(N):
        wi, vi = items[i]
        ndp = collections.defaultdict(lambda: -1)
        for ws, vs in dp.items():
            if ws + wi <= W:
                ndp[ws + wi] = max(ndp[ws + wi], vs + vi)
        for wt, vt in ndp.items():
            dp[wt] = max(dp[wt], vt)
    return max(dp.values())


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 46192
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

vector<pair<char, int> > run_length_factorization(string s){
    vector<pair<char, int> > res;
    s += '$';
    char c = s[0];
    int now = 1;
    for(int i = 1; i < s.size(); i++){
        if(s[i] != c){
            res.push_back(pair<char, int>(c, now));
            c = s[i]; now = 1;
        }else now++;
    }
    return res;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    auto r = run_length_factorization(s);
    cout << r.size() << endl;
}

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

using namespace std;

int N;
vector<int> msp;

void msps() {
	vector<bool> isp(300000, true);
	isp[1] = false;
	
	for (int i = 0; 7 * i + 1 < 300000; i++) {
		int p = 7 * i + 1;
		if (isp[p]) {
			msp.push_back(p);
			for (int j = 2 * p; j < 300000; j += p) isp[j] = false;
		}
		p = 7 * i + 6;
		if (isp[p]) {
			msp.push_back(p);
			for (int j = 2 * p; j < 300000; j += p) isp[j] = false;
		}
	}
}

int main() {
	msp.clear();
	msps();
	
	while (1) {
		cin >> N; if (N == 1) break;
		
		cout << N << ": ";
		vector<int> put;
		for (int i = 0; i < (int)msp.size(); i++) {
			if (N % msp[i] == 0) put.push_back(msp[i]);
		}
		
		for (int i = 0; i < (int)put.size(); i++) {
			if (i < (int)put.size() - 1) cout << put[i] << " ";
			else cout << put[i] << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1384
A,B,C,D,E,F = map(int, input().split())
ans = {"w":A*100, "s":0}
def density(water, sugar):
    return 100*sugar/(water+sugar)

for a in range(31):
    for b in range(31):
        water = (a*A+b*B)*100
        if water>F:
            continue
        max_sugar = min((a*A+b*B)*E, F-water)
        for c in range(max_sugar//C+1):
            sugar = c*C
            sugar += ((max_sugar-sugar)//D)*D
            if water+sugar==0: 
                continue
            if density(water, sugar)>density(ans["w"], ans["s"]):
                ans["w"] = water
                ans["s"] = sugar
print(ans["w"]+ans["s"], ans["s"])

Measured memory_bytes: 3064
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    string s; cin >> s;
    if(s.find("AC") != string::npos) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 764
import numpy as np
p = np.array(list(map(int, input().split())))

cnt = 0
mem = []
flag = True
while (p % 2).sum() == 0:
    a = p[1] // 2 + p[2] // 2
    b = p[0] // 2 + p[2] // 2
    c = p[1] // 2 + p[0] // 2
    
    p = np.array([a, b, c])
    if (a,b,c) in mem:
        flag = False
        break
    else:
        mem.append((a,b,c))
        
    cnt += 1

print(cnt if flag else -1)


Measured memory_bytes: 12396
#include <iostream>

using namespace std;

int main() 
 {
    int a,b,i,j;
    cin>> a>>b;
     while(a>0 || b>0)
    {
    
    for(i=1;i<=a;i++)
  {
    for(j=1;j<=b;j++)
    {
    cout<<"#" ;
    }
    cout<<endl;
  }
  cout<<endl;
  cin>>a>>b;
    }
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
vector<vector<int>>g(1e5+10);
int h[100005];
int n,m;
// bool dfs(int v,int h)
// {
// 	if(vis[v])
// 	return false;
 
// 	for(int i=g[v].begin();i<g[v].size();i++)
 
// }
int main() {
	// your code goes here
 
	cin>>n>>m;
	//int h[n];
	for(int i=0;i<n;i++)
	cin>>h[i];
	g.resize(n);
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
 
	vector<int>vis(n,0);
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		 if(vis[i]==1)
		 continue;
		 int flag=1;
	     for(int j=0;j<g[i].size();j++)
	     {
	     	if(h[g[i][j]]>=h[i])
	     	{
	     		flag=0;
	     		break;
	     	}
 
 
	     }
	     if(flag)
	     {
	     	cnt++;
	     	//cout<<i<<"\n";
	     	for(int j=0;j<g[i].size();j++)
	     	{
	     		vis[g[i][j]]=1;
	     	}
 
 
	     }
	}
	cout<<cnt;
 
 
 
	return 0;
}

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s,t;
    cin >> s >>t;
    char se;
    vector<bool> hai_f(s.size(),true);
    bool flag =false;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<s.size();j++){
            if(j ==0){
                se = s.at(s.size()-j-1);
            }else{
                s.at(s.size()-j)=s.at(s.size()-j-1);
            }
        }
        s.at(0)=se;
        for(int j=0;j<s.size();j++){
            if(s.at(j)!=t.at(j)) hai_f.at(i)=false;
        }
    }
    for(int i=0;i<s.size();i++){
        if(hai_f.at(i)==true) flag=true;
    }
    if(flag==true) cout << "Yes" <<endl;
    else cout <<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N, A[200005], B[200005];
long long ans;
int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		if (i - A[i] > 0)
		{
			B[i - A[i]]++;
		}
	}
	for (int i = 0; i < N; i++)
	{

	}
	for (int i = 0; i < N; i++)
	{
		if (i + A[i] < 200005)
		{
			ans += B[i + A[i]];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5188
#include <stdio.h>
#include <math.h>

int digit(long int num){
    int dig=0;
    while (num!=0) {
        dig++;
        num/=10;
    }
    return dig;
}

int main()
{
    long int N,i,a;
    scanf("%ld",&N);
    for(i=1;i<=(long int)sqrt(N);i++){
        N%i==0?a=N/i:0;
    }
    printf("%d\n",digit(a));
    return 0;
}

Measured memory_bytes: 128
import sys
n = int(input())
ans = 0
flag = False
for i in range(n):
    d1,d2 = map(int,input().split())
    if d1 == d2:
        ans += 1
    else:
        ans = 0
    if ans == 3:
        flag = True
if flag == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62224
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, i;
    cin >> a >> b;
    for(i=0;i<=100000;i++){
        if((i*8)/100==a && (i*10)/100==b){
            cout << i <<endl;
            return 0;
        } 
    }
    cout << -1 <<endl;
    return 0;
}

Measured memory_bytes: 3628
n, k = list(map(int, input().split()))
al = list(map(int, input().split()))
al = [a-1 for a in al]
used = [0]*n
first = [0]*n
step = 0
used[0] = 1
now = 0
for i in range(k):
    step += 1
    get = al[now]
    if used[get] == 0:
        first[get] = step
        used[get] = 1
        now = get
    else:
        dif = step-first[get]
        nokori = (k-step) % dif
        now = get
        for j in range(nokori):
            get = al[now]
            now = get
        print(now+1)
        exit()
print(now+1)


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

int main() {
  ll n,k;
  string s;
  cin >> n >> k >> s;
  s.at(k-1)+=32;
  cout << s << endl;
}


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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}
 
void solve()
{
	int n;
	
	cin >> n;
	
	int a[n];
	
	int cnt = 0;
	
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	sort(a , a+n);
	
	int p[n+1] {};
	int s[n+1] {};
	
	for(int i = 0; i < n; ++i) {
		if(i == 0) {
			p[i] = a[i];
			continue;
		}
		
		p[i] = __gcd(p[i-1] , a[i]);
	}
	
	for(int i = n-1; i >= 0; --i) {
		if(i == n-1) {
			s[i] = a[i];
			continue;
		}
		
		s[i] = __gcd(s[i+1] , a[i]);
	}
	
	int mx = 0;
	
	for(int i = 0; i < n; ++i) {
		if(i == 0) {
			mx = max(mx , s[i+1]);
		}
		else if(i == n-1) {
			mx = max(mx , p[i-1]);
		}
		else {
			mx = max(mx , __gcd(p[i-1] , s[i+1]));
		}
	}
	
	cout << mx;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


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

typedef long long ll;
typedef long double ld;

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

int main(){

    vector<ll> a(3);
    vector<ll> b = {5, 5, 7};

    rep(i, 3)
        cin >> a[i];

    sort(all(a));

    cout << (a == b ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> ii;

int mod = 998244353;
long long qexp(long long b, long long p){
    long long res = 1;
    while(p){
        if(p&1) res = (res * b) % mod;
        b = (b * b) % mod;
        p >>= 1;
    }
    return res;
}
int inv(long long b){ return qexp(b, mod-2); }

int pre[3005];
int cur[3005];

signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n, S; cin >> n >> S;
	
	pre[0] = 1;
	for(int i = 0;i < n;i++){
		int a; cin >> a;
		for(int j = a;j <= S;j++){
			cur[j] += pre[j-a];
		}
		
		for(int j = 0;j <= S;j++){
			cur[j] += 2*pre[j];
			cur[j] %= mod;
		}
		
		swap(cur,pre);
		fill(cur,cur+S+1,0);
	}
	
	cout << pre[S];
	
	
}



Measured memory_bytes: 3696
n = int(input())
list = []

# for _ の"_"はこの変数を使いませんよ、という意味.
for _ in range(n):
    s = input()
    #appendで追加.
    list.append(s)
new_list = sorted(list)
ans = n
for i in range(n - 1):
    if new_list[i] == new_list[i + 1]:
        #ans--はpythonで不可能.
        ans -= 1
print(ans)


Measured memory_bytes: 25448
def insertionsort(a, n)
	output = [a.join(" ")]

	1.upto(n-1) do |i|
		v = a[i]
		j = i-1
		
		while j >= 0 && v < a[j]
			a[j+1] = a[j]
			j -= 1
		end
		
		a[j+1] = v
		
		output.push(a.join(" "))
	end
	
	return output.join("\n")
end


N = gets.to_i
Arr = gets.split.map(&:to_i)

puts insertionsort(Arr, N)



Measured memory_bytes: 6920
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,s=0;
    cin>>n;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                s+=(__gcd(i,__gcd(j,k)));
            }
        }
    }
    cout<<s<<endl;
}


Measured memory_bytes: 3620
#include<stdio.h>

int main(){
  int n, i; 
  int f[44];

  scanf("%d", &n);
  f[0]=f[1]=1;
  for(i=2;i<=n;i++) f[i]=f[i-1]+f[i-2];
  printf("%d\n",f[n]);

  return 0;
}



Measured memory_bytes: 2104
import math
A, B, H, M = map(int, input().split())
a = (H + M / 60) / 12 * 2 * math.pi
b = M / 60 * 2 * math.pi
x = math.sqrt(A * A + B * B - 2 * A * B * math.cos(a - b))
print(x)

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

int sum(int n){
        int s=0;
        while(n>0){
                int r = n%10;
                s+=r;
                n/=10;
        }
        return s;
}

int main(){

        int n;
        scanf("%d",&n);
        int ans = sum(n);
        if(n%ans==0){
                puts("Yes");
        }else{
                puts("No");
        }
        return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

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

    ll sum = 0;
    ll res = 0;
    rep(i, 0, N) {
        ll A;
        cin >> A;
        res += (A * sum) % MOD;
        res %= MOD;
        sum = (sum + A) %MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const ll MOD = 1e9 +7;




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    stack<char> st;
    rep(i,s.size()){
        if(st.size()==0){
            st.push(s[i]);
        }
        else{
            if(s[i]=='T' &&st.top()=='S'){
                st.pop();
            }
            else{
                st.push(s[i]);
            }
        }
    }
    std::cout<<st.size()<<endl;
    return 0;
}


Measured memory_bytes: 720
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()

    ret = 0
    for n in range(N - 2):
        trg = P[n:n + 3][1]
        if sorted(P[n:n + 3])[1] == trg: ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10224
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

bool is_square(int a){
  for (int i = 2; i < a; i++){
    while (a % (i * i) == 0){
      a /= i * i;
    }
  }
  if (a == 1)
    return true;
  else
    return false;
}

int main(void){
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d, 0));

  for (int i = 0; i < n; i++){
    for (int j = 0; j < d; j++){
      cin >> x[i][j];
    }
  }

  int num = 0;
  for (int i = 0; i < n; i++){
    for (int j = i + 1; j < n; j++){
      int r = 0;
      for (int k = 0; k < d; k++){
        r += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      if (is_square(r))
        num++;
    }
  }


  cout << num << endl;

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin (),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp
//tgamma(i+1) is 1!


void solve(){
    int v;
    cin >> v;
    ll ans = 0;
    for(int i = 1; i <=v;++i){
        for(int j = 1; j <=v;++j){
            for(int k = 1; k <= v;++k){
                ans += __gcd(i,__gcd(j,k));
            }
        }
    }
    cout << ans;
}

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

    solve();
}








Measured memory_bytes: 3640
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            // Console.WriteLine("Hello World!");
            var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            
            if(nk[0] < nk[1])
            {
                Console.WriteLine("1");
            }
            else
            {
                Console.WriteLine(nk[0] % nk[1] == 0 ? "0" : "1");
            }

        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>

int main(){
	int n;
	std::cin >> n;
	int a[n];
	for(int i = 0;i < n;i++) {
		std::cin >> a[i];
	}
	std::sort(a, a + n);
	for(int i = 0;i < n - 1;i++){
		if(a[i] == a[i + 1]){
			std::cout << "NO" << std::endl;
			return 0;
		}
	}
	std::cout << "YES" << std::endl;
	return 0;
}

Measured memory_bytes: 1024
import java.awt.*
import java.util.*
import kotlin.math.*

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}.toIntArray()

fun <T> T.print() = println(this)

fun main() {
	abc000X()
}

fun abc000X() {
	val x = int()
	println((1..10000).first {x*it%360==0})
}


Measured memory_bytes: 34560
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
using pi = pair<lint, lint>;
const int MAXN = 100005;
const int mod = 998244353;
const int MAXC = 1005;

int main(){
	int R, G, B, n;
	cin >> R >> G >> B >> n;
	lint dap = 0;
	for(int r = 0; r <= n; r++){
		for(int g = 0; g <= n; g++){
			int x = r * R + g * G;
			if(x <= n && (n - x) % B == 0){
				dap++;
			}
		}
	}
	cout << dap << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<P> v, w;
	int x, y, ans = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> x >> y;
		v.push_back(P(x, y));
	}
	for(int i = 0; i < n; i++)
	{
		cin >> x >> y;
		w.push_back(P(x, y));
	}
	sort(w.begin(), w.end());
	bool flag[n + 1] = {};
	for(int i = 0; i < n; i++)
	{
		bool ok = false;
		int dist = -1, pos;
		for(int j = 0; j < n; j++)
		{
			if(flag[j]) continue;
			if(v[j].first < w[i].first && v[j].second < w[i].second)
			{
				ok = true;
				if(v[j].second > dist)
				{
					dist = v[j].second;
					pos = j;
				}
			}
		}
		if(ok)
		{
			flag[pos] = true;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin >> x >> y;
    bool chk = false;
    for(int i=0;i<=x;i++){
        if(2*i + 4*(x-i) == y)chk=true;
    }
    if(chk)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
bool ispalin(string s){
    int len = s.length();
    bool flag = true;
    for(int i=0; i<len/2; i++){
        if(s[i]!=s[len-1-i]){
            flag = false;
            break;
        }
    }
    return flag;
}
int main(){
    string s;
    cin >> s;
    int len = s.length();
    string part1 = s.substr(0, (len-1)/2), part2 = s.substr((len+1)/2, (len-1)/2);
    if(ispalin(s) and ispalin(part1) and ispalin(part2))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ull = unsigned long long;
using ll = long long;
using ld = long double;
int main(){
 ll N,S=0;
  cin>>N;
  ll a[200000];
  for(int i=0;i<N;i++) cin>>a[i];
 ll M=0;
  for(int i=0;i<N;i++){
    if(M>a[i]) S+=(M-a[i]);
    if(M<a[i]) M=a[i];
  }
  cout<<S<<endl;
  return 0;
}

Measured memory_bytes: 5096
while True:
    i = list(input().split(" "))
    a = int(i[0])
    op = i[1]
    b = int(i[2])
    if op == "?":
        break
    elif op == "+":
        print("{}".format(a+b))
    elif op == "-":
        print("{}".format(a-b))
    elif op == "*":
        print("{}".format(a*b))
    elif op == "/":
        print("{}".format(a//b))
    else :
        print("INVALID INPUT")

Measured memory_bytes: 7612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    string s;cin>>s;
    ll cnt=0;
    for(int i=0;i<n-2;i++){
        if(s.substr(i,3)=="ABC")cnt++;
    }
    cout<<cnt<<"\n";
}


Measured memory_bytes: 3640
data = input().rstrip().split(" ")
one = int(data[0])
zero = int(data[1])
minus = int(data[2])
num = int(data[3])
answer = 0
if one >= num:
    answer = num
elif one + zero >= num:
    answer = one
else:
    answer = one * 2 + zero - num
print(answer)


Measured memory_bytes: 9124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int A = in.nextInt();
			int B = in.nextInt();
			int C = in.nextInt();
			int count = 0;
			while(A <= B) {
				B -= A;
				count++;
				if(count == C) {
					break;
				}
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 23252
n = gets.to_i
a = gets.chomp.split.map(&:to_i)

hs = Hash.new(0)
a.each {|i| hs[i] += 1 }

ic = hs.keys.sort!
ic.unshift(ic[0] - 1)
ic.unshift(ic[0] - 1)
ic.push(ic[-1] + 1)
ic.push(ic[-1] + 1)

res = 0
ic[2...ic.size].each do |i|
  s = hs[i] + hs[i - 1] + hs[i - 2]
  res = s if s > res
end

puts res

Measured memory_bytes: 13976
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long  long
#define INF 0x3f3f3f3f
#define pll pair<long long , long long>
const int MAX=1e6+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
vector<int>adj[MAX];
int prime[MAX];
bool cmp1(pair<ll , ll >& a , pair<ll , ll>& b){
	return a.first<b.first;
}
bool cmp2(pair<ll ,ll>& a , pair<ll , ll>& b){
	return a.second<b.second;
}
int main() 
{
   long long ans = 0;
   int n;
   cin>>n;
   vector<pair<ll , ll>  > v;
   long long mx = 0;
   long long mn = INF;
   for(int i=0;i<n;i++){
   	long long x, y;
   	cin>>x>>y;
   	v.push_back({x+y,x-y});
   }
   sort(v.begin() , v.end() , cmp1);
   ans = max(abs(v[0].first-v[n-1].first), abs(v[0].second-v[n-1].second));
   sort(v.begin() , v.end() , cmp2);
   ans = max(ans , max(abs(v[0].first-v[n-1].first), abs(v[0].second-v[n-1].second)));
   cout<<ans;

}


Measured memory_bytes: 30896
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 3e3+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

db p[maxn];
db dp[maxn][maxn];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int n;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) scanf("%lf", &p[i]);

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

    db answer = 0.0;
    for(int i = n / 2 + 1; i <= n; i++)
        answer += dp[n][i];

    printf("%.10f\n", answer);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 68992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// 0 <= unsigned int <= 4.2e9

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

    int numReverse = 0;
    string first(""), last("");
    for (int q=0; q<Q; q++) {
        int T; cin >> T;
        if (T == 1) {
            // reverse(S.begin(), S.end());
            numReverse++;
        }
        else if (T == 2) {
            int F; cin >> F;
            string C; cin >> C;
            if (F == 1) {
                if ((numReverse % 2) == 0)
                    first = C + first; // default
                else
                    last = last + C;
            }
            else if (F == 2) {
                if ((numReverse % 2) == 0)
                    last = last + C; // default
                else
                    first = C + first; // default
            }
        }
    }
    S = first + S + last;
    if ((numReverse % 2) != 0)
        reverse(S.begin(), S.end());
    //S = first + S + last;
    cout << S << endl;
}


Measured memory_bytes: 1512
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y << endl;
    GAME_OVER;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b;
    cin >> a >> b;
    cout << max((b>=0?a+b:a-b), a*b) << endl;
}


Measured memory_bytes: 256
while 1:
  c=[0,1,1]+[0]*98
  while 1:
    try: a, b = map(int, raw_input().split())
    except: exit()
    if a==0==b:break
    c[a] = -c[a]+1
    c[b] = -c[b]+1
  if c.count(1): print "NG"
  else: print "OK"

Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
     cin>>n;

    double x;
       if(n % 2==0)
         x=0.500000;

       else
       {
           x=(n/2.0 +0.5)/n;
       }
       cout<<x;
}


Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
const int MAXN=100005;
const ll INF=1000000000000000;
int n,m,s,t;
queue<int>T;
struct node{
	int go,vis;ll dist[5];
	vector<ll>T[5],P;
}w[MAXN];
ll ans[MAXN];
void Add(int a,int b,int c,int d){
	w[a].T[1].push_back(c);
	w[a].T[2].push_back(d);
	w[a].P.push_back(b);
}
void SPFA(int x,int y){
	while(!T.empty())T.pop();
	for(int i=0;i<=n+1;i++)
		w[i].vis=0,w[i].dist[y]=INF;
	T.push(x);w[x].dist[y]=0;
	while(!T.empty()){
		int u=T.front();T.pop();
		w[u].vis=0;
		for(int i=0;i<w[u].P.size();i++){
			int v=w[u].P[i],e=w[u].T[y][i];
			if(e+w[u].dist[y]<w[v].dist[y]){
				w[v].dist[y]=e+w[u].dist[y];
				if(!w[v].vis){
					w[v].vis=1;
					T.push(v);
				}
			}
		}
	}
}
int main(){
	scanf("%d%d%d%d",&n,&m,&s,&t);
	for(int i=1;i<=m;i++){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		Add(a,b,c,d);Add(b,a,c,d);
	}
	SPFA(s,1);SPFA(t,2);
	ans[n+1]=INF;
	for(int i=n;i>=1;i--)
		ans[i]=min(ans[i+1],w[i].dist[1]+w[i].dist[2]);
	for(int i=1;i<=n;i++)
		printf("%lld\n",INF-ans[i]);
}


Measured memory_bytes: 32384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    return gcd(b, a % b);

}

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

class Solve {
public:
    void input() {

    }

    ll cal(ll n, ll x, ll y) {
        ll ret = 0;
        ll lc = lcm(x, y);
        ret += n / x;
        ret += n / y;
        ret -= n / lc;
        return ret;
    }

    void solve() {
        input();
        ll A, B, C, D;
        cin >> A >> B >> C >> D;
        ll tapi = cal(B, C, D);
        ll tapu = cal(A - 1, C, D);

        ll val = tapi - tapu;
        ll ans = B - A + 1 - val;
        cout << ans << endl;


    }
};


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

    Solve().solve();


    return 0;
}


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

int main() {

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

  int tmp=0;
  int ans=1;
  for(int i=n-1;i>0;--i){
    tmp=1;
    for(int j=i-1;j>=0;--j){
      if(h[i]>=h[j]) tmp=1;
      else {
	tmp=0;
	break;
      }
    }if(tmp==1) ans++;
  }

  cout << ans << endl;    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define fi first
#define se second
#define pb push_back
#define loop(i, a, b) for (int i=a; i<(b); i++)
typedef long long ll;
typedef pair<int,int> pi;
const int INF = 1e9;
const int MOD = 1000000007;


ll n;
vector<ll> divi;
ll ans=1;

void sieve(){
	for(ll i=2;i<=n;i++){
		for(ll j=i;j<=n;j+=i)
			divi[j]++;
		ans += divi[i]*i;
	}
}

void test_case() {
	cin>>n;
 	divi.assign(n+1,1);
	sieve();
	cout<<ans<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for (int i = 1; i <= t; i++) {
		test_case();
	}
	return 0;
}

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

int main()
{
	char a,b,c,d;
	int q,w,e,r;
	cin>>a>>b>>c>>d;
	q=a-48;w=b-48;e=c-48;r=d-48;
	if(q+w+e+r==7){	cout<<q<<'+'<<w<<'+'<<e<<'+'<<r<<"=7";	return 0;	}
	if(q+w+e-r==7){	cout<<q<<'+'<<w<<'+'<<e<<'-'<<r<<"=7";	return 0;	}
	if(q+w-e+r==7){	cout<<q<<'+'<<w<<'-'<<e<<'+'<<r<<"=7";	return 0;	}
	if(q+w-e-r==7){	cout<<q<<'+'<<w<<'-'<<e<<'-'<<r<<"=7";	return 0;	}
	if(q-w+e+r==7){	cout<<q<<'-'<<w<<'+'<<e<<'+'<<r<<"=7";	return 0;	}
	if(q-w+e-r==7){	cout<<q<<'-'<<w<<'+'<<e<<'-'<<r<<"=7";	return 0;	}
	if(q-w-e+r==7){	cout<<q<<'-'<<w<<'-'<<e<<'+'<<r<<"=7";	return 0;	}
	if(q-w-e-r==7){	cout<<q<<'-'<<w<<'-'<<e<<'-'<<r<<"=7";	return 0;	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  double w,h;cin>>w>>h;
  double x,y;cin>>x>>y;
  cout<<h*w/2<<" ";
  if(x*2==w&&y*2==h){
    cout<<1<<endl;
  }
  else {
    cout<<0<<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;
    cin >> N;

    int ac, wa, tle, re;
    ac = 0;
    wa = 0;
    tle = 0;
    re = 0;
    string S;
    for (int i = 0; i < N; i++)
    {
        cin >> S;
        if (S == "AC")
            ac++;
        else if (S == "WA")
            wa++;
        else if (S == "TLE")
            tle++;
        else
            re++;
    }

    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);
    return (0);
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define int long long
int h;
void maxHeapify(int *A,int i){
  int l=i*2+1;
  int r=i*2+2;
  int largest;
  if(l<h&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<h&&A[r]>A[largest]) largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(A,largest);
  }
}
void insert(int *A,int x){
  int i=h++;
  A[i]=x;
  while(i&&A[(i-1)/2]<A[i]){
    swap(A[(i-1)/2],A[i]);
    i=(i-1)/2;
  }
}
int extract(int *A){
  int res=A[0];
  A[0]=A[--h];
  maxHeapify(A,0);
  return res;
}
int A[2222222];
signed main(){
  string s;
  while(cin>>s,s!="end"){
    if(s=="insert"){
      int x;
      cin>>x;
      insert(A,x);
    }
    if(s=="extract") cout<<extract(A)<<endl;
  }
  return 0;
}

Measured memory_bytes: 10980
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;



signed main(){
	int K, Q;
	cin >> K >> Q;
	vector<int>d(K);
	REP(i, K) {
		cin >> d[i];
	}
	vector<int>ans;
	while(Q--) {
		int N, X, M;
		cin >> N >> X >> M;
		N--;
		vector<int>a(K);
		REP(i, K) {
			if(d[i] % M == 0) a[i] = M;
			else a[i] = d[i] % M;
		}
		int as = 0;
		REP(i, K) {
			as += a[i];
		}
		int amari = 0;
		REP(i, N % K) {
			amari += a[i];
		}
		int sum = as * (N / K) + amari + X % M;
		int mod = sum / M;
		ans.emplace_back(N - mod);
	}
	REP(i, ans.size()) {
		out(ans[i]);
	}
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()

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

ll MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    sort(ALL(A));
    if (N % 2 == 0) {
        ll ans1 = A[N/2] - A[N/2-1];
        ll ans2 = A[N/2] - A[N/2-1];
        REP(i, (N-2) / 2) {
            ans1 += A[N-1 - i] * 2;
            ans1 -= A[i] * 2;
            ans2 += A[i] * 2;
            ans2 -= A[N-1 - i] * 2;
        }
        PRINT(max(ans1, ans2));
    } else {
        ll ans1 = -A[N/2] - A[N/2-1];
        ll ans2 = + A[N/2] + A[N/2+1];
        REP(i, (N-1) / 2) {
            ans1 += A[N-1 - i] * 2;
            ans2 -= A[i] * 2;
        }
        REP(i, (N-2)/2) {
            ans1 -= A[i] * 2;
            ans2 += A[N-1 - i] * 2;
        }
        PRINT(max(ans1, ans2));
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int N,p;
	string s;
	cin >> N >> p >> s;
	if( p != 2 && p != 5){
	map<int,int> m1;
	ll ans = 0;
	int sm = 0;
	m1[0] = 1;
	int pows = 1;
    for(int i=s.length()-1; i >=0; i--){
        int c = ((s[i]-'0')*pows)%p;
        sm  = (sm+c)%p;
        //if( c == 0 ) ans += 1;
        //cout << ans << " ";
        ans += m1[sm];
        m1[sm] += 1;
        //cout << ans << endl;
        //for(auto c:m1) cout << c.first << " -------> " << c.second << endl;
        pows = (pows*10)%p;

    }
    cout << ans;}

    else{
        ll ans= 0;
        for(int i=0; i < s.length(); i++){
            if( (s[i]-'0')%p == 0 ) ans += i+1;
        }
        cout << ans;
    }

}
// 10 5 1536598555


Measured memory_bytes: 916