akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  cout<<(n-2)*180<<endl;
  return 0;
}


Measured memory_bytes: 256
SA=input()
SB=input()
SC=input()
lenSA=len(SA)
lenSB=len(SB)
lenSC=len(SC)
lenS=lenSA+lenSB+lenSC
"""
tmpA=0
tmpB=0
tmpC=0
Stmp=SA
"""
lS=[SA,SB,SC]
ltmp=[0,-1,-1]#どこまで消したか
tmpabc=0
#lenS=len(lS)
lans=["A","B","C"]
for i in range(lenS):
    nxt=lS[tmpabc][ltmp[tmpabc]]
    #print(nxt)
    #if lS[tmpabc][ltmp[tmpabc]]=="a":
    if nxt=="a":
        #ltmp[tmpabc]+=1
        ltmp[0]+=1
        tmpabc=0
    #elif lS[tmpabc][ltmp[tmpabc]]=="b":
    elif nxt=="b":
        #ltmp[tmpabc]+=1
        ltmp[1]+=1
        tmpabc=1
    else:
        #ltmp[tmpabc]+=1
        ltmp[2]+=1
        tmpabc=2
    """
    if ltmp[tmpabc]==len(lS[tmpabc])-1:
        print(lans[tmpabc])
        break
    """
    for j in range(3):
        #if ltmp[i]==len(lS[i])-1:
        if ltmp[j]==len(lS[j]):
            print(lans[j])
            break
    else:
        continue
    break


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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;

int main(){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == t[i]) ans++;
    }

    cout << ans;

    return 0;
}


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

#define MAX_N 2999

int n;
double p[MAX_N];

double dp[MAX_N][MAX_N + 1];

int main() {
  std::cin >> n;
  for(int i = 0; i < n; ++i) {
    std::cin >> p[i];
  }

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

  double ans = 0.0;
  for(int j = n / 2 + 1; j <= n; ++j) {
    ans += dp[n - 1][j];
  }

  std::cout << std::setprecision(10) << ans << std::endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const ll INF = 2e9;

int N;
vi S;

bool solve() {
    sort(rALL(S));
    multiset<ll> T;
    T.insert(S[0]);
    S[0] = INF;
    REP (n, N) {
        multiset<ll> U;
        int j = 0;
        for (auto it = T.rbegin(); it != T.rend(); it++) {
            bool check = false;
            while (j < (1<<N)) {
                check = (S[j] < *it);
                if (check) {
                    U.insert(S[j]);
                    S[j] = INF;
                    break;
                } else {
                    j++;
                }
            }
            if (!check) return false;
        }
        for (auto it = U.begin(); it != U.end(); it++) T.insert(*it);
    }
    return true;
}

int main() {
    cin >> N;
    S = vi(1<<N);
    REP (i, 1<<N) cin >> S[i];
    cout << ((solve()) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 20736
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <math.h>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b>=c) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=5e5+10;
int n,x[maxn];
int l,q,a,b;
int nex[maxn][20];
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i];
    }
    cin>>l>>q;
    for(int i=1;i<=n;i++) nex[i][0]=upper_bound(x+i,x+n+1,x[i]+l)-x-1;
    for(int i=0;i<19;i++){
        for(int j=1;j<=n;j++){
            nex[j][i+1]=nex[nex[j][i]][i];
        }
    }
    while(q--){
        cin>>a>>b;
        int ans=0;
        if(a>b) swap(a,b);
        for(int i=19;i>=0;i--){
            if(nex[a][i]<b){
                a=nex[a][i];
                ans+=(1<<i);
            }
        }
        cout<<ans+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

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

int main(){
    int n,x;
    int l[105]={};
    scanf("%d%d",&n,&x);
    REP(i,n)scanf("%d",&l[i]);
    long long int bound=0;
    int num=1;
    REP(i,n){
        bound+=l[i];
        if(bound<=x)num++;
    }
    printf("%d\n",num);
    return 0;
}

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

int main()
{
    int m, n, o, p, i, j;
    string x, y;
    cin >> m;
    cin >> x;
    cin >> n;
    o = (int)x[n-1];
    for (i=0;i<m;i++){
        p = (int)x[i];
        if (p == o){
            cout << char(o);
        }
        else {
            cout << "*";
        }
    }
    return 0;

}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int x = scan.nextInt();
	    int a[]=new int[n];
	    int sum=0;
	    for(int i=0;i<n;i++) {
	    	a[i]=scan.nextInt();
	    	sum+=a[i];
	    }
	    scan.close();

	    Arrays.sort(a);

	    System.out.println(n+(x-sum)/a[0]);
	}

}


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

int main(){
  int n,m,cnt=1;cin>>n>>m;
  for(int i=m;i>=1;i-=2,cnt++)cout<<cnt<<" "<<cnt+i<<endl;
  cnt=m+2;
  for(int i=m-1;i>=1;i-=2,cnt++)cout<<cnt<<" "<<cnt+i<<endl;
}


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


constexpr int n = 26;
long long d;
std::vector<long long> c;
std::vector<std::vector<long long>> s;

int calc(vector<int> v){
    int ans = 0;
    vector<int> last(n, 0);
    for(int i = 1; i <= d; ++i){
        ans += s[i - 1][v[i - 1]];
        last[v[i - 1]] = i;
        for(int j = 0; j < n; ++j)
            ans -= c[j] * (i - last[j]);
    }
    return ans;
}

vector<set<int>> day;

void solve(){
    day.resize(n);
    vector<int> ret(d, 0);
    for(int i = 0; i < n; ++i){
        day[i].emplace(-1);
        day[i].emplace(d);
    }
    for(int i = 0; i < d; ++i){
        cin >> ret[i];
        --ret[i];
        day[ret[i]].emplace(i);
    }
    int score = calc(ret);
    int m;
    cin >> m;
    for(int i = 0; i < m; ++i){
        int k, q;
        cin >> k >> q;
        --k, --q;

        auto aft = day[ret[k]].upper_bound(k);
        auto bef = prev(day[ret[k]].lower_bound(k));
        auto aft2 = day[q].upper_bound(k);
        auto bef2 = prev(day[q].lower_bound(k));
        int lb = k - *bef;
        int rb = *aft - k;
        int mb = lb + rb;
        int lb2 = k - *bef2;
        int rb2 = *aft2 - k;
        int mb2 = lb2 + rb2;

        score -= c[ret[k]] * mb * (mb - 1) / 2;
        score += c[ret[k]] * lb * (lb - 1) / 2;
        score += c[ret[k]] * rb * (rb - 1) / 2;

        score += c[q] * mb2 * (mb2 - 1) / 2;
        score -= c[q] * lb2 * (lb2 - 1) / 2;
        score -= c[q] * rb2 * (rb2 - 1) / 2;

        score -= s[k][ret[k]];
        score += s[k][q];

        day[ret[k]].erase(k);
        day[q].emplace(k);
        ret[k] = q;

        cout << score << endl;
    }
}


signed main(){
    long long D;
    scanf("%lld",&D);
    c.resize(26);
    for(int i = 0 ; i < 26 ; i++){
        scanf("%lld",&c[i]);
    }
    s.assign(D, std::vector<long long>(26));
    for(int i = 0 ; i < D ; i++){
        for(int j = 0 ; j < 26 ; j++){
            scanf("%lld",&s[i][j]);
        }
    }
    d = D;
    solve();
    return 0;
}



Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

struct unionfind {
    vector<int> d;
    unionfind(int n=0) : d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

struct edge{ int u, v; long long weight;};
bool comp(const edge &e1, const edge &e2) { return e1.weight < e2.weight;}
vector<edge> es;

long long kruskal(int n) {
    sort(es.begin(), es.end(), comp);
    unionfind uf(n);
    long long res = 0;
    for (size_t i = 0; i < es.size(); ++i) {
        edge e = es[i];
        if (!uf.same(e.u, e.v)) {
            uf.unite(e.u, e.v);
            res += e.weight;
        }
    }
    return res;
}

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

    int n;
    cin >> n;
    rep(i, n) rep(j, n) {
        int w;
        cin >> w;
        if (w >= 0) es.push_back({i, j, w});
    }
    cout << kruskal(n) << endl;
}



Measured memory_bytes: 3260
from collections import deque

def bfs(graph, start):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return visited

n, m = map(int, input().split())
g = [set() for i in range(n)]
group = []

for i in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    for j in range(len(group)):
        if s in group[j] and t in group[j]:
            print("yes")
            break
        elif s in group[j]:
            print("no")
            break
    else:
        group_tmp = set(bfs(g, s).keys())
        if t in group_tmp:
            print("yes")
        else:
            print("no")
        group.append(group_tmp)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i = 0;;++i) {
        if (i % 2 == 0) c -= b;
        else a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    return 0;
}



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

typedef long long ll;

int main() {
    int N, K, A;
    cin >> N >> K;
    rep(i, N) cin >> A;
    cout << (N + K - 3) / (K - 1) << endl;
}

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

using namespace std;

int c = 0;
void selection(int a[], int n)
{
   for(int i = 0;i<n;i++){
       int min = i;
       for(int j = i+1;j<n;j++){
           if(a[j] <a[min]) min = j;
       }
       swap(a[min],a[i]);
       if(min!=i) c++;
   }
}

int a[110];
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    selection(a, n);
    for (int i = 0; i < n-1; i++)
    {
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3144
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int x, y, z;
  cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << ' ' << y << ' ' << z << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

int INF = 10e8;
int n, m, r;
int rlist[8];
int d[200][200];
int w[8][8];

struct edge{
    int u, v, cost;
};

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
          src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int pr[1<<9][8];
Weight best[1<<9][8];

void buildPath(int S, int i, vector<int> &path) {
  if (!S) return;
  buildPath(S^(1<<i), pr[S][i], path);
  path.push_back(i);
}



int main(){
    cin >> n >> m >> r;
    
    REP(i, r) cin >> rlist[i];
    REP(i, r) rlist[i] -= 1;
    
    REP(i, n) REP(j, n) d[i][j] = INF;
    REP(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        a = a-1; b = b-1;
        d[a][b] = c;
        d[b][a] = c;
    }

    REP(k, n){
        REP(i, n){
            REP(j, n){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    REP(i, r) REP(j, r) w[i][j] = INF;
    REP(i, r) REP(j, r){
        w[i][j] = d[rlist[i]][rlist[j]];
        w[j][i] = w[i][j];
        // cout << w[i][(i+1)%r] << " " << rlist[i] << " " << rlist[(i+1)%r] << endl;
    }
  
  int output = INF;
  REP(s, r){
      vector<int> path;
      int N = 1 << r;
      REP(S,N) REP(i, r) best[S][i] = INF;
      best[1<<s][s] = 0;
      REP(S,N) REP(i,r) if (S&(1<<i)) REP(j,r)
        if (best[S|(1<<j)][j] > best[S][i] + w[i][j])
          best[S|(1<<j)][j] = best[S][i] + w[i][j],
          pr[S|(1<<j)][j] = i;
      int t = min_element(best[N-1], best[N-1]+r) - best[N-1];
      path.clear(); buildPath(N-1, t, path);
      output = min(output, best[N-1][t]);
  }
  cout << output << endl;
}


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

#define ll long long 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

ll gcd(ll a, ll b){ 
	while(a % b) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return b;
}

int main(){

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
		
	ios::sync_with_stdio(0); cin.tie(0);
	int k; cin >> k;
	ll ans = 0;
	for(int i = 1; i <= k; i++) {
		for(int j = 1; j <= k; j++) {
			for(int l = 1; l <= k; l++) {
				ans += (gcd(i, gcd(j, l)));
			}	
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3668
n = int(input())
s = input()
n_s = ""
for i in range(len(s)):
    if ord(s[i])+n > 90:
        n_s+=chr(ord(s[i])+n-26)
    else:
        n_s+=chr(ord(s[i])+n)
    
print(n_s)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int ans = 1; 
        int tmp = 0;
                
        while((tmp + 1) * (tmp + 1) <= N){
            ans =  (tmp + 1) * (tmp + 1);
            tmp++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
import sys


def main():
    h = int(input())
    w = int(input())
    n = int(input())
    if h < w:
        res = n // w
        if n % w > 0:
            res += 1
    else:
        res = n // h
        if n % h > 0:
            res += 1
    print(res)


if __name__ == '__main__':
    input = sys.stdin.readline
    main()


Measured memory_bytes: 2940
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int N;
    int result = 0;
    int count = 0;
	scanf("%d", &N);
    for (int i=1; i <= N; i=i+2) {
        for (int j=1; j <= i; j++) {
            if (i%j == 0) {
                count++;
            }
        }
        if (count == 8) {
            result++;
        }
        count = 0;
    }
    printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 128
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

quickSortVec l u arr
  | l >= u    = return ()
  | otherwise = do
      VM.unsafeSwap arr l ((u+l)`div`2)
      t <- VM.unsafeRead arr l
      let i = l
          j = u + 1
      nj <- loopVec t u i j arr
      VM.unsafeSwap arr l nj
      quickSortVec l (nj-1) arr
      quickSortVec (nj+1) u arr

loopVec !t !u !i !j arr = do
  ni <- doWhile i (+1)         (< t)
  nj <- doWhile j (subtract 1) (> t)
  if ni > nj
    then return nj
    else do VM.unsafeSwap arr ni nj
            loopVec t u ni nj arr
              where
                {-# INLINE doWhile #-}
                doWhile k op p
                  | nk > u    = return nk
                  | otherwise = do
                      x <- VM.unsafeRead arr nk
                      if p x then
                        doWhile nk op p
                        else
                        return nk
                        where
                          nk = op k

main = do
  n <- getInt
  xs <- getIntVec n

  xs' <- V.thaw xs
  quickSortVec 0 (n-1) xs'

  a <- VM.read xs' (n `div` 2 - 1)
  b <- VM.read xs' (n `div` 2)

  V.forM_ xs $ \x -> do
    if x <= a
      then print b
      else print a

Measured memory_bytes: 11004
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l = 0, r = 0;
    int ans = INF;
    for (int i = 0; i < n;i++){
        if(s[i]=='E'){
            r++;
        }
    }
    for (int i = 0; i < n;i++){
        if(s[i]=='E')
            r--;
        if(i!=0 && s[i-1] == 'W'){
            l++;
        }
        ans = min(r + l, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
    
#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
//#define int long long int
    
using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_mset = tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
    
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
//const ll INFLL = (ll)1e17;
const int MAXN = 112345;
const double pi = 3.14159265359;
const double eps = 0.00000001;

int a[MAXN];
int dp[MAXN];

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    dp[0] = 0;
    for (int i = 1; i <= k; ++i) {
        bitset<300> mex;
        for (int j = 0; j < n; ++j) {
            if (i - a[j] < 0) {
                break;
            }
            mex[dp[i - a[j]]] = 1;
        }
        for (int j = 0; j < 300; ++j) {
            if (!mex[j]) {
                dp[i] = j;
                break;
            }
        }
    }
    if (dp[k]) {
        puts("First");
    } else {
        puts("Second");
    }
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,a[100100],q[100100],d,p1,sum;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>q[i];
		a[i]=q[i];
	}
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		sum=0;
		cin>>p1>>d;
		a[p1]=d;
		for(int j=1;j<=n;j++)
		  sum+=a[j];
		cout<<sum<<endl;
		for(int j=1;j<=n;j++)
		{
			a[j]=q[j];
		}
	}
	return 0;
}

Measured memory_bytes: 256
(defn input []
  (list
    (loop [n (Integer/parseInt (read-line)) Ss '()]
      (if (zero? n)
        Ss
        (recur (dec n) (cons (read-line) Ss))))
    (loop [m (Integer/parseInt (read-line)) Ts '()]
      (if (zero? m)
        Ts
        (recur (dec m) (cons (read-line) Ts))))))

(defn TwoColorsCardGame [[Ss Ts]]
  (apply max
    (cons 0
      (map -
        (map #(->> Ss (filter (partial = %)) count) (distinct Ss))
        (map #(->> Ts (filter (partial = %)) count) (distinct Ss))))))


(-> (input)
  TwoColorsCardGame
  println)

Measured memory_bytes: 66240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
 int ans = 0;
  if(n % 2){ans = (n / 2) + 1;}
  else{ans = n / 2;}
  cout << fixed;
  cout << setprecision(8) << (double)ans / n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  ll N,M;
  cin >> N >> M;
  priority_queue<ll> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push(a);
  }
  
  for (int i = 0; i < M; i++) {
    ll m = A.top();
    m /= 2;
    A.pop();
    A.push(m);
  }
  
  ll ans = 0;
  while (!A.empty()) {
    ans += A.top();
    A.pop();
  }
  
  cout << ans << endl;
}

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

int main() {
  vector<vector<int>> c(3,vector<int>(3));//多次元配列の確認
  string answer = "Yes";
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);//添え字のずれに注意
    }
  }
  vector<int> a(3);
  vector<int> b(3);
  for (int i = 0; i <= c[0][0]; i++) {
    a[0] = i;
    b[0] = c[0][0] - a[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];
    if (c[1][1] != a[1] + b[1] || c[1][2] != a[1] + b[2] || c[2][1] != a[2] + b[1] || c[2][2] != a[2] + b[2]) {
      answer = "No";
      break;
    }
  }
  cout << answer;
}

Measured memory_bytes: 3616
# 後ろから順に考える
# 最後のA_Kは必ず2である必要がある
# A_Kの前には2~3人である必要がある
# ...

K = int(input())
As = list(map(int, input().split()))
As.reverse()

fail = False
if As[0] != 2:
    fail = True
else:
    mn = 2
    mx = 3
    for a in As[1:]:
        # 今 [mn, mx] = [4, 13], a = 3だとする
        # a人組をつくったあとにありうる数は3の倍数なので、ここでは6, 9, 12のみありうる
        if mn % a != 0:
            mn = (mn // a) * a + a
        if mx % a != 0:
            mx = (mx // a) * a
        if mn > mx:
            fail = True
            break

        # mxを修正
        mx = mx + (a - 1)
if fail:
    print(-1)
else:
    print(mn, mx)


Measured memory_bytes: 14252
#include <iostream>

using namespace std;

int main()
{

   int a[5];
   for(int i=0;i<5;i++)
   {
       cin>>a[i];
   }
   for(int i=0;i<5;i++)
   {
       if(a[i]==0)
       {
           cout<<i+1;
           break;
       }
   }

    return 0;
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	
	int ans,round=0;
	for(int i=100;i>=1;i--)
	{
		if(a%i==0 && b%i==0)
		{
			round++;
		}
		if(round==c)
		{
			ans=i;
			break;
		}
	}
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num;
		while ((num = in.nextInt()) != 0) {
			long ans = 0;
			for (int i = 0; i < 10; i++) {
				int v = (num & (7 << (i * 3))) >> (i * 3);
				if (v >= 4) {
					v++;
				}
				if (v >= 6) {
					v++;
				}
				ans += (v * Math.pow(10, i));
			}
			System.out.println(ans);
		}
	}
}

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

int n, m;
vector <pair <int, int> > bomb;
vector <vector <pair <int, int> > > g;
vector <int> vis, ans;

int dfs(int u) {
	vis[u] = 1;
	int nw = 0;
	for (int i = 0; i < g[u].size(); ++ i) {
		int v = g[u][i].first;
		if (!vis[v]) {
			int lst = dfs(v);
			if (lst ^ bomb[v].second) {
				nw ^= 1;
				ans.push_back(g[u][i].second);
			}
		}
	}
	return nw;
}

int main() {
	ios :: sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 0; i < n; ++ i) {
		int a, b; cin >> a >> b;
		bomb.push_back(make_pair(a, b));
	}
	bomb.push_back(make_pair(1e9 + 7, 0));
	sort(bomb.begin(), bomb.end());
	for (int i = n; i; -- i)
		bomb[i].second ^= bomb[i - 1].second;
	g.resize(n + 1);
	for (int i = 0; i < m; ++ i) {
		int l, r; cin >> l >> r;
		l = lower_bound(bomb.begin(), bomb.end(), make_pair(l, -10)) - bomb.begin();
		r = lower_bound(bomb.begin(), bomb.end(), make_pair(r,  10)) - bomb.begin();
		g[l].push_back(make_pair(r, i)); g[r].push_back(make_pair(l, i));
	}
	vis.resize(n + 1);
	for (int i = 0; i <= n; ++ i) if (!vis[i]) {
		int nw = dfs(i);
		if (nw ^ bomb[i].second) {
			cout << -1 << endl;
			return 0;
		}
	}
	sort(ans.begin(), ans.end());
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); ++ i) cout << ans[i] + 1 << " "; cout << endl;
	return 0;
}

Measured memory_bytes: 14196
"""
他の隣接する最大値よりも、i番目の塔の方が高かったら良い展望台として認められる。
"""

n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [0] * n #隣接する塔の最大値を格納

for i in range(m):
    a, b = map(int, input().split())
    
    l[a-1] = max(l[a-1], h[b-1])
    l[b-1] = max(l[b-1], h[a-1])

#ここで比較する
result = 0
for j in range(n):
    if h[j] > l[j]:
        result += 1
print(result)


Measured memory_bytes: 20020
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 
 
int main() {
    int n,m; 
    cin >> n >> m;
    vector<bool> accs(n+1, false);
    vector<int> wa_counts(n+1, 0);
    int acc_count = 0, wa_count = 0;
    rep(i, m) {
        string s;
        int p;
        cin >> p >> s;
        if (s == "AC") {
            if (!accs[p]) {
                accs[p] = true;
                acc_count += 1;
                wa_count += wa_counts[p];
            }
        } else {
            if (!accs[p]) {
                wa_counts[p] += 1;
            }
        }
    }
    cout << acc_count << " " << wa_count << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main (){
int a,b,x,y;
  scanf ("%d%d%d%d",&a,&b,&x,&y);
  if (a>b){
  printf("%d",b*x+((a-b)*y));
  }
  else {
  printf("%d",a*x);
  }
return 0;
}


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

int main(void){
    int n;
    int a[300][300];
    bool del[300][300]={};
    cin>>n;
    rep(i,n)rep(j,n) cin>>a[i][j];
    long long sum = 0;
    rep(k,n)rep(i,n)rep(j,n)if(i!=j && i!=k && j!=k){
        if(a[i][j] > a[i][k] + a[k][j]){
            cout<<-1<<endl;
            return 0;
        }
        if(a[i][j] == a[i][k] + a[k][j]){
            del[i][j] = true;
        }
    }
    rep(i,n)rep(j,i)if(!del[i][j])sum += a[i][j];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


ll sum[200010];

int main(void){
    ll n;
    ll ans=(ll)INF;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    sum[0]=0;
    for(ll i=0;i<n;i++)sum[i+1]=sum[i]+a[i];
    for(ll i=1;i<n;i++){
        ll sum1=sum[i];
        ll sum2=sum[n]-sum1;
        ans=min(ans,max(sum1-sum2,sum2-sum1));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
def main
  n, m, d = ARGF.gets.split.map(&:to_i)
  # puts "#{n}, #{m}, #{d}"

  # お隣の組み合わせ（順列）
  p = n * n

  # お隣組のうち美しいのは
  b_num = if d == 0
            n
          else
            (n - d) * 2
          end

  # 確率（期待値）
  b_exp = b_num.to_f / p

  # 数字の「間」が m-1 こあるので平均美しさは
  puts b_exp * (m - 1)

end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

ll POWER[6] = {1, 10, 9, 12, 3, 4};

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

    string s; cin >> s;
    int n = s.size();
    const ll MD = 1e9 + 7;
    ll dp[n + 1][13];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j < 13; j++)
            dp[i][j] = 0;
    reverse(s.begin(), s.end());

    if (s[0] == '?') {
        for (int j = 0; j < 10; j++) dp[0][j] = 1;
    } else {
        ll d = s[0] - '0';
        dp[0][d] = 1;
    }

    for (int i = 1; i < n; i++) {
        if (s[i] == '?') {
            for (int d = 0; d < 10; d++) {
                ll m = (POWER[i % 6] * d) % 13;
                for (int j = 0; j < 13; j++) 
                    dp[i][j] = (dp[i][j] + dp[i - 1][(j - m + 13) % 13]) % MD;
            }

        } else {
            ll d = s[i] - '0';
            ll m = (POWER[i % 6] * d) % 13;
            for (int j = 0; j < 13; j++) 
                dp[i][j] = (dp[i][j] + dp[i - 1][(j - m + 13) % 13]) % MD;
        }
    }
    cout << dp[n - 1][5] << endl;
    return 0;
}


Measured memory_bytes: 10704
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  ll n;
  cin >> n;
  vector<ll> a(5);
  for(ll i=0;i<n;i++){
    string s;
    cin >> s;
    if(s.at(0)=='M')
    a[0]++;
    if(s.at(0)=='A')
    a[1]++;
    if(s.at(0)=='R')
    a[2]++;
    if(s.at(0)=='C')
    a[3]++;
    if(s.at(0)=='H')
    a[4]++;
  }
  ll ans=0;
  for(int i=0;i<3;i++){
    for(int j=i+1;j<4;j++){
      for(int k=j+1;k<5;k++){
        ans=ans+a[i]*a[j]*a[k];
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        string S = cin.next();
        string ans="WA";
        int Ccount=0;
        for(int i=2;i<S.Length-1;i++)
        {
          if(S[i]-'C'==0)Ccount++;
        }
        for(int i=0;i<S.Length;i++)
        {
          if(S[i]-'A'!=0&&S[i]-'C'!=0&&char.IsUpper(S[i]))Ccount+=2;
        }
        if(S[0]-'C'==0||S[1]-'C'==0||S[S.Length-1]-'C'==0)Ccount+=2;
        if(S[0]-'A'==0&&Ccount==1)ans="AC";   
        
        Console.WriteLine(ans);
      
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
          Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 13140
import math
a,b,c,d = map(int,input().split())
lcm = c*d//(math.gcd(c,d))
e,f,g = b//c - (a-1)//c,b//d - (a-1)//d,b//(lcm) - (a-1)//(lcm)
print(b-a+1-e-f+g)

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

int main()
{
  int a,b;
  string str;
      
  for(int i=0; ;i++){

    cin >> a >> str >> b;

    if(str=="?") break;
    if(str=="+"){
      cout << a + b << endl;
    } else if(str=="-"){
      cout << a - b << endl;
    } else if(str=="*"){
      cout << a * b << endl;
    } else if(str=="/"){
      if(b==0) break;
      cout << a / b << endl;
    }
  } 

  return 0;
}

Measured memory_bytes: 1204
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($cond:expr, $a:expr, $b:expr) => {
        if $cond {
            $a
        } else {
            $b
        }
    }
}

fn main() {
    input! {
        n: usize, k: usize,
        a: [usize; n]
    };

    let mut state = vec![0; k+1];
    for i in 1..k+1 {
        let mut can_win = 0;
        for &ai in a.iter() {
            if i >= ai {
                can_win |= ifv!(state[i-ai] == 0, 1, 0);
            }
        }
        state[i] = can_win;
    }
    println!("{}", ifv!(state[k] == 1, "First", "Second"));
}


Measured memory_bytes: 4352
n=gets.to_i
h=gets.split.map(&:to_i)
if n==1 
  puts "Yes"
  exit
end
(h.size-1).downto(1) do |i|
  if h[i]-h[i-1] < -1
    puts "No"
    exit
  elsif h[i]==h[i-1]-1
    h[i-1]-=1
  end
end
puts "Yes"


Measured memory_bytes: 8580
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum = 0;
		int anss = 0;
		int j=1;
		int N = sc.nextInt();
		int X = sc.nextInt();
		//整数型配列の宣言と初期化
		int [] arys;
		arys = new int [N+1];
		
		for(int i=1; i<=N;i++)
		{		
		arys[i-1]=sc.nextInt();
		}
		for(j=1;sum<X&&j<=N;j++){
			sum=sum+arys[j-1];
		}
		
		if(j>N)
		{anss=N+1;
		}
		if(sum>X)
		{anss=j-1;
		}
		if(sum==X)
		{anss=j;
		}
		System.out.println(anss);
		}
}


Measured memory_bytes: 25172
//Written by Rhitwik Saha//
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vb          vector<bool>
#define vc          vector<char>
#define vii         vector<pii>
//#define mi          map<int,int>
//#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define ub(x)       upper_bound(x)
#define lb(x)       lower_bound(x)
#define endl        '\n'
#define file        freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define fastio      ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// #define N 			1e5+5
#define M           1000000007
#define MAX         100005
#define mem0(a)     memset(a,0,sizeof(a))
#define prec        cout<<std::setprecision(9)<<std::fixed
#define forn(i,a,b)  for(int i=a;i<b;i++)
// const double long rf=14;
int i,j,k;
vi a;

void Anon_mouS(){
	int n,m;
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2;
}

int32_t main(){
	// func();
    fastio;
    // file;
    // sieve();
    int q=1;
    while(q--)Anon_mouS();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN; 
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;

}

int min(int a, int b){return a < b ? a : b; }

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }

  head = 0; tail = n;

  while (head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t-=c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  
return 0;
}

Measured memory_bytes: 10756
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	string s;
	cin >> s;
	int n = s.size() +1;
	int rtl[n] = {}, ltr[n] = {};
	REP(i, n-1) if(s[i] == '<') ltr[i+1] = ltr[i] + 1; else ltr[i+1] = 0;
	REP(i, n-1) if(s[n-2-i] == '>') rtl[n-2-i] = rtl[n-1-i] + 1; else rtl[n-2-i] = 0;
	ll ans = 0;
	int tmp;
	REP(i, n) ans += max(ltr[i], rtl[i]);
	cout << ans << endl;
}

Measured memory_bytes: 4740
#include <iostream>
using namespace std;
string s;
int main(){
    cin >> s;
    int ans = s.size();
    int s_num = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'S') {
                s_num++;
        }
        if (s[i] == 'T') {
            if (s_num > 0) {
                s_num--;
                ans -= 2;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

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

int main(){
	fastio;

	ll n,x; cin>>n>>x;

	cout<<3*(n-__gcd(n,x))<<ln;

	return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  bool dp[101] = {0};
  dp[0] = true;
  for (int i = 0; i < 101; i++) {
    if (i - 4 >= 0)
      dp[i] |= dp[i - 4];
    if (i - 7 >= 0)
      dp[i] |= dp[i - 7];
  }
  if (dp[n])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int main()
{
    int a,b;
    cin >> a >> b;
    int cnt = 0;
    int vartmp,tmp10000,tmp1000,tmp100,tmp10,tmp1;
    for(int i = a; i <= b; i++ )
    {
        vartmp = i;
        tmp1 = (vartmp % 10);
        vartmp = vartmp /10;
        tmp10 = (vartmp % 10);
        vartmp = vartmp /10;
        tmp100 = (vartmp % 10);
        vartmp = vartmp /10;
        tmp1000 = (vartmp % 10);
        vartmp = vartmp /10;
        tmp10000 = vartmp;
        vartmp = tmp1 * 10000 + tmp10 * 1000 + tmp100 * 100 + tmp1000 * 10 + tmp10000;
        if(vartmp == i)
        {
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

int N, M, X;

struct book {
	int price;
	vector<int> skil;
};

int main() {
	S3(N, M, X);
	vector <struct book> books(N);
	R(i, N) {
		int c = 0;
		S(c);
		vector<int> skil(M);
		R(i, M) {
			int s = 0;
			S(s);
			skil[i] = s;
		}
		books[i] = {c, skil};
	}
	int mi = 1200001;
	for (int bit = 0; bit < (1 << N); ++bit) {
		vector<bool> v(N);
		for (int i = 0; i < N; ++i) {
			if (bit & (1 << i)) {
				v[i] = true;
			}
		}
		int cost = 0;
		vector<int> s(M);
		R(i, N) {
			if (v[i]) {
				cost += books[i].price;
				R(j, books[i].skil.size()) {
					s[j] += books[i].skil[j];
				}
			}
		}
		bool flag = true;
		R(i, M) {
			if (s[i] < X) {
				flag = false;
				break;
			}
		}
		if (flag) mi = min(mi, cost);
	}
	if (mi == 1200001) P(-1);
	else P(mi);
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18;
int main(){
    ll x,y,cnt = 0;
    cin>>x>>y;
    while(ll(pow(2,cnt)*x)<=y)cnt++;
    cout<<cnt<<endl;
}



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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int C = N*A;

  if (B == C) {
    cout << C  << endl;
  }

  else if (B > C) {
    cout << C  << endl;
  }

  else if (B < C) {
    cout << B << endl;
  }

}

Measured memory_bytes: 3544