akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<deque>
using ll = long long;
signed
main(){
    int n; std::cin >> n;
    std::vector<std::pair<ll,ll>>v;
    for(int i= 0; i < n; ++i){
        std::pair<ll,ll>p;
        std::cin >> p.second >> p.first;
        v.push_back(p);
    }
    std::sort(v.begin(),v.end());
    ll crt = 0;
    for(auto e : v){
        if(crt + e.second <= e.first){
            crt += e.second;
        } else {
            return puts("No")*0;
        }
    }
    std::cout << "Yes" << std::endl;
}



Measured memory_bytes: 6512
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        hs: [i64; n],
    }
    let mut dp = vec![0; n];
    dp[0] = 0;
    dp[1] = (hs[0] - hs[1]).abs();
    for i in 2..n {
        dp[i] = std::cmp::min(
            dp[i - 2] + (hs[i] - hs[i - 2]).abs(),
            dp[i - 1] + (hs[i] - hs[i - 1]).abs(),
        );
    }
    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

void dump(list<int> l) {
    list<int>::iterator it = l.begin();
    if (it != l.end()) {
        cout<<*it;
        it++;
        while (it != l.end()) {
            cout<<" "<<*it;
            it++;
        }
    }
    cout<<endl;
}

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

    int n, q;
    cin>>n>>q;
    vector<list<int>> ls(n);
    rep(i, q) {
        int j, t, x;
        cin>>j>>t;
        if (j == 0) {
            cin>>x;
            ls[t].insert(ls[t].end(), x);
        }
        else if (j == 1) {
            dump(ls[t]);
        }
        else {
            cin>>x;
            list<int>::iterator it = ls[x].end();
            ls[x].splice(it, ls[t]);
            ls[t].clear();
        }
    }
}


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

typedef long long ll;

int main() {
    int D, G;
    cin >> D >> G;
    int p[11], c[11];
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for (int mask = 0; mask < (1<<D); mask++) {
        int s = 0, num = 0, rest_max = -1;
        for (int i = 0; i < D; i++) {
            if (mask >> i & 1) {
                s += (i+1)*100*p[i] + c[i];
                num += p[i];
            } else {
                rest_max = i;
            }
        }

        if (s < G) {
            int s1 = (rest_max+1) * 100;
            int need = (G-s+s1-1) / s1;
            if (need >= p[rest_max]) continue;
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n,c = map(int,input().split())
x = [0]
v = [0]
rf = [0] * (n+2)
rg = [0] * (n+2)
lf = [0] * (n+2)
lg = [0] * (n+2)
for i in range(0,n):
    X,V = map(int,input().split())
    x.append(X)
    v.append(V)
for i in range(0,n):
    rf[i+1] = rf[i] + v[i+1]
    rg[i+1] = max(rg[i],rf[i+1] - x[i+1])
for i in range(n+1,1,-1):
    lf[i-1] = lf[i] + v[i-1]
    lg[i-1] = max(lg[i],lf[i-1] - (c-x[i-1]))

ans = max(rg[n],lg[1])
for i in range(1,n):
    ans = max(ans,rg[i]+lg[i+1] - x[i],rg[i]+lg[i+1] - (c - x[i+1]))
print(ans)


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

int main() {

	int num1 = 0, num2 = 0;
	int coua = 0, coub = 0;
	int key = 0;
	char wo[20];

	cin >> num1 >> num2;

	
	cin >> wo;


	for (int i = 0; i < num1; i++) {
		if (wo[i] != '-'&&wo[i] != '\0') { coua += 1; }
	}

	
	if (wo[num1] == '-') { key = 1; }

	for (int i = num1+1; wo[i] != '\0'; i++) {
		if (wo[i] != '-'&&wo[i] != '\0') { coub += 1; }
	}


	if (key == 1) {
		if (coua == num1 && coub == num2) { cout << "Yes" << endl; }
		else { cout << "No" << endl; }
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import defaultdict

# mod mでの二項係数を求める
class BiCoeff(object):
    def __init__(self, MAX, m):
        super(BiCoeff, self).__init__()
        fac = [0]*MAX
        finv = [0]*MAX
        inv = [0]*MAX

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2,MAX):
            fac[i] = (fac[i-1]*i)%m
            inv[i] = m - (inv[m%i] * (m//i))%m
            finv[i] = (finv[i-1] * inv[i])%m

        self.MAX = MAX
        self.m = m
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calc(self,n,k):
        if n<k:
            return 0
        if n<0 or k<0:
            return 0
        return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m

MOD = 10**9+7
n, m = map(int, input().split())

pl = defaultdict(int)
x = m
p = 2
while p*p<x+10:
    while x%p==0:
        pl[p] += 1
        x //= p
    p += 1
if x>1:
    pl[x] += 1


coeff = BiCoeff(10**6, MOD)
res = 1
for k in pl:
    res *= coeff.calc(n+pl[k]-1, pl[k])
    res %= MOD
print(res)


Measured memory_bytes: 62960
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  if(a>b)cout << a-1 << endl;
  else cout << a << endl;
}


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

int main(void){
    int a, b;
    cin >> a >> b;
    int ans;
    if(a < b)
        ans = 0;
    if(a >= b)
        ans = 10;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# if x < y:
#     z = x
# elif True:
#     z = y
# else:
#     z = 100
import sys,os,math
from collections import Counter, defaultdict
import bisect
from sys import stdin, stdout
from itertools import repeat


# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())

def main():
    n, m = map(int, raw_input().split())
    bf, af = [10000000 for i in range(1<<n)], [10000000 for i in range(1<<n)]
    bf[0] = 0
    for i in range(m):
        a, b = map(int, raw_input().split())
        ad = 0
        for st in map(int, raw_input().split()):
            ad |= 1<<(st-1)
        for st in range(1<<n):
            af[st|ad] = min(bf[st|ad], bf[st]+a, af[st|ad])
        for st in range(1<<n):
            af[st] = min(af[st], bf[st])
        bf, af = af, bf
    if bf[(1<<n)-1] == 10000000:
        print -1
    else:
        print bf[(1<<n)-1]



main()


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }

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

  bool can = false;
  re(i, n/4+1) {
    re(j, n/7+1){
      if(4 * i + 7 * j == n) can = true;
    }
  }

  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int a, b, t;
    cin >> a >> b >> t;
    cout << (t / a) * b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int maxN = 1e5 + 13, INF = 1e9 + 13;
int n, m, cmp, a[maxN], par[maxN], indx[maxN];
long long ans;
vector<int> vec[maxN], sec;
set<pair<int, int>> st;
int get_par (int x) {
    if (x == par[x])
	return x;
    return par[x] = get_par(par[x]);
}

int32_t main () {
    cin >> n >> m;
    iota(par, par + n, 0);
    for (int i = 0; i < n; i++)
	cin >> a[i];
    
    for (int i = 0; i < m; i++) {
	int x, y;
	cin >> x >> y;
	int p1 = get_par(x), p2 = get_par(y);
	if (p1 != p2) {
	    par[p1] = p2;
	}
    }
    
    if (m == n - 1)
	return cout << 0 << endl, 0;
    for (int i = 0; i < n; i++) {
	int p = get_par(i);
	vec[p].push_back(a[i]);
    }
    for (int i = 0; i < n; i++) {
	sort(vec[i].begin(), vec[i].end());
	if (vec[i].size())
	    ans += vec[i][0];
	for (int j = 1; j < vec[i].size(); j++)
	    sec.push_back(vec[i][j]);
    }

    sort(sec.begin(), sec.end());
    int s = sec.size();
    if (s < n - m - 2) 
	return cout << "Impossible" << endl, 0;
    
    for (int i = 0; i < n - m - 2; i++)
	ans += sec[i];
    cout << ans << endl;
	
	
}
	


Measured memory_bytes: 8064
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    int queryCount;
    scanf("%d", &queryCount);

    for (int i = 0; i < queryCount; ++i) {
        long long res = 0;
        long long first, second;

        scanf("%lld%lld", &first, &second);

        long long x = (long long)sqrt(first * second - 1);

        while (x * x >= first * second) x--;

        res = x * 2;

        if (first <= x) res--;
        if (second <= x) res--;

        if ((x + 1) * x >= (first * second)) {
            res--;
        }

        printf("%lld\n", res);
    }

    return 0;
}


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

const int MAXN = 503;
int H[MAXN][MAXN];
bool occ[MAXN][MAXN];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int x, int y)
{
    int z = H[x][y] + occ[x][y];
    rep(i,4)
    {
        int x1 = x+dx[i], y1 = y+dy[i];
        if (z < H[x1][y1])
        {
            H[x1][y1] = z;
            dfs(x1, y1);
        }
    }

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    // Failed to predict input format
    int n;
    cin >> n;
    REP(i,1,n+1) REP(j,1,n)
    {
        occ[i][j] = true;
        H[i][j] = min(min(i-1, n-i), min(j-1, n-j)) ;
    }

    int res = 0;
    rep(i,n * n)
    {
        int idx;
        cin >> idx;
        idx--;
        int x = idx%n;
        int y = idx/n;
        x++;
        y++;
        res += H[x][y];
        occ[x][y] = false;
        dfs(x,y);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 20304
package main

import "fmt"

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	l := make([]int, n+1)
	r := make([]int, n+1)
	l[0] = 0
	r[0] = 0
	for i := 0; i < n; i++ {
		l[i+1] = gcd(a[i], l[i])
		r[n-1-i] = gcd(a[n-1-i], r[n-i])
	}

	ans := 0
	for i := 0; i < n; i++ {
		t := gcd(l[i], r[i+1])
		if ans < t {
			ans = t
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <stdio.h>
#include <string.h>
int main()
{
	char s[3];
	int i,l,a=0;
	gets(s);
	l=strlen(s);
	for(i=0;i<l;i++)
	{
		if(s[i]=='1')
		a++;
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 128
N,A,B=map(int, input().split())
D=[int(input()) for i in range(N)]

def f(a):
  E=[]
  for i in range(N):
    if D[i]-a*B>0:
      E.append(D[i]-a*B)
  cnt=0
  for i in E:
    cnt+=-(-i//(A-B))
  if cnt<=a:
    return True
  else:
    return False
l,r=0,10**9
for i in range(50):
  mid=(l+r)//2
  if f(mid):
    r=mid
  else:
    l=mid
print(r)

Measured memory_bytes: 16776
#include <stdio.h>
#include <string.h>

int main() {
	char input[512][34];

	int max_length  = 0;
	int index_max_length;

	int count_appear[512] = {0};
	int index_most_appear;

	int i, j;
	
	i = 0;
	while(scanf("%s", input[i]) != EOF) {
		if(strlen(input[i]) > max_length) {
			max_length = strlen(input[i]);
			index_max_length = i;
		}

		for(j = 0; j < i; j++) {
			if(strcmp(input[j], input[i]) == 0) {
				count_appear[j]++;
				i--;
				break;
			}
		}

		i++;
	}

	for(j = 0, index_most_appear = 0; j < i; j++)
		if(count_appear[index_most_appear] < count_appear[j])
			index_most_appear = j;

	printf("%s %s\n", input[index_most_appear], input[index_max_length]);

	return 0;
}

Measured memory_bytes: 564
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


import sys

read = sys.stdin.buffer.read

N, Q, *TUV = map(int, read().split())
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


Measured memory_bytes: 52344
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N, K;
    cin >> N >> K;
    int digits = 1;

    while(N > 0)
    {
        N /= K;
        if(N > 0)
        {
            digits++;
        }
    }

    cout << digits;

    return 0;
}

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

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> v(N, -1);
    int digit, num;
    bool can = true;
    for (int i = 0; i < M; i++) {
        cin >> digit >> num;
        digit--;
        if (v[digit] != -1 && v[digit] != num) {
            can = false;
            break;
        }
        v[digit] = num;
    }
    if (N >= 2 && v[0] == 0) can = false;
    if (can == false) {
        cout << -1 << '\n';
    }
    else {
        for (int i = 0; i < N; i++) {
            if (v[i] != -1) {
                cout << v[i];
            }
            else if (i == 0) {
                if (N == 1)
                    cout << 0;
                else
                {
                    cout << 1;
                }
            }
            else {
                cout << 0;
            }
        }
        cout << '\n';
    }
}

Measured memory_bytes: 256
program abc133b
   implicit none
   integer :: n, d , i, j, counter
   double precision, allocatable :: x(:,:)
   double precision :: dist, diff

   read(*,*) n, d
   allocate(x(n,d) )

   do i = 1, n
      read(*,*) x(i,:)
   end do

   dist = 0.
   counter = 0
   diff = 0.

   do i = 1, n-1
      do j = i+1, n
         dist = dble(sum( (X(i,:) -X(j,:))**2 ) )
         dist = sqrt(dist)
         diff = abs(dist -dble(nint(dist) ))
         !print *, i, j, diff
         if ( diff == 0. .or. diff <= 1.e-12 ) then
            counter = counter + 1
         end if
      end do

   end do

   print *, counter



end program abc133b


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   if (N <= 9) cout << N << endl;
   else if (N <= 99) cout << 9 << endl;
   else if (N <= 999) cout << N - 90 << endl;
   else if (N <= 9999) cout << 909 << endl;
   else if (N <= 99999) cout << N - 90 - 9000 << endl;
   else cout << 90909 << endl;
   return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;


using Graph=vector<vector<int>>;//グラフ型
void dfs(const Graph &G,int v/*根*/,vector<bool> &seen){
    seen[v]=true;  //vを訪問済にする
    for(auto next_v:G[v]){ //訪問済にしたvとつながっている場所を順番に探す
        if(seen[next_v]) continue; //もし探索済みならスルー
        dfs(G,next_v,seen); //再帰的に探索
    }
}

void bfs(const Graph &G,queue<int> &que/*発見したが訪問はしていない*/,vector<int> &dist/*開始地点からの距離*/){
    while(!que.empty()){
        int v=que.front();//queのうち先頭のものからスタート
        que.pop();//先頭を削除

        for(int nv :G[v]){//vとつながっている点を列挙
            if(dist[nv]!=-1) continue;//発見済(=距離が格納されている)であればスルー
            dist[nv]=dist[v]+1;//vとつながっている点に距離の情報を追加
            que.push(nv);//vとつながっている点を発見済にする
        }
    }
}

int main(void){
    int a,b;
    cin>>a>>b;
    for(int i=1;i<1500;++i){
        if(floor(i*0.08)==a&&floor(i*0.1)==b){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
}


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

int main() {
  int X;
  cin >> X;
  
  int S;
  S = X/500;
  
  int M;
  M = (X - (S*500))/5;
  
  int N;
  N = S*1000 + M*5;
  cout << N << endl;
}

Measured memory_bytes: 256
A, B = map(int,input().split())

count=0 #初期化
for C in range(1,4):
    if A*B*C %2 ==1:
        count=count+1#Cに順番に１、２、３と代入していく中で、A×B×C が奇数になるたんびにcountに１加算していく
if count>0: #A×B×Cが奇数になるようなCが少なくとも１つ存在していたらYesと表示したい
    print("Yes")
    
else:
    print("No")

Measured memory_bytes: 9092
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
#define int long long
	int n, k;
	cin >> n >> k;
	vector<int> a, b;
	a.push_back(0);
	b.push_back(0);
	for (int i = 0; i < n; ++i) {
		int c;
		cin >> c;
		if (c < 0) {
			a.push_back(-c);
		}
		else {
			b.push_back(c);
		}
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	long long ans = LONG_INF;
	for (int tere = 0; tere < 2; ++tere) {
		for (int i = 0; i < a.size(); ++i) {
			long long geko = a[i] * 2LL;
			if (k - i < b.size()) {
				geko += b[k - i];
				ans = min(ans, geko);
			}
		}
		swap(a, b);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main()
{
    string str,com;
    cin >> str;

    int q,num1,num2;
    cin >> q;

    for(int i=0;i<q;i++){
        cin >> com >> num1 >> num2;
        if(com=="print"){
            for(int j=num1;j<=num2;j++){
            cout << str[j];
            }
            cout << endl;
        }
        else if(com=="reverse"){
            for(int j=num1;j<num1+(num2-num1+1)/2;j++){
                swap(str[num2+num1-j], str[j]);
            }
        }
        else if(com=="replace"){
            string s;
            cin >> s;
            str.replace(num1,num2-num1+1,s);
        }
    }
    
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";
int main(){
  int H, N; cin >> H >> N;
  long long sum = 0;
  rep(i, N) {
    int A; cin >> A;
    sum += A;
  }
  if (sum >= H) cout << YES << endl;
  else cout << NO << endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()
W = [0]
E = [0]
ans = float('inf')
for s in S:
    if s == "W":
        W.append(W[-1]+1)
        E.append(E[-1])
    else:
        W.append(W[-1])
        E.append(E[-1]+1)
for i in range(1, N+1):
    ans = min(ans, W[i-1]+E[-1]-E[i])
print(ans)


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll N,K;
    cin>>N>>K;
	string S;
	cin>>S;
    ll ans = 0;
    ll s = 0;
    ll ind_s=0,ind_f = 0;
    ll c = 0;
    while(ind_f<N){
        while(ind_f!=N){
            while(c<K&&ind_f!=N){
                while(S[ind_f]=='1'&&ind_f!=N){
                    ++ind_f;
                }
                if(ind_f!=N){
                    ++c;
                    while(S[ind_f]=='0'&&ind_f!=N){
                        ++ind_f;
                    }   
                }
                while(S[ind_f]=='1'&&ind_f!=N){
                    ++ind_f;
                }
            }
            ans = max(ans,ind_f-ind_s);
            // cout<<ind_s<<" "<<ind_f<<"\n";
            while(S[ind_s]=='1'&&ind_s!=N){
                ++ind_s;
            }
            
            if(ind_s!=N){
                --c;
                while(S[ind_s]=='0'&&ind_s!=N){
                    ++ind_s;
                }   
            }
        }
    }
    cout<<ans<<"\n";
	return 0;
}



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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)
#define PI 3.14159265358979323846


typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

int main(){
	int a, b, h, m;
	cin >> a>>b>>h>>m;
	m += 60*h;
	double w1 = 2.0*PI/60, w2 = 2.0*PI/(12*60);
	double a1 = m*w1, a2 = m*w2;
	double diff = a2-a1;
	double ans = sqrt(a*a + b*b - 2*a*b*cos(diff));
	printf("%.14lf\n", ans);
	return 0;
}


Measured memory_bytes: 4188
// C++ 14
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define MAX_H 1401
#define MAX_W 1401

Int H, W;
bool C[MAX_H][MAX_W];
Int HIST[MAX_H][MAX_W];

void input() {
  cin >> H >> W;
  loop(h,0,H) {
    loop(w,0,W) {
      cin >> C[h][w];
    }
  }
}

// O(N)
Int max_hist(Int hist[]) {
  stack<Int> S;
  Int max_ = 0, area = 0, tp = -1, width = 0;

  loop (i,0,W) {
    Int height = hist[i];

    // Pop every bar which is higher than me and calculate area for each of them.
    while (!S.empty() && hist[S.top()] > height) {
      tp = S.top();S.pop();

      width = S.empty() ? i : i - S.top() - 1;
      area = hist[tp] * width;
      if (max_ < area) max_ = area;
    }

    // Now bars are sorted in ascending order (greater or equal)
    S.push(i);
  }

  Int maxWidth = W;
  while (!S.empty()) {
    tp = S.top();S.pop();

    width = S.empty() ? maxWidth : maxWidth - S.top() - 1;
    area = hist[tp] * width;
    if (max_ < area) max_ = area;
  }

  return max_;
}

void solve() {
  loop(w,0,W) {
    HIST[0][w] = C[0][w] ? 0 : 1;
  }

  loop(w,0,W) {
    loop(h,1,H) {
      HIST[h][w] = C[h][w] ? 0 : HIST[h-1][w] + 1;
    }
  }

  Int max_ = 0;
  loop(h,0,H) {
    max_ = max(max_, max_hist(HIST[h]));
  }

  cout << max_ << endl;
}

int main(void) {
  input();
  solve();
}


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

#define ll long long
namespace flow{
	const ll __ = 1e6 + 7 , _ = 1e5 + 7;
	struct Edge{ll end , upEd , f , c;}Ed[__];
	ll head[_] , cntEd , S , T;
	void clear(){memset(head , 0 , sizeof(head)); cntEd = 1; S = T = 0;}
	void addEd(ll a , ll b , ll c , ll d){Ed[++cntEd] = (Edge){b , head[a] , c , d}; head[a] = cntEd;}
	void addE(ll a , ll b , ll c , ll d){addEd(a , b , c , d); addEd(b , a , 0 , -d);}

	bool vis[_]; queue < ll > q; ll dis[_] , pre[_];
	bool bfs(){
		q.push(S); memset(dis , -0x3f , sizeof(ll) * (T + 2)); dis[S] = 0;
		while(!q.empty()){
			ll t = q.front(); q.pop(); vis[t] = 0;
			for(ll i = head[t] ; i ; i = Ed[i].upEd)
				if(Ed[i].f && dis[Ed[i].end] < dis[t] + Ed[i].c){
					dis[Ed[i].end] = dis[t] + Ed[i].c; pre[Ed[i].end] = i;
					if(!vis[Ed[i].end]){vis[Ed[i].end] = 1; q.push(Ed[i].end);}
				}
		}
		return dis[T] != dis[T + 1];
	}
	
	ll EK(ll s , ll t , ll tarf , ll tarc){
		S = s; T = t; ll sum = 0;
		while(bfs()){
			ll cur = T; --tarf;
			while(cur != S){
				ll t = pre[cur]; cur = Ed[t ^ 1].end; --Ed[t].f; ++Ed[t ^ 1].f;
				if(Ed[t].c == 1e16) --tarc; else if(Ed[t].c == -1e16) ++tarc; else sum += Ed[t].c;
			}
		}
		return !tarf && !tarc ? sum : -1;
	}
}

ll bound[2][2][103] , N , M , X[83] , Y[83]; ll v[83];

signed main(){
	cin >> N; for(ll i = 1 ; i <= N ; ++i) cin >> X[i] >> Y[i] >> v[i];
	cin >> M; memset(bound , 0x3f , sizeof(bound));
	for(ll i = 1 ; i <= M ; ++i){
		char c; ll p , q; cin >> c >> p >> q;
		switch(c){
		case 'L': bound[0][0][p] = min(bound[0][0][p] , q); break;
		case 'R': bound[0][1][p] = min(bound[0][1][p] , q); break;
		case 'U': bound[1][0][p] = min(bound[1][0][p] , q); break;
		case 'D': bound[1][1][p] = min(bound[1][1][p] , q); break;
		}
	}
	ll ans = 0;
	for(ll i = 1 ; i <= N ; ++i){
		flow::clear(); bool flg = bound[0][0][100] >= i && bound[1][1][100] >= i; ll cnt = 0;
		for(ll j = 1 ; j <= 100 ; ++j){
			ll dwn = max(0ll , i - bound[0][0][j - 1]) , up = bound[0][1][j]; flg &= dwn <= up;
			cnt += dwn; flow::addE(j , j + 1 , dwn , (ll)1e16); flow::addE(j , j + 1 , up - dwn , 0);
		}
		for(ll j = 100 ; j ; --j){
			ll dwn = max(0ll , i - bound[1][1][j - 1]) , up = bound[1][0][j]; flg &= dwn <= up;
			cnt += dwn; flow::addE(202 - j , 203 - j , dwn , (ll)1e16); flow::addE(202 - j , 203 - j , up - dwn , 0);
		}
		for(ll j = 1 ; j <= N ; ++j) flow::addE(X[j] + 1 , 202 - Y[j] , 1 , v[j]);
		flow::addE(0 , 1 , i , 0); if(flg) ans = max(ans , flow::EK(0 , 202 , i , cnt));
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    double ans = 0.0;
    rep(i, n) {
        int a; cin >> a;
        ans += 1.0/a;
    }
    cout << fixed << setprecision(12) << 1.0/ans << endl;

    return 0;
}


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

const int N=100100;
int n,vis[N],col[N],ra,rb;
vector<int>g[N],ga[N],gb[N];
void add_edge(int x,int y){
	g[x].push_back(y);
	g[y].push_back(x);
}
int dfs(int x,vector<int>*g){
	int la=0;
	for(int i:g[x]){
		int u=dfs(i,g);
		if(!la)la=u;
		else add_edge(la,u),la=0;
	}
	if(la==0)vis[x]++,la=x;
	return la;
}
void dfs2(int x,int y){
	col[x]=y;
	for(int i:g[x])if(!col[i])dfs2(i,-y);
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
		int x;cin>>x;
		if(x==-1)ra=i;
		else ga[x].push_back(i);
	}
	for(int i=1;i<=n;++i){
		int x;cin>>x;
		if(x==-1)rb=i;
		else gb[x].push_back(i);
	}
	dfs(ra,ga);dfs(rb,gb);
	for(int i=1;i<=n;++i)
		if(vis[i]&1){
			cout<<"IMPOSSIBLE\n";
			return 0;
		}
	cout<<"POSSIBLE\n";
	for(int i=1;i<=n;++i){
		if(vis[i]&&!col[i])dfs2(i,1);
		cout<<col[i]<<" \n"[i==n];
	}
	return 0;
}


Measured memory_bytes: 20352
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll f(ll n){
    return (n*n + 4) / 8;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll T[110];
    cin >> N;
    rep(i,0,N) cin >> T[i];
    ll M;
    ll P[110], X[110];
    cin >> M;
    rep(i,0,M) cin >> P[i] >> X[i];
    ll sum = 0;
    rep(i,0,N) sum += T[i];
    rep(i,0,M){
        P[i]--;
        print(sum + X[i] - T[P[i]]);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    string S;
    cin >> S;
    int N = int(S.length());
    vector<int> a(N,0),b(N,0);
    
    int aa = 0, bb = 0;
    char now = '<';
    if(S[N-1] == '<') S+='>';
    else S+='<';
    
    rep(i,N){
        if(S[i] == now){
            if(now == '<') a[aa]++;
            else b[bb]++;
        }else{
            if(now == '<') now = '>', aa++, b[bb]++;
            else now = '<', bb++, a[aa]++;
        }
        
    }

    
    ll ans = 0;
    rep(i,N){
        ll c = ll(max(a[i], b[i]));
        ll d = ll(min(a[i], b[i]));
        d--;
        
        ans += (c+1)*c/2;
        ans += d*(d+1)/2;
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 4740
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main(){
	
	int N;
	cin >> N;
	
	int D[12] = {};
	int P[100] = {};
	
	for(int i = 0; i < N; i++){
		int num;
		cin >> num;
		P[i] = num;
		if(num == 0){
			cout << "0" << endl;
			return 0;
		}
		D[num - 1]++;
	}
	
	for(int i = 0; i < 12; i++){
		if(D[i] >= 3){
			cout << "0" << endl;
			return 0;
		}
	}
	if(N > 12){
		cout << "1" << endl;
		return 0;
	}
	
	int ans = 0;
	
	for(int i = 0; i < (1 << N); i++){
		int hoge = i;
		vector<int> v;
		v.push_back(0);
		for(int j = 0; j < N; j++){
			if(hoge % 2 == 0){
				v.push_back(P[j]);
			}else{
				v.push_back(24 - P[j]);
			}
			hoge /= 2;
		}
		v.push_back(24);
		sort(v.begin(), v.end());
		int ret = 24;
		for(int j = 0; j < N + 1; j++){
			ret = min(ret, v[j + 1] - v[j]);
		}
		ans = max(ans, ret);
	}
	
	cout << ans << endl;
	
	return 0;
}

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


using namespace std;

int main() {
	int n;
	cin >> n;
	
	vector<int> p(n,0);
	int flag = 0;
	
	for (int i = 0; i < n; i++) {
		cin >> p.at(i);
		if (p.at(i) != i+1) flag++;
	}
	
	if (flag <= 2) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  ll cnt = 0;
  while(1) {
    ll su = 0;
    for(int i=0;i<n;++i) {
      su += a[i]/n;
    }
    vector<ll> div(n);
    for(int i=0;i<n;++i) {
      div[i] = a[i]/n;
    }
    for(int i=0;i<n;++i) {
      cnt += div[i];
      a[i] -= div[i]*n;
      a[i] += su - div[i];
    }
    bool ok = true;
    for(int i=0;i<n;++i) {
      if(a[i] > n-1) {
        ok = false;
        break;
      }
    }
    if(ok) break;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python

import math

if __name__ == '__main__':
    a, b, C = map(float, raw_input().split())
    S = a * b * math.sin(C*math.pi/180) / 2
    L = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C*math.pi/180))
    h = b * math.sin(C*math.pi/180)

    print '{}\n{}\n{}'.format(S, L, h)



Measured memory_bytes: 4792
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long a,b;
    cin>>a>>b;
    if(a>=0 && b>=0){
        if(a<b)cout<<b-a<<endl;
        else cout<<a-b+1+(b!=0)<<endl;
    }
    else if(a<=0 && b<=0){
        if(a<b)cout<<b-a<<endl;
        else cout<<a-b+1+(a!=0)<<endl;
    }
    else if(a>0 && b<0){
        if(abs(a)>abs(b))cout<<a+b+1<<endl;
        else cout<<1-a-b<<endl;
    }
    else {
        if(abs(a)>abs(b))cout<<1-b-a<<endl;
        else cout<<1+a+b<<endl;
    }
}


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

int main(){
  int s,a,i,o;
  i=1;
  cin>>s>>a;
  o=a;
  if(s==1){
    cout<<a<<endl;
  }
  else {
    while (i<s){
      a=a*(o-1);
	i=i+1;
    }
    cout<<a<<endl;
  }
 
  return 0;
}


Measured memory_bytes: 256
S = input()
if int(S[2:]) >= 1 and int(S[2:]) <= 12:
    if int(S[:2]) <= 12 and int(S[:2]) >= 1:
        print('AMBIGUOUS')
    else:
        print('YYMM')
elif int(S[2:]) >= 13:
    if int(S[:2]) >= 1 and int(S[:2]) <= 12:
        print('MMYY')
    else:
        print('NA')
else:
    if int(S[2:]) == 0:
        if int(S[:2]) >= 1 and int(S[:2]) <= 12:
            print('MMYY')
        else:
            print('NA')
    else:
        print('NA')



Measured memory_bytes: 3064
import Control.Monad
import Control.Applicative
import Data.List


  
main :: IO ()
main = do
  jnput <- getLine
  input <- getLine
  let lenm = map read (words input ) :: [Int] 
  let len = sort lenm
  putStrLn (show(solve len))


solve :: [Int] -> Int
solve len 
  | ((length len) == 0) = 0
  | otherwise = (solvei  (tail len) (head len))+(solve (tail len) )

solvei :: [Int] -> Int -> Int
solvei len x 
  | ((length len) == 0) = 0
  | otherwise = (solveij  (tail len) x (head len))+(solvei (tail len) x )

solveij :: [Int] -> Int -> Int -> Int
solveij len x y 
  | ((length len) == 0) = 0
  | otherwise = (solveijk  x y (head len))+(solveij (tail len) x y)

solveijk ::  Int -> Int -> Int -> Int
solveijk x y z 
  | x==y =0
  | y==z =0
  | (x+y)<=z =0
  | otherwise = 1



Measured memory_bytes: 4688
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

char S[10];
string s;

int main() {
    scanf("%s", S);
    s = S;
    
    if ( stoi(s.substr(5, 2)) <= 4 ) {
        printf("Heisei\n");
    } else {
        printf("TBD\n");
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "No" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S; cin>>S;
    ll N=S.size();
    ll ans=0;
    ll tt=0;
    rep(i,N){
        if(S[i]=='T') ++tt;
        else --tt;
        maxi(ans,tt);
    }
    cout<< ans*2 <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 720
// I look at my watch
// it say nine twenty-five
// And I think oh God
// I'm still alive
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(int i = int(a); i < int(b); ++i)
#define roF(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
typedef long double ld;

const int N=2e3+10;
int mn[N];


int main(){	
	int n,x,y;cin>>n>>x>>y;
	For(i,1,n+1){
		For(j,i+1,n+1){
			int d1=j-i;
			int d2=abs(x-i)+1+abs(y-j);
			mn[min(d1,d2)]++;
		}
	}
	For(i,1,n)cout<<mn[i]<<endl;
	
	return 0;
}


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

int main()
{
  string s;
  cin >> s;
  
  if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    char clase[20];
    int am,pm;
    while(scanf("%s%d%d",clase,&am,&pm)!=EOF)cout<<clase<<" "<<am+pm<<" "<<am*200+pm*300<<endl;
    return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;


int main() {
	int N;
	scanf("%d", &N);
	int*A = new int[N];
	for (int i = 0; i < N; i++)scanf("%d", A + i);
	int c[3] = {};
	long long ans = 1;
	for (int i = 0; i < N; i++) {
		int cnt = 0;
		for (int j = 0; j < 3; j++) {
			if (A[i] == c[j]) {
				if (cnt == 0)c[j]++;
				cnt++;
			}
		}
		ans *= cnt;
		ans %= mod;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long int LL;
const LL mod = 1000000000+7;
LL mul(LL a, LL b){ return ((a%mod)*(b%mod))%mod;   }
LL add(LL a, LL b){ return ((a%mod)+(b%mod))%mod;   }

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

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

	solve();

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

	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int main()
{
    string s;
    
    cin >> s;
    int n = s.size();
  for(int i=0;i<n;i++){
    s.pop_back();

    if (s.size() %2 !=0)continue;

    string s2,s3;
    s2 = s.substr(0  ,  (s.size() /2)  );
    s3 = s.substr(( s.size() /2) , (s.size() -1)  );

    // cout << s2 <<" : " <<s3 <<endl;

    if (s2==s3)break;
  }

    cout << s.size() <<endl;
  

    return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second 
#define pii pair<int,int>
#define afor(i,a,b) for(int i=a;i<b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define print(A,j,k) for(int ii=j;ii<k;ii++)cout<<A[ii]<<" ";cout<<"\n"
#define all(v) v.begin(),v.end()
#define ps cout<<"YES\n";
#define CASES int t;cin>>t;while(t--)
//ans = a ? b : c; // to simplify: if (a) ans = b; else ans = c;
using namespace std;
int main()
{
    fast
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d);
    return 0;
}


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
bool comp(pair<ll, ll> a, pair<ll , ll> b) {
    // 基本はfirstで比較
    if(a.first != b.first){
         return a.first < b.first; // 昇順
        //return a.first > b.first; // 降順
    }

    // それ以外はsecondで比較
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        // どちらも同じ
        return true;
    }
}


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

    ll a,b,c,d,n,maxi=0,f=0,mini=INF,sum=0;
    ll h,w;
    ll m;
    cin>>n>>m;
    vector<pair<ll, ll>> p(n);
    rep(i,n) {
        cin>>a>>b;
        p[i]=make_pair(a,b);
    }
    priority_queue<ll> q;
    sort(all(p),comp);
    ll last=0;
    REP(i,1,m+1){
        while(p[last].first==i){
            q.push(p[last].second);
            last++;
        }
        if(!q.empty()){
            sum+=q.top();
            q.pop();
        }

    }

    cout<<sum<<endl;
}


Measured memory_bytes: 5856
import java.util.Scanner;

public class Main {

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

        for (int i = 1; i <= b; i++) {
            if ((i * a) % b == c) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }

}


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

int main(){
    string s;
    cin >> s;
    size_t n = s.length();

    int count1010 = 0;
    for (int i = 0; i < n; ++i){
        if (i%2==0){
            if(s[i]!='1') ++count1010;
        }else{
            if(s[i]!='0') ++count1010;
        }
    }

    int count0101 = 0;
    for (int i = 0; i < n; ++i){
        if (i%2==0){
            if(s[i]!='0') ++count0101;
        }else{
            if(s[i]!='1') ++count0101;
        }
    }

    if (count1010>count0101){
        cout << count0101 << endl;
    }else{
        cout << count1010 << endl;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int n,ans=0,sum=0,cnt=0;
	cin>>n;
	cin>>s; 
	for(int i=0;i<n;i++){
		if(s[i]=='R')ans++;
	}
	for(int i=0;i<ans;i++){
		if(s[i]=='R')sum++;
	}
	for(int i=0;i<n;i++){ 
		if(s[i]=='W')cnt++;
	}
	cout<<min(ans-sum,min(ans,cnt));
	return 0; 
}


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

int main()
{
	string s; cin>>s;
	int cnt[3]={0};
	for(char x:s) cnt[x-'a']++;

	sort(cnt,cnt+3);
	cnt[2] -= cnt[0];
	cnt[1] -= cnt[0];

	if(cnt[1] <= 1 and cnt[2] <= 1) cout<<"YES"; else cout<<"NO";
}

// abcab

Measured memory_bytes: 512
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    for (Array(n, r) <- in if n > 0 && r > 0) {
        val m = in.take(r).toSeq.reverse.foldLeft(0)((i, r) =>
            if (i >= r(0) - 1 + r(1)) i
            else if (i >= r(1)) i - r(1)
            else i + r(0) - 1 
        )
        println(n - m)
    }
}

Measured memory_bytes: 51620