akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    def subsetall(self):
        a = []
        for i in range(len(self.table)):
            if self.table[i] < 0:
                a.append((i, -self.table[i]))
        return a

def main():
    n,m = LI()
    e = [LI_() for _ in range(m)]
    r = n * (n-1) // 2
    rr = [r]

    uf = UnionFind(n)
    for a,b in e[::-1]:
        af = uf.find(a)
        bf = uf.find(b)
        if af != bf:
            r -= uf.table[af] * uf.table[bf]
            uf.union(af,bf)
        rr.append(r)

    return '\n'.join(map(str, rr[::-1][1:]))



print(main())




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

int main(void)
{
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

    printf("%lf\n", sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));
    return 0;
}

Measured memory_bytes: 652
C = [list(map(int, input().split())) for i in range(3)]
ans = 'No'
for a1 in range(100):
    b1 = C[0][0] - a1
    b2 = C[0][1] - a1
    b3 = C[0][2] - a1
    a2 = C[1][0] - b1
    a3 = C[2][0] - b1
    if C[1][1] == a2 + b2 and C[1][2] == a2 + b3 and C[2][1] == a3 + b2 and C[2][2] == a3 + b3:
        ans = 'Yes'
        break
print(ans)

Measured memory_bytes: 3064
#フローに帰着、dinic法,dinic法は蟻本
import sys
from collections import deque

sys.setrecursionlimit(200000)

class Dinic:
    
    def __init__(self,v, inf =10**10):
        self.v = v
        self.inf = inf
        self.G = [[] for _ in range(v)]
        self.level = [-1]*v#深さ
        self.ite = [0]*v#DFSでの探索が済んでいるか否か
    
    def add_edge(self, fr, to, cap):#末尾はself.G[to]から対応する辺のself.G[fr]内でのindex
        self.G[fr].append([to,cap,len(self.G[to])])###{'to':to,"cap":cap,"rev";len(self.G[to})}みたいにしたほうがいいか
        self.G[to].append([fr,0,len(self.G[fr])-1])

    
    def bfs(self,s):#BFSで深さ決定,sがstart
        self.level = [-1]*self.v#必要
        self.level[s] = 0
        Q = deque()
        Q.append(s)
        while Q:
            v = Q.popleft()
            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if e[1]>0 and self.level[e[0]]<0:###capacity>0かつtoの深さ未定
                    self.level[e[0]] = self.level[v]+1
                    Q.append(e[0])

        
    def dfs(self,v,t,f):#DFSで増加パス探索,v開始、t終点、総フローf
        if v==t:
            return f
        for i in range(self.ite[v],len(self.G[v])):
            self.ite[v] = i
            e = self.G[v][i]
            if e[1]>0 and self.level[v]<self.level[e[0]]:
                d = self.dfs(e[0],t,min(f,e[1]))
                if d>0:
                    e[1] -= d #cap減少
                    self.G[e[0]][e[2]][1] += d#逆辺のcap増加
                    return d
        return 0
    
    def max_flow(self,s,t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t]<0:
                return flow
            self.ite = [0]*self.v#DFSでの探索が済んでいるか否か
            f =self.dfs(s,t,self.inf)
            while f>0:
                flow+= f
                f = self.dfs(s,t,self.inf)
            
x,y,e = map(int, input().split( ))
D = Dinic(x+y+2)
for _ in range(e):
    u,w = map(int, input().split( ))
    D.add_edge(u,w+x,1)
for i in range(x+y):
    if i<x:
        D.add_edge(x+y,i,1)
    else:
        D.add_edge(i,x+y+1,1)
ans = D.max_flow(x+y,x+y+1)
print(ans)


        
                    


Measured memory_bytes: 7908
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=b;i<=c;i++)
    {
        if(i%a==0){cout<<"OK"<<endl;return 0;}
    }
    cout<<"NG"<<endl;
    return 0;
}


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


int main(){
	int  h,n,d;
	cin>>h>>n;
	int a[n];
	for(int i = 0; i<n ;i++){	
		cin>>d;
		a[i]=d;
		h=h-a[i];

	}

	
	if(h>0){
			cout<<"No";
			}
	else{
		cout<<"Yes";
		}
						
return 0 ;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;
 
 
 int lis( int arr[], int n )  
{  
    int lis[n]; 
   
    lis[0] = 1;    
  
    /* Compute optimized LIS values in bottom up manner */
    for (int i = 1; i < n; i++ )  
    { 
        lis[i] = 1; 
        for (int j = 0; j < i; j++ )   
            if ( arr[i] > arr[j] && lis[i] < lis[j] + 1)  
                lis[i] = lis[j] + 1;  
    } 
  
    // Return maximum value in lis[] 
    return *max_element(lis, lis+n); 
}  
void computeLPSArray(char* pat, int M, int* lps) 
{ 
    // length of the previous longest prefix suffix 
    int len = 0; 
  
    lps[0] = 0; // lps[0] is always 0 
  
    // the loop calculates lps[i] for i = 1 to M-1 
    int i = 1; 
    while (i < M) { 
        if (pat[i] == pat[len]) { 
            len++; 
            lps[i] = len; 
            i++; 
        } 
        else // (pat[i] != pat[len]) 
        { 
            // This is tricky. Consider the example. 
            // AAACAAAA and i = 7. The idea is similar 
            // to search step. 
            if (len != 0) { 
                len = lps[len - 1]; 
  
                // Also, note that we do not increment 
                // i here 
            } 
            else // if (len == 0) 
            { 
                lps[i] = 0; 
                i++; 
            } 
        } 
    } 
} 
string longestCommonPrefix(string ar[], int n) 
{ 
  
    // If size is 0, return empty string 
    if (n == 0) 
        return ""; 
  
    if (n == 1) 
        return ar[0]; 
  
    // Sort the given array 
    sort(ar, ar + n); 
  
    // Find the minimum length from  
    // first and last string 
    int en = min(ar[0].size(),  
                 ar[n - 1].size()); 
  
    // Now the common prefix in first and  
    // last string is the longest common prefix 
    string first = ar[0], last = ar[n - 1]; 
    int i = 0; 
    while (i < en && first[i] == last[i]) 
        i++; 
  
    string pre = first.substr(0, i); 
    return pre; 
} 
bool isvalid(ll int x, ll int y, ll int m, ll int n)
{
    if(x<0||y<0||x>=m||y>=n)return 0;
    else return 1;
}
bool iscor(ll int x, ll int y, ll int m, ll int n)
{
    if(x==0||y==0||x==m-1||y==n-1)return 1;
    else return 0;
}

    
int main()
{
  fastio();
 
ll int T;
//cin>>T;
T=1;
ll int anscount=1;
while(T--)
{
 ll int n,k;
 cin>>n>>k;
 n=n%k;
 ll int n1=n;
 ll int ans=n1;
 n=k-n;
 while(n!=n1)
 {
     ans=min(ans,n);
     n=k-n;
 }
cout<<ans<<endl;

 
 //cout<<n<<endl;
 
  
  
  
}
    return 0;
}

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

int main() {
    ll n;
    cin >> n;
    if(n%2 != 0) {
        cout << 0 << endl;
        return 0;    
    }
    n /= 2;
    ll res = 5;
    ll ans = 0;
    while(n >= res){
        ans += n/res;
        res *= 5;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
/**********************
    Vikas Kumar Jha
    vkjha1010
**********************/
#include<bits/stdc++.h>
using namespace std;

#define ll          long long int 
#define ld          long double
#define mod         1000000007
#define fi          first
#define se          second
#define pb          push_back
#define mp          make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vb          vector<bool>
#define mii         map<ll,ll>
#define pqb         priority_queue<ll>
#define pqs         priority_queue<ll, vi, greater<ll> >
#define ps(x,y)     fixed << setprecision(y) << x
#define fast        ios_base::sync_with_stdio(0);   cin.tie(0); cout.tie(0);
#define w(t)        ll t; cin >> t; for(ll zx=1;zx<=t;++zx)  
#define fr(be,en)   for(ll i = be; i < en; i++)
ll pow(ll x,ll y){ if(y==0) return 1; if(y%2==1) return (((pow(x,y/2)*pow(x,y/2)%mod)*x)%mod); else return (pow(x,y/2)*pow(x,y/2))%mod;}
vb prime;   vi spf; 
void sieve(ll n) 
{   prime.resize(n+1,true); prime[0]=prime[1]=false;
    spf.resize(n+1,1);  spf[2]=2;
    for(ll i=4;i<=n;i+=2){ prime[i]=false; spf[i]=2; } 
    for (ll p=3; p*p<=n; p+=2) 
    {   if (prime[p] == true) 
        {   spf[p]=p;
            for (ll i=p*p; i<=n; i += p) 
            {   if(prime[i]==true)
                {   spf[i]=p;
                    prime[i] = false;
                }
            } 
        } 
    } 
} 

int main() {
    
    fast;
    string s,t;
    cin >> s >> t;
    ll n1=s.length(), n2=t.length();
    vector<vi> dp(n1+1,vi(n2+1));
    fr(0,n1+1)
    {
        for(ll j=0;j<n2+1;++j)
        {
            if(i==0 || j==0) continue;
            if(s[i-1]==t[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
            {
                dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }
    string str="";
    ll i=n1,j=n2;
    while(i>0 && j>0)
    {   
        if(s[i-1]==t[j-1])
        {   str+=s[i-1];
            --i;
            --j;
        }
        else
        {
            if(dp[i-1][j]==dp[i][j])
            {
                i--;
            }
            else
                --j;
        }
    }
    reverse(str.begin(),str.end());
    cout << str ;
    return 0;
}

Measured memory_bytes: 70784
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <ctime>
#include <list>
#include <numeric>
#include <fstream>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PI;
#ifndef M_PI
const double M_PI=acos(-1.0);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
void pkuassert(bool b){if(!b){int a=0;cout << 1/a << endl;}};
int dx[]={0,-1,0,1,1,1,-1,-1},dy[]={1,0,-1,0,1,-1,1,-1};

string in;

int num(int s,int t){
  int ret=0;
  rep(i,t-s) ret=ret*10+in[s+i]-'0';
  return ret;
}
int memo[6][1000000];

int rec(int ne,int les,bool pr=false){
  if(les<0) return 0;
  if(ne==SZ(in)) return les==0;
  if(!pr && memo[ne][les]!=-1) return memo[ne][les];
  if(num(ne,SZ(in))<les) return 0;
  int& ret=memo[ne][les]=0;
  
  for(int i=ne+1;i<=SZ(in);++i){
    ret += rec(i,les-num(ne,i));
    if(pr && ret){
      cout << ' ' << in.substr(ne,i-ne);
      rec(i,les-num(ne,i),true);
      return 0;
    }
    if(ret>1) return ret=2;
  }
  return ret;
}

int t;
void solve(){
  memset(memo,-1,sizeof(memo));
  while(t){
    if(rec(0,t)==1){
      cout << t;
      rec(0,t,true);
      cout << endl;
      return;
    }
    if(rec(0,t)>1){
      cout << "rejected" << endl;
      return;
    }
    --t;
  }
  cout << "error" << endl;
}

int main(){
  while(cin >> t >> in && t && in!="0") solve();
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static llong MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

const int N = 300;
llong dist[N][N], a[N][N];
bool check_road_needed[N][N];

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    rep(i, n) {
        rep(j, n) {
            cin >> a[i][j];
            dist[i][j] = a[i][j];
            check_road_needed[i][j] = true;
        }
    }

    rep(i, n) {
        rep(j, n) {
            rep(k, n) {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }

    rep(i, n) {
        rep(j, n) {
            if (dist[i][j] != a[i][j]) {
                cout << -1 << endl;
                return 0;
            }

            rep(k, n) {
                if (a[i][j] == a[i][k] + a[k][j] && i != k && j != k) check_road_needed[i][j] = false;
            }
        }
    }

    llong ans = 0;
    rep(i, n) {
        rep(j, n) {
            if (check_road_needed[i][j]) ans += a[i][j];
        }
    }

    cout << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  cin >> N;
  int A[N] ,B[N];
  
  int i = 0;
  while(cin >> A[i]){
    i++;
  }
  
  for(int i = 0; i < N; i++){
    int tmp;
	tmp = A[i];
    B[tmp-1] = i+1;
  }

  for(int i = 0; i < N; i++){
    cout << B[i] << " ";
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 1536
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {in_n: u64, in_ab: [[u64; 2]; in_n]};
    let mut a = Vec::new();
    let mut b = Vec::new();

    for ab in &in_ab {
        a.push(ab[0]);
        b.push(ab[1]);
    }

    a.sort();
    b.sort();

    if a.len() % 2 == 0 {
        let i = a.len() / 2;
        let minval = a[i] + a[i - 1];
        let maxval = b[i] + b[i - 1];
        let v = maxval - minval + 1;

        println!("{}", v);
    } else {
        let i = a.len() / 2;
        let v = b[i] - a[i] + 1;

        println!("{}", v);
    }
}


Measured memory_bytes: 20712
import java.util.Scanner;


class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int a = sc.nextInt();
   int b = sc.nextInt();


   if(a>=b){
     for(int i=0;i<a;i++){
     System.out.print(b);
     }
   }
   else if(a<b){
     for(int i=0;i<b;i++){
     System.out.print(a);
     }
   }
 
 }
}


Measured memory_bytes: 21076
use proconio::input;
use proconio::marker::Usize1;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
fn main() {
    input!(R: usize, C: usize, K: usize);
    let mut values = vec![vec![0; C + 1]; R + 1];
    for _ in 0..K {
        input!(r: usize, c: usize, v: usize);
        values[r][c] = v;
    }

    let mut dp = vec![vec![vec![0; 4]; C + 1]; R + 1];
    for i in 1..R + 1 {
        for j in 1..C + 1 {
            let m = line_max(i, j, &mut dp);

            dp[i][j][0] = max(m, dp[i][j - 1][0]);
            dp[i][j][1] = max(
                m + values[i][j],
                max(dp[i][j - 1][0] + values[i][j], dp[i][j - 1][1]),
            );
            dp[i][j][2] = max(
                m + values[i][j],
                max(dp[i][j - 1][1] + values[i][j], dp[i][j - 1][2]),
            );
            dp[i][j][3] = max(
                m + values[i][j],
                max(dp[i][j - 1][2] + values[i][j], dp[i][j - 1][3]),
            );
        }
    }

    let ans = max(dp[R][C][0], max(dp[R][C][1], max(dp[R][C][2], dp[R][C][3])));
    println!("{}", ans);
}

fn line_max(i: usize, j: usize, dp: &mut Vec<Vec<Vec<usize>>>) -> usize {
    let mut ret = 0;
    for k in 0..4 {
        ret = max(ret, dp[i - 1][j][k])
    }
    ret
}


Measured memory_bytes: 709016
#include<bits/stdc++.h>
using namespace std;
#define INF 100000
int dp[44][444][444];
int main(){
  int n,ma,mb;
  int a[44],b[44],c[44];
  cin>>n>>ma>>mb;
  for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
  
  fill_n(**dp,44*444*444,INF);
  dp[0][0][0]=0;
  int ans=INF;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<444;j++){
      for(int k=0;k<444;k++){
	if(dp[i][j][k]==INF)continue;
	dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
	dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
      }
    }
  }

  for(int i=1;i<444;i++)
    for(int j=1;j<444;j++)
      if(ma*j==mb*i)ans=min(ans,dp[n][i][j]);

  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
  
  return 0;
}


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

int main(void){
   int N;
   cin>>N;
   vector<string> S(N);
   for(int i=0;i<N;i++){
      cin>>S[i];
   }
   int result[4]={0};
   for(int i=0;i<N;i++){
      if(S[i]=="AC") result[0]++;
      if(S[i]=="WA") result[1]++;
      if(S[i]=="TLE") result[2]++;
      if(S[i]=="RE") result[3]++;
   }
   cout<<"AC"<<" x "<<result[0]<<endl;
   cout<<"WA"<<" x "<<result[1]<<endl;
   cout<<"TLE"<<" x "<<result[2]<<endl;
   cout<<"RE"<<" x "<<result[3]<<endl;
   return 0;
}


Measured memory_bytes: 6372
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    int maxv = 0;
    int sum = 0;
    REP(i, n)
    {
        int t;
        cin >> t;
        sum += t;
        maxv = max(maxv, t);
    }
    if (maxv < sum - maxv)
    {
        Yes(1);
    }
    else
    {
        Yes(0);
    }
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long

int main(void)
{
    ll x,y; cin>>x>>y;
    if(x==y) cout<<"a == b"<<endl;
    else if(x<y) cout<<"a < b"<<endl;
    else cout<<"a > b"<<endl;
    return 0;
} 


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define all(x) (x).begin()s,(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define IMX INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
char c[200005];
int n,rr;
LL ans;
int main()
{
    scanf("%s",c+1);
    n=strlen(c+1);
    rr=1;
    for(int i=1;i<=n;i++)
    {
        if(c[i]=='W')
        {
            ans+=i-rr;
            rr++;
        }
    }
    printf("%lld",ans);
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define int ll
#define INF (ll)1e18
#define maxn 100001
#define MOD 1000000007
ll qexp(ll x, ll y) { 
ll res = 1; 
while (y > 0){
if (y & 1){
res = res*x; 
			res %= MOD;
        		}
        		y = y>>1;
        		x = x*x; 
        		x %= MOD;
} 
    return res; 
}

int N;

int32_t main()
{
	cin>>N;
	
	int a = qexp(10,N);
	
	a -= (qexp(9,N) * 2) % MOD;
	while (a < 0) a += MOD;
	a %= MOD;
	a += qexp(8,N); a %= MOD;
	cout<<a;
	
}


Measured memory_bytes: 3620
n, q = map(int, input().split())

ct = [0] * (n+1)
o = [0] * (n+1)
g = [[] for _ in range(n+1)]

for i in range(n-1):
  a,b= map(int, input().split())
  g[a].append(b)
  g[b].append(a)

for i in range(q):
  p,x= map(int, input().split())
  o[p] += x

todo = [1]
seen = [False] * (n+1)
while todo:
  p = todo.pop(-1)
  ct[p] += o[p]
  seen[p] = True
  for i in g[p]:
    if seen[i]:
      ct[p] += ct[i]
    else:
      todo.append(i)

print(*ct[1:])


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

int main(){
    int n;
    std::cin >> n;

    std::string s;
    std::string arare{""};
    for(int i = 0; i < n; ++i){
        std::cin >> s;
        arare += s;
    }

    std::sort(arare.begin(), arare.end());
    arare.erase(std::unique(arare.begin(), arare.end()), arare.end());

    // for(int i = 0; i < arare.size(); ++i){
    //     std::cout << arare.at(i);
    // }
    // std::cout << std::endl;

    if(3 == arare.size()){
        std::cout << "Three" << std::endl;
    }else{
        std::cout << "Four" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ITP1_3_B
{
	class Program
	{
		static void Main(string[] args)
		{
			List<int> vs = new List<int>();

			for(int i = 1; i <= 10000; i++) {
				int j = int.Parse(Console.ReadLine());
				if(j == 0) {
					break;
				}

				vs.Add(j);
			}

			int index = 1;
			foreach(int i in vs) {
				Console.WriteLine($"Case {index++}: {i}");
			}
		}
	}
}



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

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    while (x) {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  cout << endl;
}


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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = (1ll << 30) - 1;  //nearly 1.07e9
const ll INFLL = 1ll << 60;       //nearly 1.15e18
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

//================ Main Loop ================
int main() {
    int n;
    cin >> n;
    int h[100100][3];
    rep(i, n) {
        rep(j, 3) {
            cin >> h[i][j];
        }
    }

    int dp[100100][3];
    rep(i, 100100) {
        rep(j, 3) {
            dp[i][j] = 0;
        }
    }

    rep(i, n) {
        rep(j, 3) {
            rep(k, 3) {
                if(j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + h[i][k]);
            }
        }
    }

    int ans = 0;
    rep(i, 3) {
        chmax(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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;
}


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

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

    if (N[0]=='S'){
        cout << "Cloudy" << endl;
    }

    else if (N[0]=='C'){
        cout << "Rainy" << endl;
    }

    else{
        cout << "Sunny" << endl;
    }

    return 0;
}

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

int main(){
	map<char, int> m;
	char a, b, c;
	m['A'] = 1;
	int n = 0;
	while(cin >> a >> c >> b){
		swap(m[a], m[b]);
		//if(++n == 5)break;
	}
	if(m['A'])cout << 'A' << endl;
	if(m['B'])cout << 'B' << endl;
	if(m['C'])cout << 'C' << endl;
	return 0;
}

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

int main(){
  int h,w;cin>>h>>w;
  string s;
  REP(i,h){
    cin>>s;
    cout<<s<<endl;
    cout<<s<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<stack>

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int no(char x){
	if(x=='A') return 14;
	else if(x=='T') return 10;
	else if(x=='J') return 11;
	else if(x=='Q') return 12;
	else if(x=='K') return 13;
	else return x-'0';
}

int main(){
	int i, j;
	//??? ans;
	int l, ns, ew, num;
	string play[4][13];
	char t, s, now;
	while(1){
		cin >> t;
		if(t == '#') break;
		l = 0;
		ns = 0;
		ew=0;
		REP(i,4)REP(j,13) cin >> play[i][j];
		REP(j,13){
			s = play[l][j][1];
			now = s;
			num = no(play[l][j][0]);
			REP(i,4){
				if(now!=t&&play[i][j][1]==t){
					now = t;
					num = no(play[i][j][0]);
					l = i;
				}
				if(play[i][j][1]==now && no(play[i][j][0])>num){
					num = no(play[i][j][0]);
					l = i;
				}
			}
			if(l==0||l==2)ns++;
			else ew++;
		}
		if(ew>ns)cout << "EW " << ew-6 << endl;
		else cout << "NS " << ns-6 << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
(n, m) = map(int, input().split())


def intersect(lhs, rhs):
    if lhs[1] < rhs[0] or rhs[1] < lhs[0]:
        return [0, 0]
    min_value = lhs[0] if lhs[0] > rhs[0] else rhs[0]
    max_value = lhs[1] if lhs[1] < rhs[1] else rhs[1]
    return [min_value, max_value]


ans = [-1, 2 * 10 ** 5]
for _ in range(m):
    ans = intersect(ans, list(map(int, input().split())))
    if 0 == ans[0] and 0 == ans[1]:
        print(0)
        exit(0)
print(ans[1] - ans[0] + 1)


Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<functional>
using namespace std;
typedef long long LL;
typedef pair<int, int> edge;

int N,Q,K;
vector<edge> edges[100010];
LL cost[100010]={};

void MakeTree(int now){
    for(int i=0;i<edges[now].size();i++){
        int to=edges[now][i].first;
        int d=edges[now][i].second;
        if(cost[to]==0 && to!=K){
            cost[to]=cost[now]+d;
            MakeTree(to);
        }
    }
}

int main(){
    cin >> N;
    for(int i=1;i<N;i++){
        int a,b,c;
        cin >> a >> b >> c;
        edges[a].push_back(make_pair(b,c));
        edges[b].push_back(make_pair(a,c));
    }    
    cin >> Q >> K;
    MakeTree(K);
    for(int i=0;i<Q;i++){
        int x,y;
        cin>>x>>y;
        cout << cost[x]+cost[y] << endl;
    }
    return 0;
}

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

int main() {
  double x1, y1, x2, y2, x12, y12, distance;
  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

  x12 = fabs(x1 - x2);
  y12 = fabs(y1 - y2);
  distance = sqrt(pow(x12, 2) + pow(y12, 2));

  printf("%lf", distance);

  return 0;
}


Measured memory_bytes: 2044
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main() {

	int n;
	cin >> n;
	vector<int>num;

	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		num.push_back(p);
	}



	int count = 0;
	for (int i = 1; i < n - 1; i++) {
		if ((num[i - 1] < num[i] && num[i] < num[i + 1])|| (num[i - 1] > num[i] && num[i] > num[i + 1])) {
			count++;
		}
	}

	cout << count << endl;

	return 0;

}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = [I() for _ in range(N)]
    A.sort()

    if N % 2 == 0:
        ans = (2 * sum(A[N//2:]) - A[N//2]) - (2 * sum(A[:N//2]) - A[N//2-1])
        print(ans)
    else:
        ans0 = 2 * sum(A[N//2+1:]) - (2 * sum(A[:N//2+1]) - A[N//2-1] - A[N//2])
        ans1 = (2 * sum(A[N//2:]) - A[N//2] - A[N//2+1]) - 2 * sum(A[:N//2])
        print(max(ans0, ans1))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 14348
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		while( scan.hasNextInt() ) {
			int d = scan.nextInt();
			int s = 0;
			
			for(int i = 1; (600 - i*d) > 0; i++) {
				s += Math.pow(d*i,2) * d;
			}
			
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 17200
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (h, w) = get!(usize, usize);
    let _n = get!(usize);

    let mut mm = vec![vec![0; w]; h];
    let mut i = 0;
    let mut j = 0;
    let mut d = 0;
    let mut c = 0;
    for a in get!(String).split_whitespace().map(|i| i.parse::<i32>().unwrap()) {
        c += 1;
        for _ in 0..a {
            mm[i][j] = c;
            match (d, j) {
                (0, _) if j+1 == w => { i += 1; d = 1; },
                (0, _) => j += 1,
                (_, _) if j == 0 => { i += 1; d = 0; },
                _ => j -= 1,
            }
        }
    }
    for line in mm.iter() {
        println!("{}", line.iter().map(ToString::to_string).collect::<Vec<_>>().join(" "));
    }
}

Measured memory_bytes: 4476
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0] * N
dp[0] = 0
for i in range(1,N):
    dp[i] = min([dp[i-j-1] + abs(h[i]-h[i-j-1]) for j in range(min(i,K))])
 
print(dp[-1])

Measured memory_bytes: 85320
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int i,j,buf;
    int k=2000000;
    int n;
    vector<int> A,B,C;
    
    cin >> n;
	for(i=0;i<n;i++){
		//cin >> A[i]; //?buf使わなくていいの？ ->使わなきゃダメだったエラー[vector subscript out of range]
		cin >> buf;
		A.push_back(buf);
	}
    
    for(i=0;i<k;i++){C.push_back(0);}

	for(i=0;i<n;i++){
		C[A[i]]++;
	}

    for(i=1;i<k;i++){C[i]+=C[i-1];}

	for(i=0;i<n;i++){B.push_back(0);} //最初にBに要素（配列）を全部確保しておいちゃう
	for(i=n-1;i>=0;i--){
		B[C[A[i]]-1] = A[i]; 
		C[A[i]]--;
	}

	//出力
	for(i=0;i<n-1;i++){ cout << B[i] << " "; }
	cout << B[n-1] << endl;
	
	return 0;
}

Measured memory_bytes: 29376
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <time.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;
using std::next_permutation;
using std::lower_bound;

long long max(long long a, long long b)
{
    if (a > b)
        return a;
    return b;
}
long long min(long long a, long long b)
{
    if (a > b)
        return b;
    return a;
}
typedef long long ll;
typedef pair<long long, long long> pii;
typedef pair<ll, ll> pll;

namespace MySpace{

};

#define forn(i, n) for (long long (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define int long long
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
ll n, k;
ll a[50000];
ll ans = 0;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    cin >> n >> k;
    int r = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        r += a[i];
        if (r <= k)
            ans++;
    }
    cout << ans + 1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int p=a;p<b;p++)
#define modulo 1000000007

int main()
{
    char ch[20],hc[20];
    cin>>ch;
    cin>>hc;
    int x=strlen(ch);

    bool flag=true;
    for(int i=0;i<x;i++)
    {
        if(ch[i]!=hc[i])
        {
            cout<<"No\n";
            flag=false;
            break;
        }
    }
    if(flag)
    {
        cout<<"Yes\n";
    }


    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;

int main()
{
  IOS
  string s;
  cin>>s;
  ll i,ans=0;
  ll l=s.length();
  ll cnt=0;
  for(i=0;i<l;i++)
  if(s[i]=='A')
  {
    ll c=0;
    ll j=i+1;
    while(j+1<l)
    {
      if(s[j]=='B' && s[j+1]=='C')
      {
        c++;
        j+=2;
      }
      else
        break;
    }
    i=j-1;
    cnt++;
    ans=ans+(cnt*c);
  }
  else
    cnt=0;
  cout<<ans;
  return 0; 
}

Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int csr[n]; //cumulative sum
    rep(i, n) csr[i] = 0;
    rep(i, n) if (s[i] == 'W') s[i] = 'L'; else s[i] = 'R';
    rep(i, n) if (s[i] == 'R') csr[i] = 1;
    rrep(i, 1, n) csr[i] += csr[i - 1];
    //min people who turn around
    //一番左 2番目以降左に
    int mpwta = csr[n - 1] - csr[0];
    //cout << mpwta << endl; mpwta = inf;
    
    //on the far right
    mpwta = min(mpwta, n - csr[n - 1]);
    //cout << mpwta << endl;
    //自分より左を右に
    rrep(i, 1, n - 1) {
        mpwta = min(mpwta, i - csr[i - 1] + (csr[n - 1] - csr[i]));
        //cout << mpwta << endl;
    }
    cout << mpwta << endl;
}


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

typedef pair<int,int> pi;
typedef vector<int> vi;
 
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define pb push_back

template<typename T> void max_self(T &a, T b) { a = max(a,b); return;}
template<typename T> void min_self(T &a, T b) { a = min(a,b); return;}
 
const int nax = 2e5 + 5;
const int mod = 1e9 + 7;

int modExpo(int a,int b,int c){
	if(b == 0) return 1;
	int answer = 1;
	while(b){
		if(b & 1) answer = ((answer % c) * (a % c)) % c;
		a = ((a % c) * (a % c)) % c;
		b /= 2; 
	}
	
	return answer;
}

signed main(){
	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		
		int answer = 0;
		for(int i = 1; i <= n ; ++i){
			int terms = n / i;
			int val = ((2 * i + (terms - 1) * i) * terms) / 2;
			answer = answer + val;
		}
		
		cout << answer;
	}
    
    return 0;
}


Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;


int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		for (int i = 0; i < a; i++) {
			cout << a;
		}
		cout << endl;
	}
	else {
		int out = min(a, b);
		int roop = max(a, b);
		for (int i = 0; i < roop; i++) {
			cout << out;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main(){
    int q, l, r;
    cin >> q;
    int A[100001]={0}, S[100002]={0};
    for(int i=0;i<=100000;i++) A[i] = 1;
    A[0]=0;
    A[1]=0;
    for(int i=2;i<=100000;i++){
        if(!A[i]) continue;
        for(int j=2*i;j<=100000;j+=i) A[j]=0;
    }

    for(int i=2;i<=100000;i++){
        if(A[i]&&A[(1+i)/2]) S[i+1]=S[i]+1;
        else S[i+1]=S[i];
    }
    
    for(int i=0;i<q;i++){
        cin >> l >> r;
        r++;
        cout << S[r]-S[l] << endl;
    }

    return 0;

}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var stack = new Stack<int>();
            var small = input[0];
            if (input[0] > input[1])
            {
                small = input[1];
            }

            for (var i = 1; i <= small; i++)
            {
                if (input[0] % i == 0 && input[1] % i == 0)
                {
                    stack.Push(i);
                }
            }

            for (var i = 1; i < input[2]; i++)
            {
                stack.Pop();
            }
            Console.WriteLine(stack.Pop());
        }
    }
}


Measured memory_bytes: 13396
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let x: String = read();
    let mut cnt: i32 = 0;
    let mut max = 0;
    for c in x.chars() {
        if c != 'T' {
            cnt -= 1
        } else {
            cnt += 1;
        }
        if cnt > max {
            max = cnt;
        }
    }
    println!("{}", max * 2);
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.ABC168
{
    /// <summary>
    /// 
    /// </summary>
    static class A
    {
        static void Main(string[] args)
        {
            var n = NextInt();

            var last = n.ToString().Last();
            var yomi = "";
            switch (last)
            {
                case '2':
                case '4':
                case '5':
                case '7':
                case '9':
                    yomi = "hon";
                    break;
                case '0':
                case '1':
                case '6':
                case '8':
                    yomi = "pon";
                    break;
                case '3':
                    yomi = "bon";
                    break;
                default:
                    break;
            }

            Console.WriteLine(yomi);
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 27852
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    var(string, s);

    string t[] = {
        "Sunny", "Cloudy", "Rainy"
    };

    rep(i, 3) {
        if (t[i] == s) {
            print(t[(i + 1) % 3]);
        }
    }

    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string L;
    cin >> L;
    ll sum = 0;
    int count1 = 0;
    vector<ll> two(L.size()+1);
    vector<ll> three(L.size()+1);
    ll tw = 1,th = 1;
    two.at(0) = 1;
    three.at(0) = 1;
    for(int i = 1;i < L.size()+1;i++){
        tw = tw * 2 % mod;
        th = th * 3 % mod;
        two.at(i) = tw;
        three.at(i) = th;
    }
    REP(i,L.size()){
        if(L.at(i) == '1'){
            sum = (sum + two.at(count1) * three.at(L.size()-i-1))%mod;
            count1++;
        }
    }
    sum += two.at(count1);
    cout <<sum % mod<< "\n";
}


Measured memory_bytes: 2000
#include <bits/stdc++.h>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
int MOD = 998244353;

ll ar[200009];
int N;
ll dp[200009];
ll odd[200009];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> N;
	for(int i=1; i <= N; i++) cin >> ar[i];
	odd[1] = ar[1];
	for(int i=2; i <=N; i++){
        if(i%2!=0) odd[i] = odd[i-2]+ ar[i];
	}
	dp[0] = dp[1] = 0;
	for(int i=2; i <= N; i++){
        dp[i] = dp[i-2] + ar[i];
        if( i % 2 == 0 ) dp[i] =  max( dp[i], odd[i-1] );
        else{
            dp[i] = max(dp[i], dp[i-1] );
        }
	}
	cout << dp[N];

}


Measured memory_bytes: 8240