akhauriyash/Code-Regression huggingface dataset:
H,W,K = map(int, input().split())

# 縦1マスなら、たての分割は行わず横だけ見て行く
if H == 1:
    S = input()
    cnt = 0
    ans = 0

    for i in range(W):
        if S[i] == "1":
            cnt += 1
        if cnt > K:
            ans += 1
            cnt = 1


    
    print(ans)
    exit()

# 横1マスなら、横の分割は行わずに縦だけ見て行く
elif W == 1:
    S = [input() for _ in range(H)]
    cnt = 0
    ans = 0
    for i in range(H):
        if S[i] == "1":
            cnt += 1

        if cnt > K:
            ans += 1
            cnt = 1
    print(ans)
    exit()


S = [input() for _ in range(H)]

ans = (H-1) + (W - 1)
for bit in range(1 << (H-1)):
    is_valid = True
    nums = bin(bit).count("1") + 1
    cnt_cut = bin(bit).count("1")


    # 横方向に割った時の、同じ区間かつ現在の列より左のホワイトチョコの数を管理するlist
    cnt_white_prev = [0] * nums

    for w in range(W):
        # 横方向に割った時の、現在の列のホワイトチョコの数を管理するlist
        cnt_white_curr = [0] * nums
        idx = 0

        # ある列にあるホワイトの数を数える
        for h in range(H):
            if S[h][w] == "1":
                cnt_white_curr[idx] += 1
            if h < H-1 and bit & (1 << h):
                idx += 1

        # K個を上回るブロックがあったか
        is_over_K = False
        
        for i in range(nums):

            
            if cnt_white_prev[i] + cnt_white_curr[i] > K:
                is_over_K = True
                if cnt_white_curr[i] > K:
                    is_valid = False
                break


        
        # K個を超えるブロックがあった場合、かつ、横方向の割り方は妥当な場合
        if is_over_K:
            cnt_cut += 1

            for i in range(nums):
                cnt_white_prev[i] = cnt_white_curr[i]
        else:
            for i in range(nums):
                cnt_white_prev[i] += cnt_white_curr[i]
    



    if is_valid:
        ans = min(ans, cnt_cut)

    

        

print(ans)

    


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

  int all_count, tmp_count;
  all_count = 0;
  for(int i = 0;i<n;i++){
    cin >> a;
    tmp_count = 0;
    while(a%2==0){
      a/=2;
      tmp_count++;
    }
    all_count += tmp_count;
  }
  cout << all_count << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        long[] c = new long[n];
        long total = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt()-1;
            b[(int)a[i]]++;
        }
        for(int i = 0; i < n; i++){
            if(b[i] == 0) continue;
            c[i] = b[i] * (b[i]-1) / 2;
            total += c[i];
        };
        for(int i = 0; i < n; i++){
            int ai = (int)a[i];
            long alt = (b[ai]-1)*(b[ai]-2)/2;
            System.out.println(total - c[ai] + alt);
        }
    }
}

Measured memory_bytes: 106204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e6 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
#define mst(x) memset(x, 0, sizeof(x))
priority_queue <int> qua;
ll a[maxx];
vector <ll> vec;
int n, k;
ll ans;

int main() {
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) {
		ll sum = 0;
		for(int j = i; j <= n; j++) {
			sum += a[j];
			vec.push_back(sum);
		}
	}
	for(int bit = 59; bit >= 0; bit--) {
		int t = 0;
		int sz = vec.size();
		for(int i = 0; i < sz; i++) {
			ll dd = 1ll << bit;
			if(vec[i] & dd) t++;
		}
		if(t < k) continue;
		vector <ll> tmp;
		tmp.clear();
		for(int i = 0; i < sz; i++) {
			ll dd = 1ll << bit;
			if(vec[i] & dd) tmp.push_back(vec[i]);
		}
		vec = tmp;
		ans += 1ll << bit;
	}
	cout << ans << endl;
}

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

namespace _0029
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true){
                var inputString = Console.ReadLine();
                string longNameWord = "";
                var wordDictionary = new Dictionary<string, int>();

                if (string.IsNullOrEmpty(inputString))
                {
                    break;
                }

                foreach (var word in inputString.Split(' '))
                {   
                    if(wordDictionary.ContainsKey(word))
                    {
                        wordDictionary[word] += 1; 
                    }
                    else
                    {
                        wordDictionary.Add(word, 1);
                    }

                    if(longNameWord.Count() < word.Count())
                    {
                        longNameWord = word;
                    }
                }
                var sortedDictionary = wordDictionary.OrderByDescending((kvp) => kvp.Value);
                Console.WriteLine("{0} {1}", sortedDictionary.First().Key, longNameWord);
            }
        }
    }
}

Measured memory_bytes: 20584
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	int from, to;
	ll w;
};
typedef vector<vector<Edge>> Graph;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}

ll gettugibaisu(ll from, ll k) {

	ll ret = ((from + k - 1) / k) * k;

	return ret;
}

ll getmaebaisu(ll to, ll k) {

	ll ret = (to / k) * k;

	return ret;
}
class Loli {
	char str[601];
	int hash[601], pw[601];
	int mod = 1000000007, base = 1007;
	int len;
public:
	Loli() {};
	
	void setstr(char *str2, int n) {
		strcpy(str,str2);
		len = n;
		hash[0] = 0;
		pw[0] = 1;
		rep(i, 1, len + 1) {
			pw[i] = ((ll)pw[i - 1] * base) % mod;
			hash[i] = ((ll)hash[i - 1] * base + (int)str[i - 1]) % mod;
		}
	}

	inline int gethash(int l, int r) {//半開
		return  (hash[r] - (ll)hash[l] * pw[r - l] % mod + mod) % mod;
	}
};


signed main(void) {

	int n;

	cin >> n;
	vector<int> a(n);
	
	map<int, int> pos;
	REP(i, n) {
		scanf("%d", &a[i]);
		pos[a[i]] = i;
	}

	int Max = 0, dp[200001] = {};

	Fill(dp, 1);

	REP(i, n) {
		if(pos.count(a[i]-1) && pos[a[i] - 1] < i)
			dp[i] = dp[pos[a[i]-1]] + 1;
		Max = max(Max, dp[i]);
	}
	
	cout << n - Max << endl;

	return 0;
}



Measured memory_bytes: 11136
n = int(input())
l = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    l.append([s, p])
l_s = sorted(l, key = lambda l:(l[0], -l[1]))
for i in l_s:
    print(l.index(i) + 1)


Measured memory_bytes: 38384
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
b = [list(map(int,input().split())) for i in range(n)]

b.sort(key=lambda x: x[0])
a.sort(key=lambda x: x[1])
seen = [0]*n
count = 0

for i in range(n):
  for j in range(n):
    if (seen[j] == 0) and (a[-(i+1)][0] < b[j][0]) and (a[-(i+1)][1] < b[j][1]):
      seen[j] = 1
      count = count + 1
      break
      
print(count)

Measured memory_bytes: 3064
N = int(input())
A = []
for i in range(N):
    x, l = map(int, input().split())
    A.append([x+l, x-l])
A.sort()
ans = 1
check1 = A[0]
for i in range(1, N):
    check2 = A[i]
    if check1[0] <= check2[1]:
        ans += 1
        check1 = check2
print(ans)

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

struct Tree{
 struct Node{ int l=-1,r=-1,p=-1; int v; };
 vector<Node> V;
 int R=-1;

 void insert(int v){
  int* pp=&R;
  int p=R;
  while(p!=-1){
   if(v<V[p].v){ pp=&V[p].l; p=V[p].l; }
   else{ pp=&V[p].r; p=V[p].r; }
  }
  *pp=V.size();
  V.push_back({-1,-1,p,v});
 }
 int find(int v){
  int p=R;
  while(p!=-1){
   if(v==V[p].v) return p;
   if(v<V[p].v) p=V[p].l; else p=V[p].r;
  }
  return -1;
 }

 void printPreorder(int p=-2){
  if(p==-2) p=R;
  if(p==-1) return;
  printf(" %d",V[p].v);
  printPreorder(V[p].l);
  printPreorder(V[p].r);
 }
 void printInorder(int p=-2){
  if(p==-2) p=R;
  if(p==-1) return;
  printInorder(V[p].l);
  printf(" %d",V[p].v);
  printInorder(V[p].r);
 }
};

Tree T;
int Q;

int main() {
 scanf("%d",&Q);
 rep(i,Q){
  string c;
  { char buf[10]; scanf("%s",buf); c=buf; }
  if(c=="insert"){
   int v; scanf("%u",&v);
   T.insert(v);
  }
  else if(c=="find"){
   int v; scanf("%u",&v);
   if(T.find(v)==-1) printf("no\n"); else printf("yes\n");
  }
  else if(c=="print"){
   T.printInorder(); printf("\n");
   T.printPreorder(); printf("\n");
  }
 }
}



Measured memory_bytes: 11236
#include<stdio.h>
#define MAX 100
int INFTY=(1<<21);
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

int prim(){
  int u,minv,i,v;
  int d[MAX],p[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }

    if(u==-1)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  int sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }

  return sum;
}
    
  

int main(){
  int i,j;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      int e;
      scanf("%d",&e);
      M[i][j]=(e==-1)?INFTY:e;
    }
  }

  printf("%d\n",prim());

  return 0;
}



Measured memory_bytes: 2108
/*
Hanit Banga
Problem: 
*/

#include <iostream>
#include <vector>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

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

const int N = 1e5 + 5;

int main()
{
	ll I, O, T, J, L, S, Z;
	cin >> I >> O >> T >> J >> L >> S >> Z;

	ll ans = O;

	if (!L or !J or !I)
		ans += (L/2)*2 + (J/2)*2 + (I/2)*2;

	else if ((L%2) == (J%2) and (J%2) == (I%2))
		ans += L + J + I;

	else
		ans += L + J + I - 1;

	cout << ans;
}

Measured memory_bytes: 256
Module Module1


    Sub Main()

        Dim sInput As Integer
        sInput = Console.ReadLine()
        Dim sExpect1000 As Integer = sInput \ 500
        Dim sExpect5 As Integer = (sInput Mod 500) \ 5
        Console.WriteLine(sExpect1000 * 1000 + sExpect5 * 5)
        Console.ReadLine()
    End Sub

End Module


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

int N;
int is_prime[100005];
int suffix_sum[100005];

int main() {
    ios_base::sync_with_stdio(false);
    
    for(int i = 2; i <= 100000; i++) {
	if (!(i % 2)) {
	    continue;
	}
	int j;
	for(j = 2; j <= sqrt(i); j++) {
	    if (!(i % j)) {
		break;
	    }
	}
	if (j > sqrt(i)) {
	    is_prime[i] = true;
	}
    }
    is_prime[2] = true;

    int cnt = 0;
    for(int i = 1; i <= 100000; i++) {
	if (i % 2 && is_prime[i] && is_prime[(i+1)/2]) {
	    cnt++;
	}
	suffix_sum[i] = cnt;
    }

    cin >> N;
    int l, r;
    for(int i = 0; i < N; i++) {
    	cin >> l >> r;
	cout << suffix_sum[r] - suffix_sum[l-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll h = c - a;
  ll w = d - b;
  vector<vector<mint>> dp(h + 1, vector<mint>(w + 1, 0));
  rep(i, h + 1) dp[i][0] = mint(b).pow(i);
  rep(j, w + 1) dp[0][j] = mint(a).pow(j);
  rep2(k, 2, h + w + 1) {
    rep2(i, 1, k) {
      ll j = k - i;
      if(i > h || j > w) continue;
      dp[i][j] += dp[i - 1][j] * (b + j) + dp[i][j - 1] * (a + i);
      dp[i][j] -= dp[i - 1][j - 1] * (a + i - 1) * (b + j - 1);
      // printf("dp[%d][%d]=%d\n", i, j, dp[i][j]);
    }
  }
  cout << dp[h][w] << endl;
}

Measured memory_bytes: 73584
process.stdin.resume();
process.stdin.setEncoding('utf8');
let input = '';
process.stdin.on('data', function(chunk) {input += chunk;});
process.stdin.on('end', function() {main(input.split(/\r?\n/));});

function partition(A,p,r) {
	let x = A[r];
	let i = p - 1;
	let tmp;
	for (let j = p; j < r; j++) {
		if (A[j] <= x) {
			i++;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	i++;
	tmp = A[i];
	A[i] = A[r];
	A[r] = tmp;

	return i;
}

function main(lines){
	let n = Number(lines[0]);
	let A = lines[1].split(" ").map(Number);
	let target = partition(A,0,n-1);

	A[target] = "[" + A[target] + "]";

	console.log(A.join(" "));	
}



Measured memory_bytes: 32504
//#include <bits/stc++.h>
#include <bits/stdc++.h>
#include <string> 
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b

char cry(char a)
{
	return ('Z'-a)+'A';
}
int main()
{
	long long n,k;
	cin>>n>>k;
	if(n>=k)
	{
		for(long long i=0; i<n; i++)
		{
			cout<<k;
		}
		cout<<endl;
	}
	else
	{
		for(long long i=0; i<k; i++)
		{
			cout<<n;
		}
		cout<<endl;
	}
	

return 0;
}


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

#define F first    
#define S second
#define mp make_pair
#define pii pair<int,int>         
// mikty prikoldar
#define ll long long  
#define pb push_back
#define sz(a) (int)(a.size())
#define Accepted 0
#define endl '\n'
//everything goes according to the plan
#define y1 		 NOT
#define left   NEEDED
#define right  THINGS  
//countdown BEGAN. 10 , 9 , 8 ...
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 9223372036854775807;
const int Sz = 1110111;
// ai dyn dyn dyn dirindai ai dyn dyn dirindai
using namespace std;
// skr skr skr v chernih naikah
inline void Read_rap () {	// smoke weed everyday
  ios_base :: sync_with_stdio(0);
	cin.tie(0);      
}
int n;

ll l[Sz], r[Sz];
           
ll ans;

int a[Sz];
       
int main() 
{
	Read_rap ();
	cin >> n;
	for (int i = 1;i <= n;i ++)	cin >> a[i];
	
	stack <int> st;
	for (int i = 1;i <= n;i ++) {
		l[i] = i;
		while (sz(st) && a[st.top()] > a[i]) {
			l[i] = l[st.top()];
			st.pop ();
		}
		st.push (i);
	}	
	while (!st.empty())	st.pop ();

	for (int i = n;i >= 1;i --) {
		r[i] = i;
		while (sz(st) && a[st.top()] > a[i]) {
			r[i] = r[st.top()];
			st.pop ();
		}
		st.push (i);
	}	
	for (int i = 1;i <= n;i ++) {         
		ll cnt = (r[i] - i + 1) * (i - l[i] + 1);
		ans += cnt * a[i];
	}
	cout << ans;	

	return Accepted;
}	









// Coded by Z...

Measured memory_bytes: 4992
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

X, Y, Z = LI()

print(Z, X, Y)


Measured memory_bytes: 38256
/*
    If they say
    Who cares if one more light goes out?
    In a sky of a million stars
    It flickers, flickers
    Who cares when someone's time runs out?
    If a moment is all we are
    We're quicker, quicker
    Who cares if one more light goes out?
    Well I do
*/

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

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()

#define ll long long
#define ull unsigned long long
#define VI vector<int>
#define VLL vector<ll>
#define VS vector<string>
#define MPII map<int, int>
#define SET set<int>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);

ll MOD = 1e9+7;

ll add(ll a, ll b)
{
	a+=b; a%=MOD;
	if(a<0) a+=MOD;
	return a;
}
ll mult(ll a, ll b)
{
	if(a>MOD) a%=MOD;
	if(b>MOD) b%=MOD;
	ll ans=(a*b)%MOD;
	if(ans<0) ans+=MOD;
	return ans;
}
ll pw(ll a, ll b)
{
	ll r=1;
	while(b){
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}

void solve(){
    ll n;
    cin>>n;
    ll ans=0;
    ll arr[n];
    ll sm[n];
    ll sum=0;
    for(int i = 0 ; i < n ; i++){
        cin>>arr[i];
        sum = add(sum, arr[i]);
        sm[i] = sum;
    }
    for(int  i = 0 ;  i < n ; i++){
        ans=add(ans, mult(sm[n-1]-sm[i],arr[i]));
        ans %= MOD;
    }
    ans %= MOD;
    cout<<ans<<endl;
}

int main(){
    fast_io;
    ll t, k=0;
    t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}



Measured memory_bytes: 6772
s = [input() for _ in range(int(input()))]
a = b = ab = ans = 0
for si in s:
    for j in range(len(si)-1):
        if si[j] == "A" and si[j+1] == "B":
            ans += 1
    if si[0] == "B" and si[-1] == "A":
        ab += 1
    elif si[0] == "B":
        b += 1
    elif si[-1] == "A":
        a += 1
print(ans + max(ab-1, 0)) if a == b == 0 else print(ans + ab + min(a, b))

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
string st,st1;
int main()
{
    cin>>st>>st1;
    for(int i=0;i<3;i++)
        if(st[i]!=st1[2-i])
        {
            cout<<"NO"<<endl;
            return 0;
        }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;

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

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

struct Union_find {
	int par[200010]; //親
	int siz[200010]; //根ノードiの木に含まれる要素数。iが根ノード出ない場合無意味な値となる。

	//n要素で初期化
	Union_find(int n) {
		for(int i = 0;i < n;i++) {
			par[i] = i;
			siz[i] = 1;
		}
	}

	//木の根を求める
	int find(int x) {
		if(par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//ｘとｙの属する集合を併合
	void unite(int x,int y) {
		x = find(x);
		y = find(y);
		if(x == y) {
			return;
		}
		if(siz[x] < siz[y]) {
			swap(x,y);
		}
		par[y] = x;
		siz[x] += siz[y];
	}

	//ｘとｙが同じ集合に属するか否か
	bool same(int x,int y) {
		return find(x) == find(y);
	}

	int size(int x) {
		return siz[find(x)];
	}
};

int main() {
    int N,M;
    cin >> N >> M;
    Union_find uf(N);
    for(int i = 0;i < M;i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        uf.unite(A,B);
    }
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        vec.at(uf.find(i))++;
    }
    int ret = 0;
    for(int i = 0;i < N;i++) {
        chmax(ret,vec.at(i));
    }
    cout << ret << endl;
}

Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
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; }
ll MOD = 1000000007;

int main(){
  ll sum = 0;
  while(1){
    char n;
    cin >> n;
    if(cin.eof()){
      break;
    }
    int N = n - 48;
    sum += N;
  }
  if(sum % 9 == 0){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
      if(a.equals("Sunny")){
            System.out.println("Cloudy");
      }else if(a.equals("Cloudy")){
            System.out.println("Rainy");
      }else if(a.equals("Rainy")){
        System.out.println("Sunny");
      }
    }
}

Measured memory_bytes: 21204
#include<iostream>

using namespace std;

int data[11];
int sum=0;
bool input(){
	fill(data,data+11,0);
	char c;
	int x;
	for(int i=1;i<=10;i++){
		if(!(cin>>x))return false;
		cin>>c;
		data[i]=data[i-1]+x;
	}
	return true;
}
int main(){
	while(input()){
		int v1,v2;
		char c;
		cin>>v1>>c>>v2;
		double t=1.*data[10]/(v1+v2);
		
		for(int i=1;i<=10;i++){
			if(v1*t<=data[i]){
				cout<<i<<endl;
				break;
			}
		}
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
const double INF=1000000000000000.0;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}

int main(){
	ll N; cin>>N;
    vector<ll> L(N+1,0); 
    rep(i,N){
        ll tmp; cin>>tmp;
        if(L[tmp-1]==0) L[tmp]=1;
        else L[tmp]=L[tmp-1]+1;
    }
    ll ans=0;
    rep1(i,N){
        chmax(ans,L[i]);
    }
    cout<<N-ans;
}

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

int main(){

    string a,b;
    cin >> a >>b;

    if(a.size()>b.size()){
        cout << "GREATER" << endl;
    }else if(a.size()<b.size()){
        cout << "LESS" << endl;
    }else{
        for(int i=0;i<a.size();i++){
            if(a[i]-b[i]==0){
                if(i==a.size()-1){
                    cout << "EQUAL" << endl;
                }
                continue;
            }else if(a[i]-b[i]>0){
                cout << "GREATER" << endl;
                break;
            }else{
                cout << "LESS" << endl;
                break;
            }
        }
    }

    return 0;
}

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


int main(){

 int healthT,strT,healthA,strA;	
  scanf("%d%d%d%d",&healthT,&strT,&healthA,&strA);
  
  while(healthT>0 && healthA>0){
  	healthA-=strT;
  	healthT-=strA;
  }
  
  if(healthA<=0)
  	printf("Yes\n");
  else if(healthT<=0)
  	printf("No\n");	
  
 return 0;
}



Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,M=0;
 cin >> N;
 vector<int> vec1(N);
 vector<int> vec2(N, 0);
 vector<int> vec3(N, 0);
 for(int i = 0; N > i; i++){
   cin >> vec1.at(i);
}
for(int i = 0; N-1 > i; i++){
  if (vec1.at(i) >= vec1.at(i+1)){
    vec2.at(i) = 'T';
  }
  else{
    vec2.at(i) = 'F';
  }
}
  for(int i = 0; N > i; i++){
    if(vec2.at(i) == 'T'){
      M ++;
    }
    else{
      vec3.at(i) = M;
      M = 0;
    }
  }
    sort(vec3.begin(), vec3.end());
    cout << vec3.at(N-1) <<endl;
}


Measured memory_bytes: 1408
def resolve():
    N = int(input())
    Ws = list(map(int, input().split(" ")))
    sumall = sum(Ws)
    wmin = float('inf')
    for i in range(1, N):
        S1 = sum(Ws[:i])
        S2 = sum(Ws[i:])
        diff = abs(S1 - S2)
        if wmin > diff:
            wmin = diff
    print(wmin)


if '__main__' == __name__:
    resolve()

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

int main() {

    int H, W, N;
    cin >> H >> W >> N;

    int ans = 0;
    int line = max(H, W);
    while (ans * line < N) {
        ans++;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int>l(n);
    for(int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int ans = 0;
    for(int i = n - k; i < n; i++)
    {
        ans += l[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split("\\s");
        Stack<Integer> q = new Stack<Integer>();
        for (int i = 0; i < str.length; i++) {
            if (str[i].equals("+")) {
                q.add(q.pop() + q.pop());
                continue;
            }
            if (str[i].equals("-")) {
		int a1 = q.pop();
		int a2 = q.pop();
                q.add(a2 - a1);
                continue;
            }
            if (str[i].equals("*")) {
                q.add(q.pop() * q.pop());
                continue;
            }
            q.push(Integer.parseInt(str[i]));
        }
        System.out.println(q.pop());
    }
}



Measured memory_bytes: 24376
#include<bits/stdc++.h>
 
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
using namespace std;
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

vector<PII> G[100000];
int x_pos[100000];
bool ok[100000];

void add_node(int x, int y, int d){
    G[x].PB(MP(y, d));
    G[y].PB(MP(x, -d));
}

bool dfs(int idx, int prev){
    ok[idx] = true;
    REP(i, G[idx].size()){
        int next = G[idx][i].first;
        int mv = G[idx][i].second;
        if(next == prev) continue;
        if(x_pos[next] == -INF){
            x_pos[next] = x_pos[idx] + mv;
            if(!dfs(next, idx)){
                return false;
            }
        }else if(x_pos[next] != x_pos[idx] + mv){
            return false;
        }
    }

    return true;
}

int main(){
    int N, M;
    cin >> N >> M;
    REP(i, N){
        ok[i] = false;
        x_pos[i] = -INF;
    }
    REP(i, M){
        int x, y, d;
        cin >> x >> y >> d;
        add_node(x-1, y-1, d);
    }

    REP(i, N){
        if(ok[i]) continue;
        x_pos[i] = 0;
        if(!dfs(i, -1)){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
}


Measured memory_bytes: 13056
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,K;
cin>>N>>K;
int ans;
if(N%K==0)ans=0;
else ans=1;
cout<<ans<<endl;

//system("pause");
return 0;
}

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

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        v: [i64; n]
    }
    let m = v.iter().clone().sum::<i64>();
    let mut d = (v[0] * n as i64 - m).abs();
    let mut ans = 0;
    for i in 1..n {
        let dt = (v[i] * n as i64 - m).abs();
        if d > dt {
            d = dt;
            ans = i;
        }
    }
    println!("{}", ans);
}


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

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

int n, k;
ld ans;

int LOG(int a) {
	int res = 0;
	for (; a < k;)
		res++, a <<= 1;
	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		ans += pow(2, -LOG(i));
	cout << fixed << setprecision(10) << ans / n;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  for(int i = 0; i < N; i++)
    cin >> A.at(i);
  for(int i = 0; i < N; i++)
    cin >> B.at(i);
  for(int i = 0; i < N; i++)
    cin >> C.at(i);
  int ans = 0;
  for(int i = 0; i < N; i++) {
    ans += B.at(i);
  }
  for(int i = 0; i < N - 1; i++) {
    if (A.at(i) == A.at(i + 1) - 1) {
      ans += C.at(A.at(i) - 1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;


ll a[200010];


ll l[35];

ll power(ll m, ll n){

    l[0]=m;
    for(ll i=1; i<35; i++){
        l[i] = (l[i-1]*l[i-1]) % MOD;
    }
    /*
    rep(i,35){
        cout << l[i] << " ";
    }
    cout << endl;
    */

    ll tmp = n;
    ll ans = 1;
    rep(i,35){
        if(tmp%2==1){
            ans = (ans*l[i]) % MOD;
        }
        tmp /= 2;
        //cout << ans << " ";
    }
    //cout << endl;
    return ans%MOD;

}


void solve(){

    ll n;
    cin >> n;
    ll s = 0;
    rep(i,n){
        cin >> a[i];
        s = (s + a[i])%MOD;
    }
    ll all=0;
    all = (s*s)%MOD;
    rep(i,n){
        all = (all - (a[i]*a[i])%MOD + MOD) % MOD;
    }

    ll x = power(2, MOD-2);
    cout << (all*x)%MOD << endl;

}

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


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

int A, B, C, K;
cin >> A >> B >> C >> K;

bool ans = false;

for (int i = 0; i < K; i++){
    if(B <= A){
        B = B * 2;
    }
    else{
        C = C * 2;
    }
}

if(A < B && B < C){
    ans = true;
}

if(ans == false){
    cout << "No" << endl;
}
else{
    cout << "Yes" << endl;
}

return 0;
}

Measured memory_bytes: 3620
use std::io::{self, Read};
use std::str::FromStr;
pub struct Scanner<R: Read> {
    reader: R,
}
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok().expect("failed to parse token")
    }
}

fn main() {
    let sin = io::stdin();
    let sin = sin.lock();
    let mut sc = Scanner::new(sin);

    let q: usize = sc.read();
    let len: usize = q;
    let mut deque: Vec<i64> = vec![0; len];

    // head>tailで空
    // deque[head]がDequeの先頭、deque[tail]がDequeの末尾を指す
    let mut head = len/2;
    let mut tail = head-1;

    // 満杯にならないと仮定して、このチェックは外している
    
    for _ in 0..q {
        let com: u32 = sc.read();
        match com {
            0 => {  // push
                let com2: u32 = sc.read();
                match com2 {
                    0 => {  // to head
                        head = (head - 1 + len) % len;
                        deque[head] = sc.read();
                    },
                    1 => {  // to tail
                        tail = (tail + 1) % len;
                        deque[tail] = sc.read();
                    },
                    _ => {
                        panic!("irregular command2");
                    },
                }
            },
            1 => {  // random
                let p: usize = sc.read();
                let p =  (head + p) % len;
                println!("{}", deque[p]);
            },
            2 => {  // pop
                let com2: u32 = sc.read();
                match com2 {
                    0 => {  // from head
                        head = (head + 1) % len;
                    },
                    1 => {  // from tail
                        tail = (tail - 1 + len) % len;
                    },
                    _ => {
                        panic!("irregular command2");
                    },
                }
            },
            _ => {
                panic!("irregular command");
            },
        }
    }
}



Measured memory_bytes: 9124
#include <cstdio>

int s_to_num(char c){
	if(c == 'S'){return 0;}
	if(c == 'H'){return 1;}
	if(c == 'C'){return 2;}
	if(c == 'D'){return 3;}
	else return -1;
}

char num_to_s(int i){
	char r[]={'S','H','C','D'};
	return r[i];
}

int main(){
	unsigned n,r;
	char s;
	bool isExist[4][13];

	for(int i=0;i<4;i++){
		for(int j=0;j<13;j++){
			isExist[i][j]=false;
		}
	}

	scanf("%u",&n);
	for(int i=0;i<n;i++){
		scanf("\n%c %u",&s,&r);
		isExist[s_to_num(s)][r-1]=true;
	}

	for(int i=0;i<4;i++){
		for(int j=0;j<13;j++){
			if(!isExist[i][j]){printf("%c %d\n",num_to_s(i),j+1);}
		}
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

set<int>bad;
ll mem[MAXN];

ll solve( ll n )
{
    if( n == 0 )
        return 1;

    if( bad.count(n) )
        return 0;

    ll &ans = mem[n];
    if( ans != -1 )
        return ans;
    ll a1 = solve(n-1);
    ll a2 = solve(n-2);
    ans = a1+a2;
    mod(ans);
    return ans;
}

int main() 
{
    fastio();

    memset(mem,-1,sizeof(mem));

    int n,m;
    cin>>n>>m;

    for(int i=0;i<m;i++)
    {
        int x;
        cin>>x;
        bad.insert(x);
    }

    ll ans = solve(n);
    cout<<ans,nl;


    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  double ans=0;
  
  for(int i=0;i<N;i++){
  	double x; string y;
    cin >> x >> y;
    
    if(y=="JPY"){
       ans+=x;
    	}
  	else{
      ans+=(x*380000.0);
  	}
  
  
   
  
  }
  cout << ans << endl;
}


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

int main() {
  int n;cin>>n;
  vector<int> a(n);
  ll cnt=0;
  int mod=1e9+7;
  rep(i,n){
    cin>>a[i];
    cnt+=a[i];
    cnt%=mod;
  }
  ll ans=0;
  rep(i,n){
    cnt-=a[i];
    if(cnt<0)cnt+=mod;
    ans+=a[i]*cnt;
    ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string S,left,right;
  cin>>N>>S;
  stack<char> brackets;
  for (int i = 0; i < N; i++) {
    if (S[i] == '(') {
      brackets.push('(');
    } else if (brackets.empty()) {
      brackets.push(')');
    } else {
      if (brackets.top() == '(') {
        brackets.pop();
      } else {
        brackets.push(')');
      }
    }
  }
  while (!brackets.empty()) {
    if (brackets.top() == '(') {
      right.push_back(')');
    } else {
      left.push_back('(');
    }
    brackets.pop();
  }
  cout<<left<<S<<right;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sp pair<string,string>

int N;
string S;
unordered_map<string,int> mp;

void dfs1(string r, string b, int idx){
    if(idx == N){
        mp[r + ' ' + b]++;
    }else{
        dfs1(r + S[idx], b, idx + 1);
        dfs1(r, b + S[idx], idx + 1);
    }
}

ll dfs2(string r, string b, int idx){
    if(idx == N - 1){
        return mp[r + ' ' + b];
    }else{
        return dfs2(r + S[idx], b, idx - 1) + dfs2(r, b + S[idx], idx - 1);
    }
}

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

    dfs1("", "", 0);
    cout << dfs2("", "", 2 * N - 1) << endl;
    return 0;
}

Measured memory_bytes: 70900
#include<iostream>
using namespace std;
int main(){
	char a[19];
	for( int i=0;i<19;i++)
		cin>>a[i];
	 for( int i=0;i<19;i++){
			if(((a[i]==',')&&(i==5))||((a[i]==',')&&(i==13))){
			
			cout<<" ";
			continue;}
			cout<<a[i];}
		return 0;
	}

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

int main()
{
	int n;
	cin >> n;
	double r = 0.0;
	for (int i = 0; i < n; ++i) {
		string s;
		double d;
		cin >> d >> s;
		if (s[0] == 'B') {
			r += d * 380000.0;
		}
		else {
			r += d;
		}
	}


	cout << r << endl;
	return 0;
}

Measured memory_bytes: 256
// C++(Clang 10.0.0)

//GCC用 ナゾです
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <math.h>
#include <time.h>   //srand((unsigned int)time(NULL));
#include <unistd.h> //sleep
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <unordered_map>
#include <set>
#include <cassert> //assart(x>=0) -> x<0の時異常終了
#include <numeric>
#include <iterator>
#include <list>
#include <tuple>
#include <queue>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(ll i=(min);i<(max);i++)
#define FOReq(i,min,max) for(ll i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(ll i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(ll i=(max);i>=(min);i--)

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

const int MOD=1e9+7;
const int MOD2=998244353;
const int not0=1;
const int INF=2000000001;
const ll INFll=2e18;
//const int MAX_V=10000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INFll || MOD2 || not0){;}
    return 0;
}

#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
//#define br printf("\n");
#define br cout<<"\n";
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}
#define elif else if

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
#define isdiff5(a,b,c,d,e) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c) and (e)!=(a) and (e)!=(b) and (e)!=(c) and (e)!=(d))
#define Func3(f,a,b,c) (f)((f)((a),(b)),(c))
#define Func4(f,a,b,c,d) (f)((f)((f)((a),(b)),(c)),(d))

inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll samepair(ll x){return x*(x-1)/2;}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！
//inline ll  ceil(double a){return (ll)a+1;}
//ans = accumulate(A, A+N, 0, [](int a, int b) {return gcd(a,b);});
//auto count = std::count_if(v.begin(), v.end(), [](int x) { return x == 1 || x == 3; } );

ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

//累積和　しゃくとり法　木構造　DP キュー　乱択アルゴリズム　嘘解法　ハッシュ　next_permulation

//課題：DP 木構造　Xor

ll probNow(){
    ll ans;ans=INF;
    ll N;
    cin>>N;
    deque<ll> dq{1,2,3,4,5,6,7,8,9};
    
    ll num=0;
    FOR(i, 0, N){
        num=dq.front();
        dq.pop_front();
        ll temp;
        temp= num%10;
        if(temp!=0)dq.push_back(10*num+temp-1);
        dq.push_back(10*num+temp);
        if(temp!=9)dq.push_back(10*num+temp+1);
    }
    
    
    OutputAndReturn0(num);
    return 0;
}

signed main(){
    cin.tie(0);    //cinとcoutの結び付き解除（cout時にcinの内容を吐き出さなくなる）
    ios::sync_with_stdio(false);  //coutとprintfの結び付き解除（coutとprintfを同時に使うな！）
    probNow();
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <queue>
#include <functional>
#include <iso646.h>
#include <bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main()
{
	ll N;
	cin >> N;
	vll A;
	ll i, j;
	for (i = 0; i < N; i++)
	{
		ll a;
		cin >> a;
		A.push_back(a);
	}
	vll H(N, 0);
	for (i = N - 1; i >= 0; i--)
	{
		ll p = i + 1 - A[i];
		if (p >= 0)
		{
			H[p]++;
		}
	}
	ll ans = 0;
	for (i = 0; i < N; i++)
	{
		ll q = i + A[i] + 1;
		if (q < N)
		{
			ans += H[q];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5992
n, k, q = map(int, input().split(' '))
p_list = [int(input()) for _ in range(q)]
scores = [k for _ in range(n)]
c_num = [0 for _ in range(n)]

if k > q:
    for _ in range(n):
        print('Yes')
else:
    for p in p_list:
        c_num[p-1] += 1
    for i in range(len(scores)):
        scores[i] -= q - c_num[i]
    for s in scores:
        if s > 0:
            print('Yes')
        else:
            print('No')

Measured memory_bytes: 12572
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}

int main(){
    //std::stack<int> stack;
    long double a,b;
    cin >> a >> b;
    long long ans = a*b;
    cout << ans << endl;
    return 0;
}





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

int main()
{
    ll n, sum = 0;
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            sum += i;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636