akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);

        String s;
        char schar[] = new char[10];

        s = sc.next();
        
        for (int i = 0; i < s.length(); i++) {
            schar[i] = s.charAt(i);
        }

        char schar_out[] = new char[s.length()];
        int j = 0;
        for (int i = 0; i < s.length(); i++) {
            if (schar[i] == 'B') {
                if (j != 0) {
                    j--;
                    schar_out[j] = '\0';
                }
            } else {
                schar_out[j] = schar[i];
                j++;
            }

        }
        
        String sstring_out = new String(schar_out);
        out.println(sstring_out.trim());
        sc.close();
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <stack>

using namespace std;
static const int dx[8] = {-1,0,1,-1,1,-1,0,1}, dy[8] = {-1,-1,-1,0,0,1,1,1};

int main(){
  int A,B,imax;
  char a[100][100];
  cin >> A >> B;
  int maxs = max(A,B);
  for(int i=1;i<24;++i){
    if(maxs <= (i*i)){
      imax = i;
      break;
    }
  }
  int Bcount = B-1;
  int Acount = A-1;

  for(int i=0;i<imax*4;i++){
    for(int j=0;j<imax*2;j++){
      if(i<imax*2){
        if(i%2==0 && j%2==0 && Bcount != 0){
          --Bcount;
          a[i][j] = '#';
        }else{
          a[i][j] = '.';
        }
      }else{
        if(i%2==1 && j%2==0 && Acount != 0){
          --Acount;
          a[i][j] = '.';
        }else{
          a[i][j] = '#';
        }
      }
    }
  }
  
  cout << imax*4 << " " << imax*2 << endl;
  for(int i=0;i<imax*4;i++){
    for(int j=0;j<imax*2;j++){
      cout << a[i][j];
    }
    cout << endl;
  }

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, i, ret, min, max;
    double sum;
    double arr[10000];

    ret = scanf("%d", &n);
    if (ret == 1) {

        for(i = 0; i < n; i++){
            scanf("%lf", &arr[i]);
        }
    }

    for(i = 0; i < n; i++)
        if(i == 0){
            min = arr[i];
            max = arr[i];
            sum = arr[i];
        } else if(i != 0) {
            if(min > arr[i]) {
                min = arr[i];
            }
            if(max < arr[i]) {
                max = arr[i];
            }
            sum = sum + arr[i];
        }
    printf("%d %d %.lf\n", min, max, sum);

    return 0;
}

Measured memory_bytes: 740
a, b, c, k = list(map(int, input().split(' ')))
result = 0

if a > k:
    result += k
    k -= k
else:
    result += a
    k -= a

if k > 0:
    if b > k:
        k -= k
    else:
        k -= b
    if c > k:
        result -= k
        k -= k
    else:
        result -= c
        k -= c

print(result)

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

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 60; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}
long long Div(long long a, long long b, long long m) {
	return (a*modpow(b, m - 2, m)) % m;
}

long long inv[2009], mod = 1000000007;

void init() {
	for (int i = 1; i <= 2008; i++) inv[i] = Div(1, i, mod);
}

long long ncr(long long n, long long r) {
	if (r < 0 || n < r) return 0;
	long long ret = 1;
	for (long long i = n; i > n - r; i--) { ret *= (i%mod); ret %= mod; }
	for (long long i = r; i >= 1; i--) { ret *= inv[i]; ret %= mod; }
	return ret;
}

long long dp[2009][2009];

long long solve(long long N, long long D, long long LIM) {
	if (LIM == 0) {
		if (N == 0) return 1;
		return 0;
	}
	for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) dp[i][j] = 0; }
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		long long S = 0;
		for (int j = 1; j <= N; j++) {
			S += dp[i - 1][j - 1];
			dp[i][j] = S%mod;
			if (j - LIM >= 0) S -= dp[i - 1][j - LIM];
		}
	}
	long long sum = 0;
	for (int i = 0; i <= N; i++) sum += (ncr(D, i)*dp[i][N]) % mod;
	return sum%mod;
}

int main() {
	long long A, B, C; init();
	while (true) {
		cin >> A >> B >> C; if (A + B + C == 0) break;
		cout << solve(A, B, C - 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 34488
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int Q = scan.nextInt();
        long[] s = new long[A+1];
        for (int i = 0; i < A; i++) {
            s[i] = scan.nextLong();
        }
        s[A] = 10000000010L;
        long[] t = new long[B+1];
        for (int i = 0; i < B; i++) {
            t[i] = scan.nextLong();
        }
        t[B] = 10000000010L;
        for (int i = 0; i < Q; i++) {
            long start = scan.nextLong();
            long distance = Long.MAX_VALUE;
            distance = Math.min(distance, first_move(start, s, A, t, B));
            distance = Math.min(distance, first_move(start, t, B, s, A));
            System.out.println(distance);
        }
    }
    private long first_move(long start, long[] s, long A, long[] t, long B) {
        int result = Arrays.binarySearch(s, start);
        int index = 0 <= result ? result : ~result;
        long distance = Long.MAX_VALUE;
        for (int j = Math.max(index - 1, 0); j < Math.min(index + 2, A); j++) {
            distance = Math.min(distance, second_move(start, s, j, t, B));
        }
        return distance;
    }
    private long second_move(long start, long[] s, int position, long[] t, long N) {
        int result = Arrays.binarySearch(t, s[position]);
        int index = 0 <= result ? result : ~result;
        long distance = Long.MAX_VALUE;
        long from_start = Math.abs(start - s[position]);
        for (int i = Math.max(index - 1, 0); i < Math.min(index + 2, N); i++) {
            long temp = from_start + Math.abs(s[position]-t[i]);
            distance = Math.min(distance, temp);
        }
        return distance;
    }
}


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

using namespace std;
int main(){
    int h,w;

    while(1){
        cin >> h >> w;
        if(h == 0 && w == 0){
            break;
        }else{
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if((i + j) % 2 == 0){
                        cout << "#" << flush;
                    }else{
                        cout << "." << flush;
                    }
                }
                cout << endl;
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int A, B;
	cin >> A >> B;
	if (max(A, B) > 9) puts("-1");
	else cout << A * B << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
 
r,g,b=0,0,0

for i in range(N):
    if S[i] == 'R':
        r = r+1
    else:
      if S[i] == 'G':
        g = g+1
      else:
        b = b+1
        
n = (N+1)//2
  
remove = 0
for i in range(1,n+1):
    for j in range(N-2*i):
        if S[j] != S[j+i] and S[j+i] != S[j+2*i] and S[j] != S[j+2*i]:
            remove = remove+1
            
print(r*g*b-remove)

Measured memory_bytes: 9212
import math
list = input().split()

a = int(list[0])
b = int(list[1])
x = int(list[2])

if a*a*b/2 - x > 0:
  theta = math.degrees(math.atan(( 2 * x ) / ( a*b*b )))
  ans = 90 - theta
else:
  ans = math.degrees(math.atan( 2 * ( a*a*b - x ) / ( a**3  )))

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string.h>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    long int n;
    cin >> n;
    int k = log10(n) + 1;
    int a[k];
    for(int i = 0; i < k; i++){
        a[k-i-1] = n % 10;
        n = n/10; 
    }
    int ans = 1000;
    for(int i = 0; i < k - 2; i++){
        if(ans >= abs(753-(a[i]*100 + a[i+1]*10 + a[i+2]))){
            ans = abs(753-(a[i]*100 + a[i+1]*10 + a[i+2]));
        }
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

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

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

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

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

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

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        void Omame()
        {
            cin = new Scanner();
            long N = cin.nextLong();
            string S = cin.next();
            string T = cin.next();
            string ans = "";
            for (int i = 0; i < N; i++)
            {
                ans += S[i];
                ans += T[i];
            }

            Console.WriteLine(ans);
        }
    }
}


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

#define ll long long int

using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> X(n), Y(n), H(n);
    for (ll i = 0; i < n; ++i) {
        cin >> X[i] >> Y[i] >>H[i];
    }

    ll cx = -1, cy = -1, h = -1;

    for (ll i = 0; i <= 100; ++i) {
        bool gok = false;
        for (ll j = 0; j <= 100; ++j) {
            ll tmpH;
            bool ok = true;
            bool firstOne = true;

            for (ll k = 0; k < n; ++k) {
                if (H[k] == 0) continue;
                if (firstOne) {
                    tmpH = H[k] + abs(X[k]-i) + abs(Y[k]-j);
                    firstOne = false;
                } else {
                    if (tmpH != H[k] + abs(X[k]-i) + abs(Y[k]-j)) {
                        ok = false;
                        break;
                    }
                }
            }

            if (!ok) continue;

            for (ll k = 0; k < n; ++k) {
                if (H[k] > 0) continue;
                if (tmpH > abs(X[k]-i) + abs(Y[k]-j)) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                cx = i;
                cy = j;
                h = tmpH;
                gok = true;
            }
        }
        if (gok) break;
    }

    cout << cx << " " << cy << " " << h << endl;
}



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

struct Rectangle {
  int height;
  int pos;
};
 

#include <stdio.h>
#define SIZ 1400
int m[SIZ+1][SIZ+1];
int st[SIZ];
char z[9999999];
int get(){
	static int input_count=0;
	int r=0;
	for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0';
	input_count++;
	return r;
}
int main(){
	fread(z,1,sizeof(z),stdin);
	int i,j,k,y=get(),x=get(),r,ptr;
	for(j=0;j<y;j++)for(r=i=0;i<x;m[j][i]=r,i++){
		int t=get();
		r=t==0?r+1:0;
	}
	r=0;
/*
	for(i=0;i<x;i++)for(ptr=j=0;j<=y;j++){
		//printf("%d %d %d %d\n",i,j,ptr,m[j][i]);
		if(!ptr || st[ptr-1]<m[j][i])st[ptr++]=m[j][i];
		else{
			for(;ptr && st[ptr-1]>m[j][i];){
				int _y=(j-(ptr-1)),_x=st[--ptr];
				//printf("%d %d\n",_x,_y);
				if(r<_x*_y)r=_x*_y;
			}
			st[ptr++]=m[j][i];
		}
	}
*/
	Rectangle rect;
	for(int i=0;i<x;i++){
		stack<Rectangle> stk;
		rect.height = 0;
		rect.pos = 0;
		stk.push(rect);
		int pop=0;
		for(int j=0;j<=y;j++){
			rect.height = m[j][i];
			rect.pos = j;
			if(stk.empty() || stk.top().height < rect.height){
				stk.push(rect);
			}else{
				//printf("[-] %d %d\n",i,j);
				for(;!stk.empty() && stk.top().height >= rect.height;){
					pop++;
					Rectangle pre = stk.top(); stk.pop();
					//pre.pos=stk
					int area = pre.height * (j - pre.pos);
					r = max(r, area);
					//printf("%d %d\n",target,pre.pos);
					rect.pos = pre.pos;
				}
				stk.push(rect);
			}
			if(rect.height==0)pop=0;
		}
	}

	printf("%d\n",r);
	return 0;
}

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

int main() {
  int a,count=1;
  cin>>a;
  string b;
  cin>>b;
  
  for(int i=0;i<a-1;i++){
    if(b.at(i)!=b.at(i+1)){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,f=0;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b && a!=c) f = 1;
    else if(a==c && a!=b) f = 1;
    else if(b==c && a!=c) f = 1;
    if(f)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;
constexpr ll modsize = 500010;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
	if (modsize == 0) abort();
	fac[0] = 1; fac[1] = 1; inv[1] = 1;
	facinv[0] = 1; facinv[1] = 1;
	for (ll i = 2; i < modsize; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		facinv[i] = facinv[i - 1] * inv[i] % mod;
	}
}

ll modinv(ll a) {
	if (a == 0) abort();
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

ll modpow(ll a, ll b) {
	ll ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[n - k] % mod;
}

ll modhom(ll n, ll k) {
	if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
	if (n == 0 && k == 0) return 1;
	return fac[n + k - 1] * facinv[k] % mod * facinv[n - 1] % mod;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	modcalc();

	ll n, m;
	cin >> n >> m;
	ll ans = 0;
	rep(i, n + 1) {
		if (i & 1) ans -= modperm(m - i, n - i)*modcomb(n, i) % mod;
		else ans += modperm(m - i, n - i)*modcomb(n, i) % mod;
	}
	ans %= mod; if (ans < 0) ans += mod;
	cout << ans * modperm(m, n) % mod << '\n';
}

Measured memory_bytes: 15056
#include<stdio.h>

int main(){

	int n,x=0;
	int max = 0;
	scanf("%d",&n);
	char arr[n];
	
	for(int i=0;i<=n;i++){
		scanf("%c",&arr[i]);
		if(arr[i] == 'I'){
			x++;
		}
		else if(arr[i] == 'D'){
			x--;
		}
		
		
		if(x >= max){
			max = x;
		}
	}

printf("%d",max);

	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    string abcd;
    int a;
    int b;
    int c;
    int d;
    cin >> abcd;
    a = abcd[0]-'0';
    b = abcd[1]-'0';
    c = abcd[2]-'0';
    d = abcd[3]-'0';

    if(a+b+c+d==7){
        cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
    }else if(a+b+c-d==7){
        cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;        
    }else if(a+b-c+d==7){
        cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;        
    }else if(a+b-c-d==7){
        cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;        
    }else if(a-b+c+d==7){
        cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;        
    }else if(a-b+c-d==7){
        cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;        
    }else if(a-b-c+d==7){
        cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;        
    }else if(a-b-c-d==7){
        cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;        
    }

}

Measured memory_bytes: 256
N, M = map(int, input().split())
edges = [input().split() for i in range(M)]
searched_edge = [0 for i in range(M)]
searched = [0 for i in range(N)]
stack = ['1']

count = 0
searched[0] = 1
def search(stack, searched, edges, searched_edge):
	global count
	
	while (stack):
		now = stack.pop()
		searched[int(now)-1] = 1
		
		if 0 not in searched:
			count += 1
			return
		
		for edge in edges:
			if now in edge:
				next = edge[1] if edge[0] == now else edge[0]
				searched_edge[edges.index(edge)] = 1
				if searched[int(next)-1] == 0:
					stack += [next]
					searched[int(next)-1] = 1
					search(stack, searched, edges, searched_edge)
					searched_edge[edges.index(edge)] = 0
					searched[int(next)-1] = 0

	return

search(stack, searched, edges, searched_edge)
print(count)

Measured memory_bytes: 3192
N = input()

def dfs(string, value, i):
    if len(string) ==2*len(N) -1:
        if value == 7:
            print(string + "=7")
            exit()
        return
    else:
        dfs(string + "+" + N[i+1], value + int(N[i+1]), i+1), dfs(string + "-"+ N[i+1], value - int(N[i+1]), i+1)
dfs(N[0], int(N[0]), 0)

Measured memory_bytes: 3064
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <unordered_map>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout << endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define o(x)		  cout << x << endl;
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll bS(ll l, ll r, ll x, vll arr) {
	while (l <= r) {
		ll m = l + (r - l) / 2;

		if (arr[m] == x)
			return m;

		if (arr[m] < x)
			l = m + 1;

		else
			r = m - 1;
	}

	return -1;
}

void primeFactors(ll n) {
	while (n % 2 == 0) {
		//cout << 2 << " ";
		n = n / 2;
	}

	for (ll i = 3; i <= sqrt(n); i += 2) {
		while (n % i == 0) {
			//cout << i << " ";
			n = n / i;
		}
	}

	if (n > 2)
		cout << n << " ";
}

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll n;
		cin >> n;
		if (n & 1) {
			o(0)
			return 0;
		}
		n /= 2;
		ll count = 0;
		for (ll i = 5; n / i >= 1; i *= 5)
			count += n / i;

		o(count)


	}
	CLOCK
	return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }

const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    long long r = 1;
    cin >> n;
    FOR(i,1,n+1){
        r *= i;
        r = r % int(1e9+7);
    }
    cout << r;
}


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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
   su;
   int n,m,c,a,sum,cnt=0;
   cin>>n>>m>>c;
   int b[m];
   lo(i,0,m)
   {
     cin>>b[i];
   }
   lo(i,0,n)
   {
     sum=c;
     lo(j,0,m)
     {
       cin>>a;
       sum+=(a*b[j]);
     }
     if(sum>0)
      cnt++;
   }
   cout<<cnt<<nl;
   return 0;
}


Measured memory_bytes: 3652
#include<cstdio>
const long long mod = 998244353;
long long f[8005], invf[8005];
long long pow2[8005];

long long power(long long a,long long b){
    long long res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

long long inv(long long u){ return power(u,mod-2); }

long long getComb(int n,int m){
    if(m>n || m<0) return 0;
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}

void preWork(int n){
    f[0] = invf[0] = pow2[0] = 1;
    for(long long i = 1; i <= n; i++){
        pow2[i] = pow2[i-1]*2ll%mod;
        f[i] = f[i-1]*i%mod;
        invf[i] = inv(f[i]);
    }
}

long long getDivide(int n,int m){
    return getComb(n-1,m-1);
}

long long getCount(int x,int y,int n){
    if(x>n) return 0;
    else{
        long long res = getDivide(n+y,x+y);
        return res;
    }
}

long long solve(int n,int k,int x){
    int left = k, pair = 0, one = 0;
    for(int i = 1; i <= k; i++){
        int j = x-i;
        if(j>=1 && j<=k && i<j){
            left -= 2;
            pair++;
        }
    }
    if(x%2==0) one = 1, left--;
    long long ans = 0;
    for(int i = 0; i <= pair; i++){
        if(!one){
            long long base = getCount(i,left,n);
            long long mul = getComb(pair,i)*pow2[i]%mod;
            base = base*mul%mod;
            ans = (ans+base)%mod;
        }
        else{
            long long add = getCount(i,left,n)*getComb(pair,i)%mod*pow2[i]%mod;
            add += getCount(i,left,n-1)*getComb(pair,i)%mod*pow2[i]%mod;
            if(add>mod) add -= mod;
            ans = (ans+add)%mod;
        }
    }
    return ans;
}

int main(){
    int n,k;
    scanf("%d%d",&k,&n);
    preWork(8001);
    //printf("%lld\n",solve(n,k,3));
    for(int i = 2; i <= 2*k; i++) printf("%lld\n",solve(n,k,i));
    return 0;
}


Measured memory_bytes: 1916
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <map>
#include <iomanip> 
#include <ctime>
#include <numeric>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<string, int> P;
typedef vector<vector<int>> Graph;

const double PI = 3.14159265358979323846;

const int mod = 1000000007;

int main(int argc, char *args[]) {
	ll n, a, b;
	cin >> n >> a >> b;
	ll sum = a + b;
	ll count = n / sum;
	ll r = n % sum;
	count *= a;
	if (a >= r) {
		count += r;
	}
	else {
		count += a;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
count = int(input())
point = {'taro': 0, 'hanako': 0}
for i in range(count):
    (taro, hanako) = [s for s in input().split()]
    if (taro > hanako) - (taro < hanako) == 0:
        point['taro'] += 1
        point['hanako'] += 1
    elif (taro > hanako) - (taro < hanako) > 0:
        point['taro'] += 3
    else:
        point['hanako'] += 3

print(point['taro'], point['hanako'])

Measured memory_bytes: 6724
from math import sqrt

def is_prime(n):
    m = int(sqrt(n))
    for q in range(2, m + 1):
        if n % q == 0:
            return False
    return True

def main():
    n = int(input())
    sum = 0
    for _ in range(n):
        x = int(input())
        if is_prime(x):
            sum += 1
    print(sum)


main()



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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long double w, h, x, y;
    cin >> w >> h >> x >> y;

    cout << w * h / 2 << "\n";

    if(x * 2 == w && y * 2 == h){
        cout << 1;
    } else {
        cout << 0;
    }

    return 0;
}


Measured memory_bytes: 256
def gi; gets.split.map(&:to_i); end
H,W=gi

as = H.times.map do
    gi
end

ret = []
H.times do |y|
    W.times do |x|
        a = as[y][x]
        if a.odd?
            if x < W-1
                ret << [y,x,y,x+1]
                as[y][x+1] += 1
            elsif x == W-1 && y < H-1
                ret << [y,x,y+1,x]
                as[y+1][x] += 1
            end
        end
        
    end
end

puts ret.length
ret.each do |l|
    puts l.map{|n|n+1}.join(' ')
end

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

int main(void) {

  long n;
  scanf("%ld", &n);
  long max = sqrt(n*2);
  long sum = max*(max+1)/2;
  while (sum < n) {
    max++;
    sum += max;
  }
  for (long i = 1; i <= max; i++) {
    if (sum-n == i) {
      continue;
    }
    printf("%ld\n", i);
  }

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void)
{
	int N;

	scanf("%d",&N);

	if(N<=111) printf("111");
	else if(N<=222) printf("222");
	else if(N<=333) printf("333");
	else if(N<=444) printf("444");
	else if(N<=555) printf("555");
	else if(N<=666) printf("666");
	else if(N<=777) printf("777");
	else if(N<=888) printf("888");
	else if(N<=999) printf("999");

	return 0;
}

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

int main() {
  
  int N, K;
  cin >> N >> K;
  
  vector<long long> x(N);
  for(int i=0; i<N; i++){ cin >> x[i]; }
  
  long long min=LLONG_MAX;
  long long tmin=0;
  for(int i=0; i<N-K+1; i++){
    if(x[i]>=0){ tmin = x[i+K-1]; }
    else if(x[i+K-1]<=0){ tmin = -x[i]; }
    else{
      tmin = std::min( 2*x[i+K-1]-x[i], x[i+K-1]-2*x[i] );
    }
    if(tmin<min){ min=tmin; }
  }
  
  cout << min << endl;
}



Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskD   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int M = in.nextInt();
        long s[] = new long[N+1];
        for (int i=0; i<N; i++) {
            s[i+1] = s[i] + in.nextLong();
        }
        long ans = 0;
        HashMap<Integer, Integer> hm = new HashMap<>();
        for (int i=1; i<=N; i++) {
            int yo = (int)(s[i] % M);
            if (yo == 0){
                if(!hm.containsKey(yo)){
                    hm.put(yo, 1);
                    ans+=1;
                }
                else {
                    int m = hm.get(yo);
                    hm.put(yo, m+1);
                    ans+=m+1;
                }
            }
            else{
                if(!hm.containsKey(yo)) hm.put(yo, 1);
                else {
                    int m = hm.get(yo);
                    hm.put(yo, m+1);
                    ans+=m;
                }
            }
        }
        out.println(ans);
    }

}
}



Measured memory_bytes: 59548
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var r = cin.ReadInt;
            WriteLine(3 * r * r);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

using namespace std;

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  if (n == 2) {
    cout << dp[1] << endl;
    return 0;
  }
  for (int i = 2; i < n; i++) {
    int tmp = dp[i - 1] + abs(h[i] - h[i - 1]);
    for (int j = 2; j <= min(i, k); j++) {
      tmp = min(tmp, dp[i - j] + abs(h[i] - h[i - j])); 
    } 
    dp[i] = tmp;
  }
  cout << dp.back() << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
    using namespace std;
    int main()
    {
      int n;
      std::cin >> n;
      int h[n];
      int b = 0; //カウント用
      int c = 0; //カウント用

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

      for (int i = 0; i < n-1; i++) {
        if (h[i] >= h[i+1]) {
          b++;
        }
        else {
          if (c < b) {
            c = b;
            b = 0;
          }
          else{
            b=0;
          }
        }
      }

      //最後の組が一番多かったとき用
      if (c < b) {
        c = b;
      }
      
      cout << c << '\n';
      return 0;
    }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}
void primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        cout << 2 << " ";  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            cout << i << " ";  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        cout << n << " ";  
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
   
    long long int n1,m1,t;
 //   cin>>t;
   t=1;
    while(t--)
    {
   long long int i,j;
 //long long int b[1000000];
 //set<long long int >s;
       long long int f=1,p=0,z,o=0;
       double pie=3.141592653589793238;
    long long int c=0,n,m,l=0,r=0,k,min1=10000000000000,max2=-100;
 cin>>n;
 
 long long int a[n];
 for(i=0;i<n;i++)
 cin>>a[i];
 sort(a,a+n);
 
 p=p+a[n-1];
      if(n==2)
        cout<<p;
      else
      {
		c=2;
   for(i=n-2;i>=0;i--)
 {
     if(n-c>=2)
     {p=p+2*a[i];
     c=c+2;}
     else if((n-c)==1)
     {
     p=p+a[i];
     c=n;
     break;}
     else
       break;
       
 }
   cout<<p;   }
 //cout<<p;
 }
 
 
 return 0;
}


Measured memory_bytes: 5252
main :: IO ()
main = do
    [n, a, b, c] <- map read.words <$> getLine
    ls <- map read.words <$> getContents
    print $ solve n a b c ls

solve :: Int -> Int -> Int -> Int -> [Int] -> Int
solve n a b c ls = minimum $ do
    gr <- mapM (const [0..3]) ls
    ga@(_:_) <- return . map snd . filter ((== 0).fst) $ zip gr ls
    gb@(_:_) <- return . map snd . filter ((== 1).fst) $ zip gr ls
    gc@(_:_) <- return . map snd . filter ((== 2).fst) $ zip gr ls
    let [la, lb, lc] =  map length [ga, gb, gc]
    let [sa, sb, sc] = map sum [ga, gb, gc]
    return $! (la + lb + lc - 3) * 10 + abs (sa - a) + abs (sb - b) + abs (sc - c)


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

using namespace std;



float simpleDistance(int dim, int v1[], int v2[]) {
    float res = 0.0;
    for (int i = 0; i < dim; ++i) {
        res += pow(v1[i]-v2[i],2);
    }
    return sqrt(res);
}

bool isIntDistance(int dim, int v1[], int v2[]) {
    float d = simpleDistance(dim, v1, v2);
    return abs(round(d) - d) < 0.00001;
}



int main() {

    // Input //

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

    int x[10][10];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> x[i][j];
        }
    }


    // Evaluate //

    int count = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            if (isIntDistance(d,x[i],x[j])) {
                count++;
            }
        }
    }


    // Output //

    cout << count << endl;

}




Measured memory_bytes: 512
N, M, *_ = map(int, open(0).read().split())

A = []
K_i = 0
for i in range(N):
    K = _[K_i]
    A.append(_[K_i+1 :  K_i+1+K])
    K_i += K + 1
    
ans = 0

for m in range(1, M+1):
    for k, a_i in enumerate(A, start=1):
        if m not in a_i:
            break
        if k == len(A):
            ans += 1

print(ans)

Measured memory_bytes: 9144
function main(input){
    let str = input;
    let low = "abcdefghijklmnopqrstuvwxyz";
    let up =  "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    let answer = "";
    for(let i=0;i<str.length;i++){
        let put = "";
        if(low.indexOf(str[i])!==-1){
            put=str[i].toUpperCase();

        }else if(up.indexOf(str[i])!==-1){
            put= str[i].toLowerCase();
        }else{
            put = str[i];
        }
        answer+=put;
    }
    console.log(answer.trim());

}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 16056
#include <stdio.h>

int main(void)
{
    int flag[3] = { 0, 0, 0 };
    flag[getchar() - 'a'] = 1;
    flag[getchar() - 'a'] = 1;
    flag[getchar() - 'a'] = 1;
    if (flag[0] && flag[1] && flag[2]) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<functional>
#include<cmath>
#include<algorithm>
#define INF 999999999
typedef  long long ll;
 
int main() {
	ll n = 0;
	ll f = 0;
	ll sa = 0, ans = INF;
	ll ar[100] = {};
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> ar[i];
	}
	f = ar[0];
	for (ll i = 1; i < n; i++) {
		if (f != ar[i]) {
			goto kiyomaru;
		}
	}
	std::cout << 0 << std::endl;
	return 0;
	kiyomaru:
	std::sort(ar, ar + n);
	for (ll i = ar[0]; i < ar[n - 1]; i++) {
		for (ll j = 0; j < n; j++) {
			sa +=(ar[j]-i)*(ar[j]-i);
		}
		ans = std::min(ans, sa);
		sa = 0;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
using namespace std;
using ll = long long;
using graph = std::vector<std::vector<long long>>;
int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll>l;
    vector<ll>r;
    for (int i = 0; i < N; ++i) {
        ll tmp;
        cin >> tmp;
        if(tmp < 0){
            l.push_back(tmp);
        }else{
            r.push_back(tmp);
        }
    }
    sort(l.begin(),l.end(),greater<ll>());
    sort(r.begin(),r.end());
    ll m = 1ll << 50;
    if(l.size() == 0){
        cout << r[K - 1] << endl;
        return 0;
    }
    if(r.size() == 0){
        cout << abs(l[K - 1]) << endl;
        return 0;
    }
    if(K == 1){
        cout <<min(abs(r[0]),abs(l[0])) << endl;
        return 0;
    }
    if(r.size() >= K){
        m = min(m,r[K - 1]);
    }
    if(l.size() >= K){
        m = min(m,abs(l[K - 1]));
    }
    for (ll i = 0; i < min((unsigned long)K,l.size()); ++i) {
        if(K - i - 1 <= r.size())
        m = min(m,abs(2 * l[i]) + abs(r[K - i - 2]));
    }
    for (ll i = 0; i < min((unsigned long)K,r.size()); ++i) {
        if(K - i - 1 <= l.size())
        m = min(m,abs(2 * r[i]) + abs(l[K - i - 2]));
    }
    cout << m << endl;
}

Measured memory_bytes: 1656
n=1<<18;N,m;L[1<<18],p;first[1<<18],next[1<<18];
long dat[1<<20],lazy[1<<20],A[1<<18],x;
eval(i,l,r){
	dat[i]+=lazy[i];
	lazy[2*i+1]+=lazy[i];
	lazy[2*i+2]+=lazy[i];
	lazy[i]=0;
}
long update(a,b,k,l,r){
	eval(k,l,r);
	return a<=l&r<=b?lazy[k]+=x,eval(k,l,r),dat[k]:l<b&a<r?dat[k]=fmax(
		update(a,b,2*k+1,l,(l+r)/2),
		update(a,b,2*k+2,(l+r)/2,r)
	):dat[k];
}
long query(a,b,k,l,r){
	eval(k,l,r);
	return a<=l&r<=b?dat[k]:l<b&a<r?fmax(
		query(a,b,2*k+1,l,(l+r)/2),
		query(a,b,2*k+2,(l+r)/2,r)
	):0;
}
main(i){
	for(scanf("%d%d",&N,&m);~scanf("%d%d%ld",L+i,&p,A+i);first[p]=i++)next[i]=first[p];
	for(i=1;i<=N;i++){
		x=query(0,i,0,0,n);
		update(i,i+1,0,0,n);
		for(p=first[i];p!=0;p=next[p]){
			x=A[p];
			update(L[p],i+1,0,0,n);
		}
	}
	printf("%ld",query(0,N+1,0,0,n));
}

Measured memory_bytes: 18944
/*
 * 2019年  2月 25日 月曜日 12:20:59 JST
 */

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

std::vector<std::string> split(std::string str, std::string sep){
  std::vector<std::string> res;
  size_t begin = 0;
  while(1){
    size_t pos = str.find(sep, begin);
    if(pos == std::string::npos) break;
    res.push_back( str.substr(begin, pos-begin) );
    begin = pos + sep.size();
  }
  res.push_back( str.substr(begin, str.length() - begin) );
  return res;
}

bool calc(int y, int m, int  d){
  const bool Heisei = true;
  const bool TBD = false;
  if(y > 2019){
    return TBD;
  }else if(y == 2019){
    if(m > 4) {
      return TBD;
    }else if(m == 4){
      if(d > 30){
        return TBD;
      }else{
        return Heisei;
      }
    }else{ //m < 4
      return Heisei;
    }
  }else{ // y < 2019
    return Heisei;
  }
}

int main(void){
  string S; cin >> S;
  vector<string> ymd = split(S, "/");
  int y = atoi(ymd[0].c_str());
  int m = atoi(ymd[1].c_str());
  int d = atoi(ymd[2].c_str());

  if(calc(y, m, d) == true){
    cout << "Heisei" << endl;
  }else{
    cout << "TBD" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
// #define double long double
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N   100005
#define MAX 300005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcountll
#define PI acos(-1)
//#define endl "\n"
#define inf 1e+15
int dp[N],b[N]={0};
signed main(){
  fast;
  int n,m,x;
  cin>>n>>m;
  for(int i=0;i<m;i++) cin>>x,b[x]=1;
  dp[0]=1;
  for(int i=1;i<=n;i++){
  	   if(b[i] == 0)
  	   dp[i] = (dp[i-1] + dp[i-2])% mod;
  	   else dp[i]=0;
  }

  cout<<dp[n]<<endl;
}
  


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


int main(){
  int n;
  cin >> n;
  double ans;
  if(n%2==1){
    ans=((n-1)/2)+1;
    ans=ans/n;
  }else{
    ans=0.5;
  }
  printf("%.10f\n",ans);
  return 0;

}


Measured memory_bytes: 256
n, k = (int(i) for i in input().split())

if n%2==1:
    if k>(n+1)/2:
        print(-1)
    else:
        wlist=[]
        for i in range(n):
            if i<=(n/2)-1:
                wlist.append([k-i+2*n, k+i, k+2*(n-i)-2])
            else:
                wlist.append([k+3*n-i, k+i, k+n+2*(n-i)-2])
        wlist=sorted(wlist)
        #print(wlist)
        for i in range(n):
            print(wlist[i][1], wlist[i][2], k+2*n+i)
else:
    if k<=(n//2):
        wlist=[]
        for i in range(n):
            if i<n/2:
                wlist.append([k-i+2*n+1, k+i, k+2*(n-i)-2])
            else:
                wlist.append([k+3*n-i+1, k+i, k+n+2*(n-i)-1])
        wlist=sorted(wlist)
        #print(wlist)
        for i in range(n):
            print(wlist[i][1], wlist[i][2], k+2*n+i)
    else:
        print(-1)

Measured memory_bytes: 59536
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long A = long.Parse(str[0]);
		long B = long.Parse(str[1]);
		long ans = (A*3+B)/2;
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
def solve(s):
    sums = 0
    sumt = 0
    ans = 0
    for i in s:
        if i == 'S':
            sums += 1
        else:
            if sums > 0:
                sums -= 1
                ans += 2
    return len(s)-ans

if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3500