akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct Seg {
    int _add;
    int mn;
    int lb, rb;
    Seg *ls, *rs;
    void Pushup() { mn = min(ls->mn, rs->mn); }
    void Tag_Add(int x) {
        _add = x;
        mn = x;
    }
    void Pushdown() {
        if (ls == nullptr || rs == nullptr)
            return;
        if (_add == 0)
            return;
        ls->Tag_Add(_add);
        rs->Tag_Add(_add + (ls->rb - ls->lb + 1));
        _add = 0;
    }
} * Root;

Seg *Build(int l, int r) {
    Seg *result = new Seg();
    result->lb = l;
    result->rb = r;
    result->mn = result->_add = 0;
    if (l == r)
        return result;
    int m = (l + r) >> 1;
    result->ls = Build(l, m);
    result->rs = Build(m + 1, r);
    return result;
}

int Get(Seg *k, int s, int t, int x) {
    if (k->lb == k->rb)
        return k->mn;
    k->Pushdown();
    int m = (s + t) >> 1;
    return m >= x ? Get(k->ls, s, m, x) : Get(k->rs, m + 1, t, x);
}

void Add(Seg *k, int s, int t, int l, int r, int j) {
    if (s == l && t == r) {
        k->Tag_Add(j);
        return;
    }
    k->Pushdown();
    int m = (s + t) >> 1;
    if (m >= r)
        Add(k->ls, s, m, l, r, j);
    else if (m < l)
        Add(k->rs, m + 1, t, l, r, j);
    else {
        Add(k->ls, s, m, l, m, j);
        Add(k->rs, m + 1, t, m + 1, r, j + (m - l + 1));
    }
    k->Pushup();
}

int Min(Seg *k, int s, int t, int l, int r) {
    if (s == l && t == r)
        return k->mn;
    k->Pushdown();
    int m = (s + t) >> 1;
    if (m >= r)
        return Min(k->ls, s, m, l, r);
    if (m < l)
        return Min(k->rs, m + 1, t, l, r);
    return min(Min(k->ls, s, m, l, m), Min(k->rs, m + 1, t, m + 1, r));
}

int H, W, i, A, B, ban = 1;
int main() {
    scanf("%d%d", &H, &W);
    Root = Build(1, W);
    for (i = 1; i <= H; ++i) {
        scanf("%d%d", &A, &B);
        if (A <= ban)
            ban = max(ban, B + 1);
        if (ban > W) {
            puts("-1");
            continue;
        }
        if (ban < A)
            Add(Root, 1, W, A, B, Get(Root, 1, W, A - 1) + 1);
        printf("%d\n", Min(Root, 1, W, ban, W) + i);
    }
}

Measured memory_bytes: 22468
#include<bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define vpii vector<pair<int,int> >
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back   
#define PB pop_back
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;

void solve(){
    int n, x1 = 0;
    cin>>n;
    int a[n+10];
    f(i,n)cin>>a[i],x1 ^= a[i];
    f(i,n)cout<<(x1^a[i])<<" ";
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 5112
def main():
    s = input()
    t = input()
    ls,lt = len(s),len(t)
    
    dp = [[0 for _ in range(lt+1)] for _ in range(ls+1)]
    
    for i in range(ls):
        for j in range(lt):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j]+1
            else:
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])

    i += 1;j += 1
    ans = ""
    k = dp[-1][-1]
    while k:
        if dp[i-1][j] == k:
            i -= 1
        elif dp[i][j-1] == k:
            j -= 1
        else:
            k -= 1
            i -= 1
            j -= 1
            ans += s[i]
    
    print(ans[::-1])
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 120028
package main

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

func getScanner(fp io.Reader) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 500001), 500000)
	return sc
}

func getHugeScanner(fp io.Reader, size int) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, size), size)
	return sc
}

func getNextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func getNextInt(sc *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(sc))
	return i
}

func getNextInt64(sc *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(sc), 10, 64)
	return i
}

func getNextFloat64(sc *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(sc), 64)
	return i
}

var e [][]int
var c []int
var a []int

func DFS(i, cnt int) {
	a[i] = c[i] + cnt
	for _, v := range e[i] {
		if a[v] != -1 {
			continue
		}
		DFS(v, a[i])
	}
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := getScanner(stdin)

	n := getNextInt(sc)
	q := getNextInt(sc)

	e = make([][]int, n)
	c = make([]int, n)
	a = make([]int, n)
	for k := range c {
		a[k] = -1
	}

	for i := 1; i < n; i++ {
		a := getNextInt(sc)
		b := getNextInt(sc)
		a--
		b--

		e[a] = append(e[a], b)
		e[b] = append(e[b], a)
	}

	for i := 0; i < q; i++ {
		p := getNextInt(sc)
		x := getNextInt(sc)
		p--

		c[p] += x
	}

	DFS(0, 0)

	for i := 0; i < n; i++ {
		_, _ = fmt.Fprintf(stdout, "%v ", a[i])
	}
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}

Measured memory_bytes: 52608
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  for (int i=0; i<=25; i++) {
    int d = N - i * 4;
    if (d < 0) break;
    if (d % 7 == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
# AGC 031: A – Colorful Subsequence
N = int(input())
S = input()
s = set(S)
s_count = [S.count(c) + 1 for c in s]

tmp = 1
for i in s_count:
    tmp *= i

print((tmp - 1) % (10 ** 9 + 7))

Measured memory_bytes: 3188
#include <stdio.h>

void swap(int *x, int *y)
{
    int t;
    
    t = *x;
    *x = *y;
    *y = t;
}

int main(void)
{
    int N, A[100], i, j = 0, n = 0;
    
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
       scanf("%d", &A[i]); 
    }
    while (j < N) {
        for (i = N - 1; i > j; i--) {
            if (A[i] < A[i - 1]) {
                swap(&A[i], &A[i - 1]);
                n++;
            }
        }
        j++;
    }
    for (i = 0; i < N; i++) {
        printf("%d", A[i]);
        if (i != N - 1) {
            printf(" ");
        } else {
            printf("\n");
        }
    }
    printf("%d\n", n);
    return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

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

    double p;
    vector<vector<double>> dp(N + 1, vector<double>(N + 1));
    //cout << dp[0][0] << endl;
    dp[0][0] = 1.0;
    for (int i = 1; i <= N; i++) {
        cin >> p;
        for (int j = 0; j <= N; j++) {
            if (j == 0)
                dp[i][j] = dp[i - 1][j] * (1 - p);
            else
                dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p);
            
        }
        //cout << i << endl;
    }
    //cout << "finished" << endl;
    double ans = 0;
    for (int i = (N + 1) / 2; i <= N; i++)
        ans += dp[N][i];

    cout << fixed << setprecision(10) << ans << endl;
    //cout <<  ans << endl;
}


Measured memory_bytes: 70656
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct BIT{
    int size;
    vector<long long> bit;
    void init(int n){
        size = n;
        bit.assign(size+1, 0);
    }

    // from 1 to x (inclusive)
    long long sum(int x){
        long long res = 0;
        while(x > 0){
            res += bit[x];
            x -= (x & -x);
        }
        return res;
    }

    void add(int x, long long y){
        while(x <= size){
            bit[x] += y;
            x += (x & -x);
        }
    }
};

long long inv_num(int n, vector<long long> array){
    long long res = 0;
    vector<long long> v;
    BIT b;
    b.init(n);
    v.assign(array.begin(), array.end());
    sort(v.begin(), v.end());
    auto tmp = unique(v.begin(), v.end());
    v.erase(tmp, v.end());
    for(int i=0;i<n;i++){
        int val = (int)(lower_bound(v.begin(), v.end(), array[i]) - v.begin()) + 1;
        res += i - b.sum(val);
        b.add(val, 1);
    }
    return res;
}

int main(void){
    int n, k;
    vector<long long> v;
    cin >> n >> k;
    v.push_back(0);
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        v.push_back(v.back() + a - k);
    }

    cout << (long long)n * (n+1) / 2 - inv_num(n+1, v) << endl;
}


Measured memory_bytes: 6768
N = int(input())
L_list = list(map(int, input().split()))

L_list.sort()
import bisect
res = 0
for i in range(N):
    a= L_list[i]
    for j in range(i+1,N):
        b= L_list[j]
        ind = bisect.bisect_left(L_list,a+b)
        res+=(ind-j-1)

print(res)

Measured memory_bytes: 3188
#include<stdio.h>

long long int kaijo(int);

int main(void)
{
	int n;
	scanf("%d",&n);
	printf("%lld\n",kaijo(n));
	return 0;
}

long long kaijo(int n)
{
	if(n==1) return 1;
	return n*kaijo(n-1);
}

Measured memory_bytes: 592
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DFaceProducesUnhappiness solver = new DFaceProducesUnhappiness();
        solver.solve(1, in, out);
        out.close();
    }

    static class DFaceProducesUnhappiness {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            boolean[] left = new boolean[n];
            char[] input = in.next().toCharArray();
            for (int i = 0; i < n; i++) {
                left[i] = (input[i] == 'L');
            }

            int answer = solve(n, k, left);
            out.println(answer);
        }

        private static int solve(int n, int k, boolean[] left) {
            int score = 0, lr = 0, rl = 0;
            for (int i = 0; i + 1 < n; i++) {
                if (left[i] == left[i + 1]) {
                    score++;
                } else if (left[i]) {
                    lr++;
                } else {
                    rl++;
                }
            }

            while (k > 0) {
                if (lr > 0 && rl > 0) {
                    lr--;
                    rl--;
                    k--;
                    score += 2;
                } else {
                    break;
                }
            }

            if (k > 0 && (lr > 0 || rl > 0)) {
                score++;
            }

            return score;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 25172
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from collections import defaultdict
from bisect import bisect_left

S = input().rstrip()
T = input().rstrip()

LS = len(S)

index = defaultdict(list)

for i,s in enumerate(S):
    index[s].append(i)

x = -1
for t in T:
    arr = index[t]
    if len(arr) == 0:
        x = -2
        break
    y = (x+1) % LS
    i = bisect_left(arr,y)
    if i < len(arr):
        next_x = (x+1) + arr[i] - y
    else:
        next_x = (x+1) + arr[0] - y + LS
    x = next_x

print(x + 1)



Measured memory_bytes: 45936
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

void solve() {
	int n; cin >> n;
	vector<int> x(n);
	rep(i, n) {
		cin >> x[i];
	}
	int ans = mod;
	rep1(i, 100) {
		int sum = 0;
		rep(j, n) {
			int dif = x[j] - i;
			sum += dif * dif;
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
	return 0;
}


Measured memory_bytes: 4352
#pragma comment(linker, "/STACK:60777216")  

#include <cassert>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<cstdlib>
#include<memory.h>
#include<ctime>
#include<bitset>
#include<fstream>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>

using namespace std;

typedef long double ld;

typedef long long ll;
typedef pair<int,int>	pii;
typedef pair<ld,ld>	pdd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef pair<ll,ll> pl;

#define FOR(i,a,b)		for(int i=(a);i<(b);i++)
#define REP(i,n)		FOR(i,0,n)
#define SORT(v)			sort((v).begin(),(v).end())
#define UN(v)			SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)			memset(a,b,sizeof a)
#define pb				push_back

int n,h,w;
int a[111111];

int r[111][111];

int main(){	
#ifdef LocalHost
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif

	cin>>h>>w>>n;
	REP(i,n)cin>>a[i];
	int x = 0, y = 0;
	REP(i,n){
		REP(j,a[i]){
			r[x][y]=i+1;
			if(x%2==0)y++;
			else y--;
			if(y==w){
				y--;
				x++;
			}else if(y<0){
				y++;
				x++;
			}
		}
	}

	REP(i,h){
		REP(j,w){
			if(j)printf(" ");
			printf("%d",r[i][j]);
		}
		puts("");
	}

#ifdef LocalHost
	printf("TIME: %.3lf\n",ld(clock())/CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}


int main(){
 ll n ;cin>> n;
 vector<ll> A(n) ; rep(i,n) cin>>A[i] ;
 vector<ll> ans(n) ;
 rep(i,n){
   ll k=n-1-i ;
   ll sum= 0;
   for(ll j=2;j<n+5;j++){
      if(j*(k+1)-1>n-1) break ;
      sum+=ans[(k+1)*j-1] ;
   }
   if( sum%2 != A[k] ) ans[k]=1 ;
 }
 ll cnt=0 ;
 rep(i,n) if(ans[i]==1) cnt++ ;
 cout<<cnt<<endl ;
 rep(i,n) {
   if(ans[i]==1) cout<<i+1<<endl;
 }
 
  return 0 ;
}

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

using namespace std;

int main()
{
    int N,X,m;
    int sum = 0;
    cin >> N >> X;
    vector<int> buf;

    for(int i=0; i<N; i++){
        cin >> m;
        buf.push_back(m);
        sum += m;
    }

    int min = *std::min_element(buf.begin(),buf.end());
    int cnt = N;

    while(true)
    {
        sum += min;
        if(X < sum)
        {
            sum -= min;
            break;
        }

        cnt++;
    }

    cout << cnt << endl;
    return 0;

}


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

string run(string str, int len, int h) {
	string res = "";
	for(int i = h; i < len; i++) res += str[i];
	for(int i = 0; i < h; i++) res += str[i];
	return res;
}

int main() {
	string str;
	int n, h;
	while(cin >> str && str != "-") {
		int len = str.length();
		cin >> n;
		while(n--) {
			cin >> h;
			str = run(str, len, h);
		}
		cout << str << '\n';
	}
	return 0;
}


Measured memory_bytes: 3216
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()
if 400 <= X < 600:
    print(8)
elif 600 <= X < 800:
    print(7)
elif 800 <= X < 1000:
    print(6)
elif 1000 <= X < 1200:
    print(5)
elif 1200 <= X < 1400:
    print(4)
elif 1400 <= X < 1600:
    print(3)
elif 1600 <= X < 1800:
    print(2)
elif 1800 <= X < 2000:
    print(1)




Measured memory_bytes: 10628
#include<cstdio>

#define ran 101101

int n, m;
char s[ran];
int v[ran];

int main() {
	scanf("%d%d", &n, &m);
	scanf("%s", s);
	
	v[0] = 0;
	for(int i=1;i<n;i++) {
		if (s[i]=='C' && s[i-1] == 'A') v[i] ++;
		v[i] += v[i-1];
	}
	
	for(int i=0;i<m;i++) {
		int l, r; scanf("%d%d", &l, &r);
		l--; r--;
		
		int ans = v[r] - (l==0 ? 0 : v[l-1]);
		if (s[l-1] == 'A' && s[l] == 'C') ans--;
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 1280
import sys

s = []
for i in range(3):
    s.append(input())

al = ["A", "B", "C"]    
def check(s, d, c):
    if len(s[d]) == 0:
        print(c[d])
        sys.exit()        
    if s[d][0] == "a":
        s[d] = s[d][1:] 
        return 0
    elif s[d][0] == "b":
        s[d] = s[d][1:]
        return 1
    else:
        s[d] = s[d][1:]
        return 2      
        
d = 0
while True:
    d = check(s, d, al)

Measured memory_bytes: 3064
s=input()
g=0
p=0
point=0
for i in s:
  if(i=="g"):
    if(p<g):
      point+=1
      p+=1
    else:
      g+=1
  else:
    if(p<g):p+=1
    else:
      g+=1
      point-=1
print(point)
    

Measured memory_bytes: 3316
a,b= map(int,input().split())
res=0

if a==1:
    res+=300000
if b==1:
    res+=300000
if a==2: 
    res+=200000
if b==2: 
    res+=200000
if a==3: 
    res+=100000
if b==3: 
    res+=100000    
if a==1 and b==1:
    res=1000000
    
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

int sumArray(int a[], int n) {
	int ans = 0;
	for (int i = 0; i < n; i++)ans += a[i];
	return ans;
}

int main() {
	int N; cin >> N;
	int ans = INF;
	for (int i = 1; i < N; i++) {
		int num1 = i;
		int num2 = N - i;

		int digit1[5], digit2[5];
		// 各桁の数を求める
		for (int k = 4; k >= 0; k--) {
			int a = 1;
			for (int j = 0; j < k; j++) a *= 10; // aは10のi乗
			digit1[k] = num1 / a;
			digit2[k] = num2 / a;
			num1 -= digit1[k] * a;
			num2 -= digit2[k] * a;
		}
		int tmp = (sumArray(digit1, 5) + sumArray(digit2, 5));
		ans = min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<map>
using namespace std;
struct Data{string s;int n;};
int main()
{
  map<int,int> change;
  change['r'+'g']='b';
  change['g'+'b']='r';
  change['b'+'r']='g';
  map<string,int> changed;
  queue<Data> q;
  string s;
  Data d;
  int i,n;
  bool flag;
  int t=0;
  while(cin>>s,s!="0"){
    changed.clear();
    while(!q.empty())q.pop();
    d.s=s;
    d.n=0;
    q.push(d);
    changed[d.s]=1;
    while(!q.empty()){
      d=q.front();
      s=d.s;
      n=d.n;
      q.pop();
      flag=true;
      for(i=1;i<s.size();i++){
	if(s[i-1]==s[i])continue;
	flag=false;
	d.s=s;
	d.s[i-1]=d.s[i]=change[d.s[i-1]+d.s[i]];
	d.n=n+1;
	if(changed.find(d.s)!=changed.end())continue;
	changed[d.s]=1;
	q.push(d);
      }
      if(flag)break;
    }
    if(flag)cout<<n<<endl;
    else puts("NA");
  }
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	while(sc.hasNext()) {
		double sum=0;
		double sum2=0;
		double a = 0;
	int n=sc.nextInt();
	if(n==0) {
		break;
	}
	int s[]=new int[n];
	for(int i=0;i<s.length;i++) {
		s[i]=sc.nextInt();
	}
	for(int i=0;i<s.length;i++) {
		sum=sum+s[i];
	}
	double m=sum/n;
	for(int i=0;i<s.length;i++) {
			a=(s[i]-m)*(s[i]-m);
			sum2=sum2+a;
	}
	double a2=sum2/n;
	double a3=(double) Math.sqrt(a2);
	System.out.println(a3);
}
}
}



Measured memory_bytes: 30880
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;
  bool x;
  int cnt = 1;
  int bcnt = 1;
  for (int i = 0; i < (int)s.size(); i++) {
    x = false;
    if (s[i] == 'a' && cnt <= a+b) {
      x = true;
      cnt++;
    }
    else if (s[i] == 'b' && cnt <= a+b && bcnt <= b) {
      x = true;
      cnt++;
      bcnt++;
    }
    dump(x ? "Yes" : "No");
  }
  return 0;
}


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

using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vector<int> p;
    for (int i=0; i<n; i++){
        int v; cin>>v;
        p.push_back(v);
    }
    std::sort(p.begin(),p.end());
    int ans=0;
    for(int i=0; i<k; i++){
        ans+=p[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

vector<int> f(int N, int S, int W){
	vector<int> a(N);
	int g = S;
	for(int i=0; i < N; i++ ) {
		a[i] = (g / 7) % 10;
		g = (g % 2)? (g / 2) ^ W : (g / 2);
	}
	return a;
}

int main(){
	int N, S, W, Q;
	while( cin >> N >> S >> W >> Q, N || S || W || Q ){
		vector<int> a = f(N, S, W);
		
		int ans = 0;
		if( Q == 2 || Q == 5 ){
			int cnt = 0;
			for(int i=0 ; i < N ; i++ ){
				if( a[i] != 0 ) cnt++;
				if( a[i] % Q == 0 ){
					ans += cnt;
				}
			}
			
		}else{
			int b = 1, r = 0;
			map<int,int> m;
			m[0] = 1;
			for(int i = N-1 ; i >= 0 ; i-- ){
				r += b * a[i];
				r %= Q;
				if( a[i] != 0 ) ans += m[r];
				m[r]++;
				b = (b * 10) % Q;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 5540
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define B begin()
#define E end()
using namespace std;
int main()
{
    string s; cin>>s; ll c=0;
    if(s[2]=='R' && s[1]=='R' && s[0]=='R') c+=3;
    else if(s[0]=='R' && s[1]=='R') c+=2;
    else if(s[2]=='R' && s[1]=='R') c+=2;
    if(c!=0)
    {
        cout<<c; return 0;
    }
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]=='R') c++;
    }
    if(c!=0) cout<<"1";
    else cout<<"0";
}


Measured memory_bytes: 3620
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

D = lines[0][0]
Inf = 10 ** 10

last_date = []
for i in 1..26 do
  last_date.push(0)
end

satis = 0
for i in 1..D do
  max_satis = - Inf
  best_contest = 0
  for k in 1..26 do
    now_satis = 0
    now_satis += lines[i+1][k-1]
    now_satis += lines[1][k-1] * (i - last_date[k-1])
    if now_satis > max_satis then
      max_satis = now_satis
      best_contest = k
    end
  end
  satis += now_satis
  for j in 1..26 do
    satis -= lines[1][best_contest-1] * (j - last_date[best_contest-1])
  end
  last_date[best_contest-1] = i
  if i < D then
    puts best_contest
  else
    print best_contest
  end
end

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

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

  vector<ll> x(n), y(n);
  vector<ll> cx(m), cy(m);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  for (int i = 0; i < m; i++) cin >> cx[i] >> cy[i];

  for (int i = 0; i < n; i++) {
    int no = 0;
    ll dist = 1e10;
    for (int j = 0; j < m; j++) {
      ll d = abs(x[i] - cx[j]) + abs(y[i] - cy[j]);
      if (d < dist) {
        no = j + 1;
        dist = d;
      }
    }
    printf("%d\n", no);
  }
}


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

int main(){
	std::string s;
	int counter = 0;

	std::cin >> s;

	for(int i = 0; i < 3; ++i){
		if(s[i] == '1'){
			++counter;
		}
	}

	std::cout << counter << std::endl;

	return 0;
}


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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int K; 
  cin >> K;

  int ans = 0;
  FOR(i, 1, K+1) FOR(j, 1, K+1) FOR(k, 1, K+1){
    ans += gcd(gcd(i, j), k);
  }
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=1005,MAXM=200005;
 
int N,M;
vector<int> adj[MAXN];
int E[MAXM][2];
 
int p[MAXN][MAXN],q[MAXN][MAXN];
bool vis[MAXN];
 
void mark(int s,int u,int id,int mk[])
{
	if(u==s||vis[u])return;
	vis[u]=true;
	mk[u]=id;
	for(int i=0;i<(int)adj[u].size();i++)
		mark(s,adj[u][i],id,mk);
}
 
int main()
{
	scanf("%d%d",&N,&M);
	for(int i=1,a,b;i<=M;i++)
	{
		scanf("%d%d",&a,&b);
		E[i][0]=a;E[i][1]=b;
		adj[a].push_back(b);
	}
	
	for(int i=1;i<=N;i++)
	{
		memset(vis,0,sizeof vis);
		int id=0;
		for(int j=0;j<(int)adj[i].size();j++)
			mark(i,adj[i][j],++id,p[i]);
		memset(vis,0,sizeof vis);
		reverse(adj[i].begin(),adj[i].end());
		id=adj[i].size();
		for(int j=0;j<(int)adj[i].size();j++)
			mark(i,adj[i][j],id--,q[i]);
	}
	
	for(int i=1;i<=M;i++)
		if((p[E[i][1]][E[i][0]]>0)==(p[E[i][0]][E[i][1]]!=q[E[i][0]][E[i][1]]))
			puts("same");
		else
			puts("diff");
	
	return 0;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=998244353;
lli inf=9223372036854775807;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
int main()
{
	lli a,b,c;
	cin>>a;b=a;c=a;
	
	lli ani=0;
	for(lli i=1;i<=a;i++){
		for(lli j=1;j<=b;j++){
			lli temp=__gcd(i,j);
			for(lli k=1;k<=c;k++){
				ani+=__gcd(temp,k);
			}
		}
	}
	cout<<ani;
	
	
    return 0;
}

Measured memory_bytes: 3636
(function underscore(undefined) {
	'use strict';
	var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;

	var push = ArrayProto.push,
	slice = ArrayProto.slice,
	concat = ArrayProto.concat,
	toString = ObjProto.toString,
	hasOwnProperty = ObjProto.hasOwnProperty;

	var nativeForEach = ArrayProto.forEach,
	nativeMap = ArrayProto.map,
	nativeReduce = ArrayProto.reduce,
	nativeReduceRight = ArrayProto.reduceRight,
	nativeFilter = ArrayProto.filter,
	nativeEvery = ArrayProto.every,
	nativeSome = ArrayProto.some,
	nativeIndexOf = ArrayProto.indexOf,
	nativeLastIndexOf = ArrayProto.lastIndexOf,
	nativeIsArray = Array.isArray,
	nativeKeys = Object.keys,
	nativeBind = FuncProto.bind;

	this._ = {};
	var each = _.each = _.forEach = function(obj, iterator, context) {
		if (obj == null) return;
		if (nativeForEach && obj.forEach === nativeForEach) {
			obj.forEach(iterator, context);
		} else if (obj.length === +obj.length) {
			for (var i = 0, l = obj.length; i < l; i++) {
				if (iterator.call(context, obj[i], i, obj) === breaker) return;
			}
		} else {
			for (var key in obj) {
				if (_.has(obj, key)) {
					if (iterator.call(context, obj[key], key, obj) === breaker) return;
				}
			}
		}
	};

	_.extend = function(obj) {
		each(slice.call(arguments, 1), function(source) {
			if (source) {
				for (var prop in source) {
					obj[prop] = source[prop];
				}
			}
		});
		return obj;
	};
}).call(global);

(function(undefined){
	'use strict';

	var INPUT_TYPE = 'number';

	var INPUT_REGEXP_LIST = {};
	INPUT_REGEXP_LIST['string'] = /\w*/g;
	INPUT_REGEXP_LIST['number'] = /[-]?\d+/g;
	var INPUT_REGEXP = INPUT_REGEXP_LIST[INPUT_TYPE];

	var Solver = {
		fire: function() {
			setTimeout( Solver.solve, 0, this );
		},
		solve: function solve() {
			var n = input_number();
			var m = 100000;
			for ( var i = 0; i < n; ++ i ) {
				m = parseInt(m * 1.05);
				if ( m % 1000 > 0 ) {
					m += 1000;
				}
				m = (function(m){
					return Math.floor(m/1000)*1000;
				})(m);
			}
			output(m);
			if ( ! has_next() )
				setTimeout( Solver.solve, 0, this );
		}
	};

	(function init() {
		_.extend( this, {
			output: function() {
				console.log.apply( console, arguments );
			},
			stdin: process.openStdin(),
			input_list: [],
			input_number: function() {
				return parseInt( input_list.splice(0,1)[0] );
			},
			input_text: function() {
				return input_list.splice(0,1)[0];
			},
			has_next: function() {
				return ! input_list.length;
			}
		} );
		stdin.setEncoding('utf8');
		stdin.on('data', function(chunk){
			var result = chunk.match(INPUT_REGEXP);
			input_list = input_list.concat(result.filter(function(line){
				return line.length;
			}));
		});
		stdin.on('end', function(){
			Solver.fire.call(this);
		});
	}).call( this );

}).call(global);

Measured memory_bytes: 7876
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define SIZE 26     
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 1e5 + 5;

ll fact[N],ifact[N],a[N];

ll power(ll x,ll y){
    ll res=1;
    x=x%mod;
    while(y>0){
        if(y & 1) res=(res*x)%mod;
        y=y>>1;
        x=(x*x)%mod;
    }
    return res%mod;
}
 
ll modInv(ll n){
    return power(n,mod-2);
}
 
ll mul(ll a,ll b){
    return (a*b)%mod;
}

ll C(ll n,ll r){
    if(r>n or r<0) return 0; 
    return mul(fact[n],mul(ifact[r],ifact[n-r]));
}

void precal(){
    fact[0]=1;
    ifact[0]=1;
    for(int i=1;i<N;++i){
        fact[i]=mul(fact[i-1],i);
        ifact[i]=mul(ifact[i-1],modInv(i));
    }
}

signed main(){
    fastio;
    precal();
    ll i,n,k,ans=0;
    cin>>n>>k;
    for(i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n;++i){
        ans+=mul(a[i],C(i,k-1)-C(n-i-1,k-1));
        ans%=mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll K;
int main(){
    cin>>K;
    int n=50;
    printf("%d\n",n);
    ll a=K/(ll)n; ll b=K%(ll)n;
    int cnt=0;
    for(int i=1;i<=(int)b;++i){
        ++cnt;
        cout<<49ll+a+((ll)n-(b-1ll))<<(cnt==n ? '\n' : ' ');
    }
    for(int i=1;i<=n-(int)b;++i){
        ++cnt;
        cout<<49ll+a-b<<(cnt==n ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	
	int k,s,z;
	int ans=0;
	cin>>k>>s;
	for(int x=0;x<=k;x++)
	{
		for(int y=0;y<=k;y++)
		{
			z=s-(x+y);
			if(z>=0 && z<=k && x+y+z==s){
			
		
		ans++;
	    	
		}
	}
}
	 cout<<ans;
}

Measured memory_bytes: 256
n, k, q = gets.split(' ').map(&:to_i)
seikaisha = []
q.times do
  seikaisha << gets.to_i
end

points = Array.new(n,0)
seikaisha.map do |s|
  points[s-1] ? points[s-1] += 1 : points[s-1] = 1
end

goukakuline = q - k + 1
points.each do |p|
  if (!p || p < goukakuline)
    puts 'No'
  else
    puts 'Yes'
  end
end


Measured memory_bytes: 5684
import java.util.Scanner;
import java.util.TreeSet;
import java.util.Arrays;
public class Main {
 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String x;
        x=sc.nextLine();
        x=x.toLowerCase();
        int count=0;
        while(true){
            String y;
            y=sc.next();
            if(y.equals("END_OF_TEXT"))break;
           y= y.toLowerCase();
            if(y.equals(x))count++;
        }
        System.out.println(count);
}
}




Measured memory_bytes: 26244
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N, M, V, P;
  cin >> N >> M >> V >> P;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  int ans = 0;
  RREP(i, N){
    if(N-i <= P){
      ans++;
      continue;
    }

    // V個配る
    int cnt = V;
    // 残りcnt個配れる
    cnt -= i+1;
    cnt -= P-1;

    if(A[i]+M < A[N-P]) continue;
    if(cnt > 0){
      int res = 0;
      for(int j = i+1; j <= N-P; j++){
        res += (A[i]+M)-A[j];
        if(res >= cnt*M) break;
      }
      if(res >= cnt*M){
        ans++;
        continue;
      }
    }
    else if(A[N-P] <= A[i]+M){
      ans++;
      continue;
    }

    break;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define int long long
using namespace std;

signed main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		for (int c = 0; c < a; c++) {
			for (int d = 0; d < b; d++) {
				if (c != 0 && d != 0 && a - 1 != c&&b - 1 != d)cout << ".";
				else cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
}

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

int main() {
  int N, K, cost_a, cost_b, total_cost = 0, temp;
  vector<int> x;

  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    cin >> temp;
    x.push_back(temp);
  }

  for (int i = 0; i < N; i++) {
    cost_a = (x[i] - 0) * 2;
    cost_b = (K - x[i]) * 2;

    if (cost_a < cost_b) {
      total_cost += cost_a;
    } else {
      total_cost += cost_b;
    }
  }

  cout << total_cost << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s,t = sc.next
  var m1,m2 = Map[Char, Set[Char]]()
  s.zip(t).foreach{ case (c1,c2) =>
    m1 += c1 -> (m1.getOrElse(c1, Set()) + c2)
    m2 += c2 -> (m2.getOrElse(c2, Set()) + c1)
  }

  println(if ((m1.values ++ m2.values).forall(_.size == 1)) "Yes" else "No")
}

Measured memory_bytes: 60532
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto i : a) cout << i << ' ';
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);


using namespace std;


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


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	_, _ = fmt.Scan(&n, &m)
	arr := make([]int, m)
	for i := 0; i < m; i++ {
		var tmp int
		_, _ = fmt.Scan(&tmp)
		arr[i] = tmp
	}
	sort.Sort(sort.IntSlice(arr))
	arr2 := make([]int, m - 1)
	for i := 0; i < m - 1; i++ {
		arr2[i] = arr[i + 1] - arr[i]
	}
	sort.Sort(sort.IntSlice(arr2))
	sum := 0
	for i := m - 2; i > m - 2 - n + 1; i-- {
		if i < 0 {
			break
		}
		sum += arr2[i]
	}
	fmt.Println(arr[m - 1] - arr[0] - sum)
}

Measured memory_bytes: 7552
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }


void solve() {
    string s;
    cin >> s;
    int sum = 0;
    for (int i = 0; i < s.size(); ++i) {
        sum += s[i] - '0';
    }
    if (s.size() == 1) {
        cout << s[0] << endl;
    } else {
        cout << max(sum, (int)((s[0] - '0') - 1 + 9 * (s.size() - 1))) << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

using namespace std;

int main()
{
	int w, a, b;
	cin >> w >> a >> b;
	int r;
	if (a > b) r = max(0, a-b-w);
	else r = max(0, b-a-w);
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

const int INF = 1 << 29;

int N, M, R;
int r[8];

int main() {
    cin >> N >> M >> R;
    for (int j = 0; j < R; ++j) {
        cin >> r[j];
        --r[j];
    }

    i64 d[200][200];
    for (int j = 0; j < 200; ++j) {
        fill(d[j], d[j]+200, INF);
        d[j][j] = 0;
    }

    for (int j = 0; j < M; ++j) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        d[a][b] = d[b][a] = min(d[a][b], (i64)c);
    }

    for (int l = 0; l < N; ++l) {
        for (int j = 0; j < N; ++j) {
            for (int k = 0; k < N; ++k) {
                d[j][k] = min(d[j][k], d[j][l] + d[l][k]);
            }
        }
    }

    int ans = INF;
    sort(r, r+R);
    do {
        int s = 0;
        for (int j = 0; j < R-1; ++j) {
            s += d[r[j]][r[j+1]];
        }
        ans = min(ans, s);
    } while(next_permutation(r, r+R));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
int main() {
  ll h, w;
  cin >> h >> w;
  char s[h][w];
  ll mx = 0;
  REP(i, h) REP(j, w) {
    cin >> s[i][j];
    if (s[i][j] == '.') ++mx;
  }

  ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  ll d[h][w];
  REP(i, h) {
    REP(j, w) { d[i][j] = INF; }
  }

  queue<P> que;
  que.push(P(0, 0));
  d[0][0] = 0;

  while (!que.empty()) {
    P p = que.front();
    que.pop();
    if (p.first == h - 1 && p.second == w - 1) break;
    REP(i, 4) {
      ll ny = p.first + dy[i], nx = p.second + dx[i];

      if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] != '#' &&
          d[ny][nx] == INF) {
        d[ny][nx] = d[p.first][p.second] + 1;
        que.push(P(ny, nx));
      }
    }
  }
  if (d[h - 1][w - 1] == INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << mx - d[h - 1][w - 1] - 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
             using namespace std;
             
            int main()
            {
            	int a,c;
              	double b;
              cin>>a;	
              if(a%2==0) b=0.5;
              	else 
                {
                c=a/2;
                  b=(c+1)/double(a);
                }
              cout<<b;
            return 0;
            }

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


A, B = map(int, input().split())
print('unsafe' if A <= B else 'safe')


Measured memory_bytes: 9544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 100010;

int main() {
    int h, w; cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    vector<bool> H(h, false);
    vector<bool> W(w, false);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
            if (a[i][j] == '#') {
                H[i] = true;
                W[j] = true;
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (H[i] && W[j]) cout << a[i][j];
        }
        if (H[i]) cout << endl;
    }
}

Measured memory_bytes: 256