akhauriyash/Code-Regression huggingface dataset:
n = int(input())
*array, = list(map(int, input().split())) 


def bubble_sort(a):
    c = 0
    flag = 1
    i = 0
    while flag:
        flag = 0

        # range(a, b, c) jがbになったときに処理中断する
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:

                a[j], a[j-1] = a[j-1], a[j]
                c += 1
                flag = 1

        i += 1

    print(*a)
    print(c)


bubble_sort(array)







Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll dp[200005];

int main(){
  int N, D, A;
  cin >> N >> D >> A;
  vector<pair<ll,ll>> v;
  rep(i,N){
    ll x, h;
    cin >> x >> h;
    v.emplace_back(x,h);
  }

  sort(ALLOF(v));

  vector<int> range;
  int idx = 0;
  rep(i,N){
    while(idx+1 < N && v[idx+1].first <= v[i].first + 2*D) idx++;
    range.push_back(idx+1);
  }

  ll ret = 0;
  ll base = 0;
  rep(i,N){
    base += dp[i];
    ll val = v[i].second + base;
    if(val <= 0) continue;
    ll damage = (val + A - 1) / A;
    dp[range[i]] += damage * A;
    base -= damage * A;
    ret += damage;
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 7148
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

##############################
n=I() #n:頂点数　w:辺の数

d = [[float("inf")]*n for i in range(n)]
lis=[LI() for i in range(n)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(n):
    for j in range(i+1,n):
        d[i][j]=lis[i][j]
        d[j][i]=lis[i][j]
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
warshall_floyd(d)
sm=0
for i in range(n):
    sm+=sum(lis[i])
#インデックスで与えられていることに注意
#ソース　https://juppy.hatenablog.com/entry/2018/11/01/蟻本_python_全点対最短経路法（ワーシャルフロイド法
count=0
for i in range(n-1):
    for j in range(i+1,n):
        if d[i][j]!=lis[i][j]:
            print(-1)
            sys.exit()
        if d[i][j]==lis[i][j]:
            for k in range(n):
                if i!=k!=j and d[i][k]+d[k][j]==d[i][j]:
                    count+=lis[i][j]
                    #print(i,j,k)
                    break
print(sm//2-count)


                

        

    
            
        
        
    

    
        
    
    
    

Measured memory_bytes: 77148
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

const int MOD = 1e9 + 7;
double EPS = 1e-10;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

bool kr_cmp(const edge& l, const edge& r) { return l.w < r.w; }

ll kruskal(int N, vector<edge> E) {
	sort(E.begin(), E.end(), kr_cmp);
	union_find uf(N);
	ll sum = 0;
	for (edge e: E)
		if (!uf.same(e.u, e.v)) {
			uf.unite(e.u, e.v);
			sum += e.w;
		}
	return sum;
}

int main() {
	int N; cin >> N;
	vector<int> x(N), y(N);
	rep(u, N) scanf("%d%d", &x[u], &y[u]);
	vector<i_i> xu(N), yu(N);
	rep(u, N) {
		xu[u] = i_i(x[u], u);
		yu[u] = i_i(y[u], u);
	}
	sort(xu.begin(), xu.end());
	sort(yu.begin(), yu.end());
	vector<edge> E;
	rep(i, N - 1) E.pb(edge{xu[i].second, xu[i + 1].second, xu[i + 1].first - xu[i].first});
	rep(i, N - 1) E.pb(edge{yu[i].second, yu[i + 1].second, yu[i + 1].first - yu[i].first});
	cout << kruskal(N, E) << endl;
}


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

using namespace std;

const int maxn=1e6+10;

struct Node
{
    int a, b;
    bool operator <(const Node n) const {
        if(b == n.b) return a > n.a;
    	return b< n.b;
    }
}x[maxn];

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i ++) scanf("%d%d", &x[i].a, &x[i].b);
	sort(x, x + n);
	int t = 0;
	for(int i = 0; i < n; i ++)
    {
        if(x[i].a + t > x[i].b) return puts("No"), 0;
        t = t + x[i].a;
    }
    puts("Yes");
	return 0;
}


Measured memory_bytes: 1792
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = []
for _ in range(N):
  b.append(int(input()))
for n in range(N):
  for i in range(3):
    for j in range(3):
      if b[n]==A[i][j]:
        A[i][j]=0
a=A[0][0]+A[0][1]+A[0][2]
b=A[1][0]+A[1][1]+A[1][2]
c=A[2][0]+A[2][1]+A[2][2]
d=A[0][0]+A[1][0]+A[2][0]
e=A[0][1]+A[1][1]+A[2][1]
f=A[0][2]+A[1][2]+A[2][2]
g=A[0][0]+A[1][1]+A[2][2]
h=A[0][2]+A[1][1]+A[2][0]
if a==0 or b==0 or c==0 or d==0 or e==0 or f==0 or g==0 or h==0:
  print('Yes')
else:
  print('No')

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

int main(){
  int n;
  cin >> n;
  string ans = "No";
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(n==i*j)
        ans = "Yes" ;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vc vector
#define a first
#define b second
#define pb push_back
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)

/////////////////////////////////////////////////////////

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

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

/////////////////////////////////////////////////////////

void Main(){
  int n;
  cin >> n;
  n %= 10;
  if(n == 3){
    cout << "bon" << endl;
  }
  else if((n == 0) || (n == 1) || (n == 6) || (n == 8)){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();

  return 0;
}


Measured memory_bytes: 3604
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def count_black(subset, c):
    black = total_black
    for i in range(len(c)):
        if i in subset:
            for item in c[i]:
                if '#' == item:
                    black -= 1

    for i in range(len(c[0])):
        if len(c) + i in subset:
            for j in range(len(c)):
                if j not in subset:
                    if '#' == c[j][i]:
                        black -= 1
    return black


def candidates(subset, k, c):
    start_at = 0 if len(subset) == 0 else subset[-1] + 1
    go_to = len(c) + len(c[0])
    for i in range(start_at, go_to):
        yield subset + [i]


solutions = 0
def backtrack(subset, k, c):
    curr = count_black(subset, c)
    if curr < k:
        return
    if curr == k:
        global solutions
        solutions += 1
    for cand in candidates(subset, k, c):
        backtrack(cand, k, c)


def solve(h, w, k, c):
    backtrack([], k, c)
    return solutions


total_black = 0
if __name__ == "__main__":
    h, w, k = arr_in()
    c = []
    for _ in range(h):
        c.append(str_in())
        total_black += c[-1].count("#")
    out(solve(h, w, k, c))

Measured memory_bytes: 75616
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>

using namespace std;
const int MOD=2e5+10;

int main()
{
    int n,left,right;
	LL A[MOD],ans=0;
	LL sum,sumx;

	cin>>n;
	
	rep(i,n) {
		cin>>A[i];
	}
	
	left=right=0;
	sum=sumx=A[0];
	
	while(left<n) {
		while(right<n-1) {
			if((sumx^A[right+1])!=sum+A[right+1]) break;
			right++;
			sumx^=A[right];
			sum=sumx;
		}
		ans+=(right-left+1);
		
		sumx^=A[left];
		sum-=A[left];
//		if(left>=n-1) break;
		left++;
	}
	
	cout<<ans;
		
	rt0;
}


Measured memory_bytes: 1792
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;

template<class T>
using vec2d = std::vector<std::vector<T>>;


template<class T>
vec2d<T> makeVec2d(const int n1, const int n2, const T initValue) {
  return vec2d<T>(n1, vec<T>(n2, initValue));
}


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


#define all(c) c.begin(), c.end()


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream& in, ostream& out) {
  auto s = next<string>(in);
  auto t = next<string>(in);

  vec2d<int> f = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
  vec2d<int> p = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
  f[0][0] = 0;
  FOR(i, s.length()) {
    FOR(j, t.length()) {
      if (f[i][j] != -1) {
        if (f[i + 1][j] < f[i][j]) {
          f[i + 1][j] = f[i][j];
          p[i + 1][j] = 0;
        }
        if (f[i][j + 1] < f[i][j]) {
          f[i][j + 1] = f[i][j];
          p[i][j + 1] = 1;
        }
        if (s[i] == t[j]) {
          if (f[i + 1][j + 1] < f[i][j] + 1) {
            f[i + 1][j + 1] = f[i][j] + 1;
            p[i + 1][j + 1] = 2;
          }
        }
      }
    }
  }
  int res = 0;
  int bi = 0, bj = 0;
  FOR(i, s.length() + 1) {
    FOR(j, t.length() + 1) {
      if (res < f[i][j]) {
        res = f[i][j];
        bi = i;
        bj = j;
      }
    }
  }
  string r;
  while (bi != 0 || bj != 0) {
    if (p[bi][bj] == 2) {
      r.push_back(s[bi-1]);
      --bi;
      --bj;
    } else if (p[bi][bj] == 0) {
      --bi;
    } else {
      --bj;
    }
  }
  reverse(all(r));
  out << r << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



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


using namespace std;

int main()
{
  int q;
  cin >> q;
  while(1){
	if (q <= 0) break;
	int n ;
	cin >> n;
	int count = 0;
	string hoge;
	hoge = to_string(n);
	while(1){
	  int max = 0;
	  int l = hoge.length();
	  if(l <= 1) break;
	  int i;
	  
	  for (i = 1; i < l; i++) {
		string a,b;
		int c,d;
		a = hoge.substr(0,i);
		b = hoge.substr(i);
		// cout << a << endl;
		// cout << b << endl;
		c = stoi(a);
		d = stoi(b);
		if(max < c * d) max  = c * d;
		// cout << max << endl;	
	  }
	  
	  count++;
	  if(max >= 10) hoge = to_string(max);
	  else break;
	}
	cout << count << endl;
	q--;
  }  
  return 0;
}

Measured memory_bytes: 3268
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	s := getNextString(scanner)
	cc := make([][10]int, n+1)
	for i := 0; i < n; i++ {
		for j := 0; j < 10; j++ {
			cc[i+1][j] = cc[i][j]
		}
		cc[i+1][s[i]-'0']++
	}
	numbers := make([]int, 1000)
	for i := 1; i < n-1; i++ {
		for j := 0; j < 10; j++ {
			for k := 0; k < 10; k++ {
				if cc[i][j] == 0 {
					continue
				}
				if cc[n][k]-cc[i+1][k] == 0 {
					continue
				}
				numbers[100*j+10*int(s[i]-'0')+k]++
			}
		}
	}
	var ans int
	for i := 0; i < 1000; i++ {
		if numbers[i] == 0 {
			continue
		}
		ans++
	}
	fmt.Fprintln(writer, ans)
}


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

int main()
{
    ll N,i,j,cnt=0,p1=0,p2=0,ans,p3=0,p4=0;
    string s;
    
    cin>>N;
    for(i=1;i<=N;i++)
    {
        cin>>s;
       
        
        for(j=0;j<s.size()-1;j++)
        {
            if(s[j]=='A' && s[j+1]=='B')
            cnt ++;
        }
        if(s[0]=='B'  && s[s.size()-1] !='A')
        p2++;
        
        if(s[s.size()-1] =='A' && s[0]!='B')
        p1++;
        
        if(s[0]=='B' && s[s.size()-1] =='A')
        p3++;
    }
    
    if(p3>0)
    {
    cnt = cnt + p3 -1;
    p1++;
    
    if(p1>1)
    {
        cnt++;
        p1--;
        
    }
    
    ans = cnt + min(p1,p2);
    
    
    cout<<ans;
    }
    
    else
    {
        ans = cnt + min(p1,p2);
        cout<<ans;
    }
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

const int N=1e5+10;
const ll INF=1e9+7;
ll a[N<<4];
int sum[11];
main(){
    
    int h,w,n;scanf("%d%d%d",&h,&w,&n);
    int x,y;
    int cnt=0;
    ll m=(ll)(h-2)*(w-2);
    rep(iii,n){
        scanf("%d%d",&x,&y);
        rep(i,3)if( x-i>=1 && x-i<=h-2 ){
            rep(j,3)if(y-j>=1 && y-j<=w-2){
            a[cnt++]=(1ll<<32)*(x-i)+(y-j);
            }
        }
    }
    sort(a,a+cnt);
    ll t=1;
    rep(i,cnt){
        if(a[i]==a[i+1])t++;
        else sum[t]++,t=1,m--;
    }
    printf("%lld %d %d %d %d %d %d %d %d %d",m,sum[1],sum[2],sum[3],sum[4],sum[5],sum[6],sum[7],sum[8],sum[9]);
}



Measured memory_bytes: 8448
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int n,m;
string s;
int a[100];
ll ans=0;

inline ll bfs(){
  queue<pair<int,ll> > q;
  q.push(make_pair(1,a[0]));
  q.push(make_pair(1,a[0]-1));
  q.push(make_pair(1,a[0]+1));
  while(!q.empty()){
    int now=q.front().fi;
    int nowsum=q.front().se;
    q.pop();
    if(now==n){
      if(nowsum%2==0)ans++;
      continue;
    }
    q.push(make_pair(now+1,nowsum*a[now]));
    q.push(make_pair(now+1,nowsum*(a[now]+1)));
    q.push(make_pair(now+1,nowsum*(a[now]-1)));
  }
  return ans;
}
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  cout<<bfs()<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<string.h>
int main(){
  char i,s[10010],c[10]={"YAKI"};
  scanf("%s",s);
  for(i=0;i<4;i++){
    if(s[i]-c[i])break;
  }
  printf("%s\n",i<4?"No":"Yes");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 510000;
const int MOD =  1000000007;
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

     signed main(){
     int n;
     cin>>n;
     int h[n+1]={};
     for(int i=0;i<n;i++)cin>>h[i];
     int dp[n][n+1];
     dp[0][n]=modpow(2,h[0],MOD);
     for(int i=0;i<n;i++){
       if(h[i]<=h[0]){
         dp[0][i]=modpow(2,h[0]-h[i]+1,MOD);
       }else dp[0][i]=0;
     }
     for(int i=1;i<n;i++){
       if(h[i]>h[i-1]){
         for(int j=0;j<=n;j++){
           if(h[i]>=h[j]){
             if(h[j]>h[i-1]){
               dp[i][j]=(dp[i-1][i-1]*modpow(2,h[i]-h[j],MOD)%MOD)*2%MOD;
             }else dp[i][j]=(dp[i-1][j]*modpow(2,h[i]-h[i-1],MOD)%MOD+dp[i-1][i-1]*modpow(2,h[i]-h[i-1],MOD)%MOD)%MOD;
           }else dp[i][j]=0;
         }
       }else{
         for(int j=0;j<=n;j++){
           if(h[i]>=h[j]){
             dp[i][j]=(dp[i-1][j]+dp[i-1][i])%MOD;
           }else dp[i][j]=0;
         }
       }
     }
     cout<<dp[n-1][n]<<endl;
                  
}


        


Measured memory_bytes: 384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

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

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


def main():
    rr = []

    def f(n,m):
        a = [LI_() for _ in range(m)]
        p = collections.defaultdict(list)
        c = collections.defaultdict(list)
        for s,d in a:
            p[s].append(d)
            c[d].append(s)

        v = collections.defaultdict(int)
        d = collections.defaultdict(lambda: -1)
        b = collections.defaultdict(set)
        def _f(i):
            # print('_f',i)
            if v[i] == 2:
                return -1
            if v[i] == 1:
                d[i] = i
                b[i].add(i)
                return i
            v[i] = 1
            for j in p[i]:
                r = _f(j)
                if r < 0:
                    continue
                d[i] = r
                b[r].add(i)
            v[i] = 2
            if d[i] == i:
                return -1
            return d[i]

        for i in range(n):
            _f(i)

        def g(i):
            # print('g',i)
            if d[i] >= 0 and d[i] != i:
                return 1
            cs = set(c[i])
            if d[i] == i:
                for j in b[i]:
                    cs |= set(c[j])
            r = 1
            # print('cs',i,cs)
            for j in cs:
                if j in b[i]:
                    continue
                gr = g(j)
                # print('jgr',j,gr)
                r *= gr
                r %= mod
            r += 1
            return r

        r = 1
        for i in range(n):
            if d[i] == i or len(p[i]) == 0:
                gr = g(i)
                # print('igr',i,gr)
                r *= gr
                r %= mod

        return r

    while 1:
        n,m = LI()
        if n == 0:
            break
        rr.append(f(n,m))
        break

    return '\n'.join(map(str, rr))


print(main())



Measured memory_bytes: 9688
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

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

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


def main():
    n,k = LI()
    a = LI()
    t = []
    for i in range(42):
        ii = 2**i
        b = 0
        for c in a:
            if c & ii:
                b += 1
        t.append([b*ii,(n-b)*ii])

    fm = {}
    def f(i,mf):
        if i < 0:
            return 0
        fk = (i,mf)
        if fk in fm:
            return fm[fk]
        ii = 2**i
        r = 0
        if k & ii or not mf:
            b = f(i-1,mf)
            b += t[i][1]
            if r < b:
                r = b
            b = f(i-1,False)
            b += t[i][0]
            if r < b:
                r = b
        elif mf:
            b = f(i-1,mf)
            b += t[i][0]
            if r < b:
                r = b
        fm[fk] = r
        return r

    mi = 0
    for i in range(1,42):
        ii = 2**i
        if ii > k:
            mi = i - 1
            break
    r = f(40,True)

    return r



print(main())




Measured memory_bytes: 17144
#include <stdio.h>

int main() {
int L,R,d,count=0;
scanf("%d",&L);
scanf("%d",&R);
scanf("%d",&d);
 
 for(int i=L;i<=R;i++){
 if(i%d==0){
   count++;
 }
 }
printf("%d",count);
}

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> pos(n + 2);
  for (int i = 0; i < n; i++) {
    cin >> pos[i + 1];
  }
  int sum = 0;
  for (int i = 0; i < n + 1; i++) {
    sum += abs(pos[i + 1] - pos[i]);
  }
  for (int i = 1; i <= n; i++) {
    cout << sum - abs(pos[i] - pos[i - 1]) - abs(pos[i] - pos[i + 1])
                + abs(pos[i + 1] - pos[i - 1]) << '\n';
  }
  return 0;
}

Measured memory_bytes: 1664
while True:
    n = input()
    s = input()
    n = int(n)
    if(n==len(s)):
         break
    else:
        print("error")

d  = ''

for i in range(0,len(s)-1):
    if s[i]!=s[i+1]:
        d+=s[i]

d += s[len(s)-1]
print(len(d))


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

const int MAXN = 105;
int H;
int G[MAXN][MAXN];

int main() {
  string s;
  int pre = -1;
  int b = 0;
  fill(G[0], G[MAXN], -1);
  for(H = 0; cin >> s; ++H) {
    int num = count(s.begin(), s.end(), ',');
    replace(s.begin(), s.end(), ',', ' ');
    stringstream ss(s);
    if(num < pre) ++b;
    pre = num;
    for(int i = 0; ss >> G[H][b+i]; ++i);

  }
  for(int i = 1; i < H; ++i) {
    for(int j = 0; j < H; ++j) {
      if(G[i][j] == -1) continue;
      int maxi = 0;
      if(j-1 >= 0) maxi = max(maxi, G[i-1][j-1]);
      maxi = max(maxi, G[i-1][j]);
      G[i][j] += maxi;
      if(i == H-1) cout << G[i][j] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
#define mod 1000000007
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
int fact[200010],ifact[200010],c[200010],w[200010],mnw[200010],cnt[200010],p[200010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),X=gi(),Y=gi(),ans=1;
	fact[0]=1;for(int i=1;i<=n;++i)fact[i]=1ll*fact[i-1]*i%mod;
	ifact[n]=pow(fact[n],mod-2);for(int i=n;i;--i)ifact[i-1]=1ll*ifact[i]*i%mod;
	for(int i=0;i<=n;++i)mnw[i]=1e9;
	for(int i=1;i<=n;++i)c[i]=gi(),w[i]=gi(),mnw[c[i]]=std::min(mnw[c[i]],w[i]);
	for(int i=1;i<=n;++i)
		if(mnw[c[i]]+w[i]<=X)w[i]=mnw[c[i]],++cnt[c[i]];
		else if(w[i]==mnw[c[i]])++cnt[c[i]];
	int mn=0,cmn=0;
	for(int i=1;i<=n;++i){
		if(mnw[mn]>mnw[i])cmn=mn,mn=i;
		else if(mnw[cmn]>mnw[i])cmn=i;
	}
	int sz=cnt[mn];
	for(int i=1;i<=n;++i)if(c[i]!=mn&&mnw[mn]+w[i]<=Y)++sz,++p[c[i]];
	if(sz==cnt[mn])return puts("1"),0;
	for(int i=1;i<=n;++i)if(c[i]==mn&&w[i]!=mnw[mn]&&mnw[cmn]+w[i]<=Y)++sz,++p[c[i]];
	p[mn]+=cnt[mn];
	ans=fact[sz];
	for(int i=1;i<=n;++i)ans=1ll*ans*ifact[p[i]]%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int gcd( int x, int y ){ return y ? gcd(y, x%y) : x; }
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
int a=0,b=0,c=0,d=0;
while (true) {
  std::cin >> n;
  if(n==-1)break;
if(n<=10)std::cout << 4280-1150 << '\n';
else if(n<=20)std::cout << 4280-(1150+(n-10)*125) << '\n';
else if(n<=30)std::cout << 4280-(1150+1250+(n-20)*140) << '\n';
else std::cout << 4280-(1150+1250+1400+(n-30)*160) << '\n';
}
}



Measured memory_bytes: 3084
#include <iostream>
#include <cmath>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b){
  ll r = min(a, b);
  ll q = max(a, b);
  while (r != 0){
    ll tmp = r;
    r = q % r;
    q = tmp;
  }
  return q;
}

int main(){
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll l = C * D / gcd(C, D);
  ll Nc = B / C -  (A - 1) / C, Nd = B / D - (A - 1) / D, Ncd = B / l - (A - 1) / l;
  cout << (B - A + 1) - (Nc + Nd - Ncd) << endl;
  return 0;
}

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

using namespace std;


int main() {
  int input;

  scanf("%d", &input);

  int sum = 0, tmp = input;
  while(tmp != 0){
    sum += tmp % 10;
    tmp /= 10;
  }

  if(input % sum == 0){
    printf("Yes");
  }else{
    printf("No");
  }

  return 0;
}


Measured memory_bytes: 128
S = input()

subs = 0
l = len(S)
i = 0
while i < l:
    if S[i] != "A":
        i += 1
        continue
    else:
        for j in range(l-1, i, -1):
            if S[j] == "Z":
                subs = j - i + 1
                break
        break
print(subs)

Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

map<int,vector<int> > mp;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
	rep(i,n){
        int x;
        cin >> x;
        mp[-x].push_back(i);
	}
    vl ans(n, 0);
    set<int> st;
    for(auto it = mp.begin(); it != mp.end(); it++){
        each(id,it->se){
            st.insert(id);
        }
        if(len(st) == n){
            ans[0] += (ll)n*(-it->fi);
            break;
        }else{
            it++;
            int val = -it->fi;
            it--;
            ans[*st.begin()] += (ll)len(st)*(-it->fi-val);
        }
    }
    rep(i,n){
        cout << ans[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 17536
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

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

	var cnt int
	for i := 0; i < n; i++ {
		if p[i] != i+1 {
			cnt++
		}
		if cnt > 2 {
			fmt.Println("NO")
			break
		}
	}
	if cnt <= 2 {
		fmt.Println("YES")
	}
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    int K;
    cin >> K;
    int ans = max({A, B, C});
    int d = A + B + C - ans;
    rep(i, 0, K) ans *= 2;
    ans += d;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%d", $k);
fscanf(STDIN, "%d", $x);
fscanf(STDIN, "%d", $y);
 
if ($n < $k) {
$result = $n * $x;
} else {
$result = ($k * $x) + ($n - $k) * $y;
}
echo $result;
?>

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A/D > C/B){
    cout << "Yes" <<endl;
  }
  else if(A/D == C/B && A%D != 0){
    cout << "Yes" << endl;
  }
  else if(A/D+1 == C/B && A%D != 0 && C%B == 0){
    cout << "Yes" << endl;
  }
  else if(A/D == C/B && A%D == 0 && C%B == 0){
    cout << "Yes" <<endl;
  }
  else{
    cout << " No" << endl;
  }
}


Measured memory_bytes: 3636
#include <iostream>
 #include <vector>
 #include <map>
 #include <string>
 #include <algorithm>
 using namespace std;

 typedef long long ll;



 int main()
 {
    int n;
    cin >> n;
    vector<int> h(n);

    for(int i = 0; i < n; i++)
    {
        cin >> h.at(i);
    }

    h.at(0)--;

    for(int i = 1;i < n; i++)
    {
        if(h.at(i) - 1 >= h.at(i - 1))
        {
            h.at(i)--;
        }
        else if(h.at(i) < h.at(i - 1))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;

     return 0;
 }

Measured memory_bytes: 640
S = input()
N = len(S)

for i in range(int((len(S)-1)/2)):
  if(S[i] != S[(i+1)*(-1)]):
    print('No')
    exit()

for i in range(int((len(S)-1)/4)):
  if S[i] != S[int((N-1)/2-1-i)]:
    print('No')
    exit()

for i in range(int((len(S)-1)/4)):
  if S[int((N+3)/2-1+i)] != S[(i+1)*(-1)]:
    print('No')
    exit()

print('Yes')


Measured memory_bytes: 3064
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x, ll m) { if (x == 0) {return 1;} ll ans = 1; ll k = 1;  while (k <= x) {if (x & k) {ans = ((ans * a) % m);} k <<= 1; a *= a; a %= m; } return ans; }
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int d, n;
    cin >> d >> n;

    int sum = 0;
    forr(i, n) {
        int a;
        cin >> a;
        sum += a;
    }
    int ans  = max(-1LL, d - sum);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
ll n,a[100005],b[100005],c[100005],dp[100005][5];
int main(){
   cin>>n;
   for(ll i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
   dp[1][1]=a[1];
   dp[1][2]=b[1];
   dp[1][3]=c[1];
   for(ll i=2;i<=n;i++){
      dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
      dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
      dp[i][3]=max(dp[i-1][1],dp[i-1][2])+c[i];
   }
   cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
   return 0;
}

Measured memory_bytes: 9808
h, w = map(int, input().split())
s = [input() for i in range(h)]
flag = True

for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      top = max(0, i-1)
      bottom = min(h-1, i+1)
      right = min(w-1, j+1)
      left = max(0, j-1)
      if s[i][right] != "#" and s[i][left] != "#" and s[top][j] != "#" and s[bottom][j] != "#":
        flag = False
        break
  if flag == False:
    break

if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
    int v;
    color[u]=GRAY;
    d[u]=++tt; //最初の訪問
    for(v=0; v<n; v++){
        if(M[u][v]==0){ continue; }
        if(color[v]==WHITE){ dfs_visit(v); } 
    }
    color[u]=BLACK;
    f[u]=++tt;//訪問の完了
}

void dfs(){
    int u;
    //初期化
    for(u=0; u<n; u++){ 
        color[u]=WHITE; 
    }

    tt=0;

    for(u=0; u<n; u++){
        //未訪問のuを始点として深さ優先探索
        if(color[u]==WHITE){ dfs_visit(u); }
    }

    for(u=0; u<n; u++){
        printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}

int main(){
    int u,v,k,i,j;

    scanf("%d",&n);
    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            M[i][j]=0;
        }
    }

    for(i=0; i<n; i++){
        scanf("%d %d",&u,&k);
        u--;
        for(j=0; j<k; j++){
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }

    dfs();

    return 0;
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  string X;
  cin >> X;

  int s = 0,sum = 0;
  int N = X.size();
  for(int i = 0;i < N;i++) {
    if(X.at(i) == 'S') s++;
    else if(X.at(i) == 'T') {
      if(s > 0) {
        sum += 2;
        s--;
      }
    }
  }

  cout << N - sum << endl;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

int main(void){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  ll ans = MOD;
  for(int i = 0; i <= max(x, y) * 2; i += 2){
    int num_A = max(0, x - i / 2);
    int num_B = max(0, y - i / 2);
    ll sum = num_A * a + num_B * b + i * c;
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    ll l = 0, r = INF;
    ll mid = 0;
    while(l + 1 < r) {
        mid = (l + r) / 2;
        ll b_damage = b * mid;
        ll cnt = 0;
        for (ll i = 0; i < n; i++) {
            ll c = h[i] - b_damage;
            if (c > 0) {
                cnt += (c + a - b - 1) / (a - b);
            }
        }
        if (cnt <= mid) r = mid;
        else l = mid;
    }

    cout << r << endl;

    return 0;
}

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

#define ll long long
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

const int N =100;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);

}
ll f(ll n) {
	return n * (n - 1) / 2;
}
bool cmp(const tuple<int, string, string>& a,
               const tuple<int, string, string>& b)
{
    return (get<0>(a) < get<0>(b));
}
void solve()
{
   string s;
   int ans=0;
   int c=0;
   cin>>s;
   for(int i=0;i<s.length();i++)
   {
       if(s[i]=='R')
       {

           c++;
       }
       else
       {
           ans = max(ans,c);
           c=0;
       }
   }
   ans = max(ans,c);
   cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3616
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        n = n > b? b-1:n;
        long ans = 0;
        while(n > 0){
            if(floor(n,b) == 0){
                ans = floor(a*n,b) - a * floor(n, b);
                break;
            }
            n--;
        }
        System.out.println(ans);
    }

    static long floor(long x,long num){
        return x/num;
    }  
}

Measured memory_bytes: 35768
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>
#include <stdlib.h>
# include <map>

using namespace std;

int main(){
    int n ,t, a ,ans , h ;
    double candidate;
    float tmp;
    tmp = pow(10 , 9);
    cin >> n>> t>> a;
    for(int i = 0;i < n;i++){
        cin >> h;
        if (abs(a-(t-0.006*h)) < tmp){
            tmp = abs(a-(t-0.006*h));
            ans  = i+1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define all(x) (x).begin, (x).end()
#define SORT(v,n) sort(v,v+n)
#define VSORT(v) sort(all(x))
#define inf 999999999
#define debug(x) cout<<#x<<":"<<x<<endl;
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define pi 2*acos(0.0)
#define in scanf
#define out printf
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define true 1
#define false 0

// --
#define bit(n) (1LL<<(n)) // ???bit?????????
// --

using namespace std;

typedef long long llong;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<llong, pll> plp;

typedef pair<string, int> psi;

const int MOD=1000000007;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};  // ????????????


int main(int argc, char**argv){
    int n, q, sum = 0;
    cin >> n >> q;
    queue<psi> que;
    REP(i, n){
        psi p;
        cin >> p.first >> p.second;
        que.push(p);
    }
    while(!que.empty()){
        psi p = que.front();
        que.pop();
        if (p.second <= q){
            sum += p.second;
            cout << p.first << " " << sum << endl;
        }else {
            sum += q;
            p.second -= q;
            que.push(p);
        }
    }
    return 0;
}

Measured memory_bytes: 6376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static class Point {
		double x;
		double y;
		public Point(double x, double y) {
			this.x = x;
			this.y = y;
		}
		public String toString() {
			return String.format("%.8f %.8f", x, y);
		}
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		reader.close();		
		getKochCurve(n, new Point(0, 0), new Point(100, 0));
	}

	private static void getKochCurve(int n, Point start, Point end) {
		System.out.println(start);
		getKochCurve(0, n, start, end);
		System.out.println(end);
	}

	private static void getKochCurve(int i, int n, Point start, Point end) {		
		if (i < n) {
			Point firstPoint = getPoint(start, end, 1.0/3.0);
			Point thirdPoint = getPoint(start, end, 2.0/3.0);
			Point secondPoint = getSecondPoint(start, end, firstPoint, thirdPoint);
			getKochCurve(i + 1, n, start, firstPoint);
			System.out.println(firstPoint);
			getKochCurve(i + 1, n, firstPoint, secondPoint);
			System.out.println(secondPoint);
			getKochCurve(i + 1, n, secondPoint, thirdPoint);
			System.out.println(thirdPoint);
			getKochCurve(i + 1, n, thirdPoint, end);
		}
	}

	private static Point getPoint(Point start, Point end, double d) {
		double deltaX = end.x - start.x;
		double deltaY = end.y - start.y;
		deltaX = deltaX * d;
		deltaY = deltaY * d;				
		return new Point(start.x + deltaX, start.y + deltaY);
	}

	private static Point getSecondPoint(Point start, Point end, Point second, Point third) {
		double deltaX = third.x - second.x;
		double deltaY = third.y - second.y;
		double len = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));		
		double x;
		double y;		
		if (deltaY == 0) {
			x = start.x + (end.x - start.x) / 2;
			if (start.x < end.x) {
				y = second.y + Math.sqrt((Math.pow(len, 2) - Math.pow(len / 2.0, 2)));
			} else {
				y = second.y - Math.sqrt((Math.pow(len, 2) - Math.pow(len / 2.0, 2)));
			}
		} else if (start.x < end.x && start.y < end.y) {
			x = start.x;
			y = third.y;
		} else if (start.x < end.x && start.y > end.y) {
			x = end.x;
			y = second.y;
		} else if (start.x > end.x && start.y < end.y) {
			x = end.x;
			y = second.y;
		} else {
			x = start.x;
			y = third.y;
		}
		return new Point(x, y);
	}
}


Measured memory_bytes: 39832
'use strict'

function Main(input){
  const tmpInputs = input.toString().split(" ");
  const N = parseInt(tmpInputs[0]);
  const L = parseInt(tmpInputs[1]);

  let totalTaste = 0;
  let tasteArray = [];
  let tasteAbsArray =[];
  //総和で味を出す
  for (let i=1 ; i<=N ; i++ ){
    let taste = L + i - 1;
    totalTaste = totalTaste + taste;
    tasteAbsArray.push(Math.abs(taste));
    tasteArray.push(taste);
  }

    console.log(totalTaste - tasteArray[tasteAbsArray.indexOf(Math.min(...tasteAbsArray))])

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372