akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,s,e) for(int i = s; i < e; i++)
using namespace std;

bool cmp(int a, int b)
{
   return a > b;
}

int main()
{
    int n;
    while(scanf("%d", &n) && n != 0)
    {
        list<int> c[40000];
        int left = 40000, right = 0;
        int fx, fy;
        int px, py;
        rep(i,0,n+1)
        {
            int x,y;
            if(i == n)
            {
                x = fx;
                y = fy;
                goto label;
            }
            cin >> x >> y;
            if(i == 0)
            {
                fx = x;
                fy = y;
                px = x;
                py = y;
                continue;
            }
            label:
            if(x != px)
            {
                int Min = min(x,px)+20000, Max = max(x,px)+20000;
                left = min(left,Min), right = max(right,Max);
                rep(j,Min,Max)
                {
                    c[j].push_back(y);
                }
                px = x;
            }
        }
        rep(i,left,right)
            c[i].sort(greater<int>());
    
        pair<int,int> cartain[4];
        rep(i,0,4)
        {
            cin >> cartain[i].first >> cartain[i].second;
            cartain[i].first += 20000;
        }
        sort(cartain,cartain+4);
        int cUp= cartain[1].second;
        int cBottom = cartain[0].second;
        int cLeft = cartain[1].first;
        int cRight = cartain[3].first;
        long long ans = 0;
       
        rep(i, left, right)
        {
            bool flag = true;
            auto it = c[i].begin();
            auto end = c[i].end();
            for(it; it != --end; it++)
            {
                if(flag)
                {
                    int up = *it;
                    int bottom = *(++it);
                    it--;
                    if(cLeft > i || cBottom >= up || cUp <= bottom || cRight <= i)
                        ans += up - bottom;
                    else if(cBottom >= bottom && cBottom <= up && cUp >= up)
                        ans += cBottom - bottom;
                    else if(cUp >= bottom && cUp <= up && cBottom <= bottom) 
                        ans += up - cUp;
                    else if(cUp <= up && cBottom >= bottom)
                        ans += (up-cUp) + (cBottom-bottom);   
                }
                flag = !flag;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 66368
#include<cstdio>
#include<algorithm>
using namespace std;

const int N=1000005,P=998244353;
int n,m,f[N],rf[N];

int pw(int a,int x)
{
	int ans=1;
	for(;x;x>>=1,a=1ll*a*a%P)
		if(x&1)ans=1ll*ans*a%P;
	return ans;
}

int C(int n,int m)
{
	return 1ll*f[n]*rf[m]%P*rf[n-m]%P;
}

int main()
{
	scanf("%d%d",&n,&m);
	if(n<m)swap(n,m);
	for(int i=f[0]=1;i<=n+m;i++)f[i]=1ll*f[i-1]*i%P;
	rf[n+m]=pw(f[n+m],P-2);
	for(int i=n+m;i;i--)rf[i-1]=1ll*rf[i]*i%P;
	int ans=n;
	for(int i=1;i<=m;i++)
		ans=(ans+1ll*C(2*i,i)*C(n+m-2*i,n-i)%P*pw(2*C(n+m,n),P-2))%P;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 7936
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int N,K; cin >> N >> K;
    string s; cin >> s;
    vector<int> v;
    int cnt = 1;
    rep(i,N-1){
        if(s[i] != s[i+1]){
            v.push_back(cnt);
            cnt = 1;
        }
        else cnt++;
    }
    v.push_back(cnt);

    int t = v.size();
    vector<int> sum(t+1);
    rep(i,t){
        sum[i+1] = sum[i] + v[i];
    }
    int ans = 0;
    vector<int> suml(t+1),sumr(t+1);
    rep(i,t){
        suml[i+1] = suml[i]+v[i]-1;
    }
    for(int i = t; i >= 1; i--){
        sumr[i-1] = sumr[i]+v[i-1]-1;
    }
    rep(i,t){
        ans = max(ans,sum[min(i+2*K+1,t)]-sum[i]+suml[i]+sumr[min(i+2*K+1,t)]);
    }
    cout << ans-1 << endl;

}


Measured memory_bytes: 2168
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		for (char c : line.toCharArray()) {
			if (Character.isLowerCase(c)) {
				System.out.print(Character.toUpperCase(c));
			} else {
				System.out.print(Character.toLowerCase(c));
			}
		}
		System.out.println();
	}
}

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

#define ll long long

const ll INF = 10e9 + 5;

void maxSelf(ll &a, ll b) {
	a = max(a,b);
	return;
}

void minSelf(ll &a, ll b) {
	a = min(a,b);
	return;
}

int main() {
	
	int i,N,W;
	cin>>N>>W;

	vector<int> w(N+1);
	vector<int> v(N+1);

	int sumValues = 0;

	for (i=0;i<N;i++) {
		cin>>w[i]>>v[i];
		sumValues += v[i];
	}

	// dp[x] - minimum total weight of items with total value exactly x

	vector<ll> dp(sumValues+1, INF);

	dp[0]=0;

	for (i=0;i<N;i++) {
		for (int j=sumValues-v[i];j>=0;j--) {
			minSelf(dp[j+v[i]],dp[j]+w[i]);
		}
	}


	int max1=0;
	for (i=1;i<=sumValues;i++)
	if (dp[i]<=W) {
		// cout<<dp[i]<<" "<<i<<"\n";
		max1=i;
	}
	cout<<max1<<"\n";
	return 0;
}

Measured memory_bytes: 1024
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    const ll p = 998244353;
    int n, k;
    cin >> n >> k;
    vector <pair <int, int> > v(n);
    for (int i = 0; i < k; i++) cin >> v[i].F >> v[i].S;
    vector <ll> pre(n+1, 0), dp(n+1, 0);
    pre[1] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < k; j++) {
            int r = i-v[j].F;
            int l = max(i-v[j].S, 1);
            if (r < 0) continue;
            dp[i] += (pre[r] - pre[l-1] + p)%p;
            dp[i] %= p;
        }
        pre[i] = (pre[i-1] + dp[i])%p;
    }
    cout << (dp[n]+p)%p << endl;
    return 0;
}




Measured memory_bytes: 7936
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    K, T = MI()
    a = LI()
    q = deque()

    for i in range(K):
        mx = 0
        mx_i = -1
        for j in range(T):
            if a[j] > mx and ((len(q) > 0 and q[-1] != j) or len(q) == 0):
                mx = a[j]
                mx_i = j

        if mx_i != -1:
            a[mx_i] -= 1
            q.append(mx_i)

    print(sum(a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 39916
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String line = scanner.nextLine();
		String ans = "";
		switch (line) {
		case "A":
			ans =  "T";
			break;
		case "C":
			ans =  "G";
			break;
		case "T":
			ans =  "A";
			break;
		case "G":
			ans =  "C";
			break;
		}
		System.out.println(ans);
		scanner.close();
	}
}


Measured memory_bytes: 20564
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int before = (int) Math.ceil(n / 1.08);
        String result = (int) (before * 1.08) == n ? Integer.toString(before) : ":(";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back

int main()
{
    ll x;
    cin >> x;
    set<ll> st;
    map<ll, ll> mp;
    for (ll i = -1000; i <= 1000; i++)
    {
        ll y = pow(i, 5);
        st.insert(y);
        mp[y] = i;
    }
    ll a, b;

    for (auto i : st)
    {
        if (st.find(x + i) != st.end())
        {
            a = mp[x + i];
            b = mp[i];
            break;
        }
    }
    cout << max(a, b) << " " << min(a, b) << endl;
}


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

int main(){
  ll n;cin>>n;
  vector<char> sc(n);
  ll rc=0,gc=0,bc=0;
  for(int i=0;i<n;i++){
    char c;cin>>c;
    if(c=='R')rc++;
    else if(c=='G')gc++;
    else bc++;
    sc[i]=c;
  }
  
  ll anm=0;
  for(int i=0;i<n-2;i++)for(int k=i+1;k<n-1;k++){
    if(sc[i]==sc[k])continue;
    int x=2*k-i;
    if(x>=n)continue;
    if(sc[i]!=sc[x]&&sc[k]!=sc[x])anm++;
  }
  cout<<rc*gc*bc-anm<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
long long n;
long long city[6];
long long a[6];

int main(){
	long long min=1000000000000001;
	long long ans=0;
	cin>>n;
	for (int i=1;i<=5;i++){
		cin>>a[i];
		if (a[i]<min) min=a[i];
	}
	ans+=n/min;
	if (n%min!=0) ans++;
	cout<<ans+4<<endl;
	return 0;
}

Measured memory_bytes: 256
abc=['z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y']
abc_n=[26,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
S=""
n=int(input())
for i in range(0, 11):
    if (n//26)>=1:
        S+=abc[n%26]
        n=int((n-abc_n[n%26])/26)
    elif n==0:
        break
    else:
        S+=abc[n%26]
        break
        
print(S[::-1])


Measured memory_bytes: 9228
#include <iostream>

using namespace std;

int linerSearch( const int *S, const int n,  int key ) {
    for ( int i = 0; i < n; ++i ) {
        if ( S[i] == key ) {
            return 1;
        }
    }
    return 0;
}

int main() {
    int n;
    int q;

    int S[10000];
    int T[500];

    int cnt = 0;

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

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

    for ( int i = 0; i < q; ++i ) {
        cnt += linerSearch(S,n,T[i]);
    }

    cout << cnt << endl;
    return 0;

}


Measured memory_bytes: 3124
#include <iostream>

using namespace std;

int main()
{
    int A, B;
    string S, T, U;

    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if (U==S) {A -= 1;}
    else if (U==T) {B -= 1;}

    cout << A << " " << B << endl;

}

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

const int maxn = 200010;
int n, K;
char s[maxn];
deque<char> q;

int main() {
    scanf("%d %d %s", &n, &K, s + 1);
    int pos = 1, cur = s[1] - 'A', cnt = 0;
    while (K--) {
        if (!cur) {
            cur ^= 1, s[pos] = s[pos] == 'A' ? 'B' : 'A';
        } else {
            cnt++, pos++;
            cur = (s[pos] - 'A') ^ (cnt & 1);
        }
        if (pos > n) break;
    }
    if (pos <= n) {
        for (int i = pos; i <= n; i++) {
            printf("%c", 'A' + ((s[i] - 'A') ^ (cnt & 1)));
        }
        for (int i = 1, j = (cnt - 1) & 1; i < pos; i++) {
            printf("%c", 'A' + (j & 1)), j ^= 1;
        }
    } else if ((cnt - 1) & 1) {
        for (int i = 1; i <= n; i++) {
            printf("%c", 'A' + (i & 1));
        }
    } else {
        printf("%c", 'A' + (K & 1));
        for (int i = 1; i < n; i++) {
            printf("%c", 'A' + (i & 1));
        }
    }
    return 0;
}

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

int main() {
	int s;	
	cin >> s;
	
	int h = s / 3600;
	int m = s / 60 % 60;
	int s2 = s % 60;
	cout << h << ":" << m << ":" << s2 << endl;
	
	return 0;
}


Measured memory_bytes: 3128
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
     ll n;
     cin>>n;
     ll hash[100001]={0};
     ll A[n];
     ll s=0;
     for(int i=0;i<n;++i)
     {
     	cin>>A[i];
     	s+=A[i];
     	hash[A[i]]++;
	 }
	 ll q;
	 cin>>q;
	 while(q>0)
	 {
	 	ll x,y;
	 	cin>>x>>y;
	 	if(hash[x]!=0)
	 	{
	 	  hash[y]+=hash[x];
	 	  s=s+((y-x)*(hash[x]));
	 	  cout<<s<<endl;
		   hash[x]=0;
		}
		else
		cout<<s<<endl;
	 	q--;
	 }
    return 0;
}


Measured memory_bytes: 5200
from collections import Counter

N = int(input())
Ss = [input() for _ in range(N)]

C = Counter(Ss)
for s in ["AC", "WA", "TLE", "RE"]:
    if not s in C:
        c = 0
    else:
        c = C[s]
    print("{} x {}".format(s, c))

Measured memory_bytes: 78748
n = input().strip()
n = int(n)
i = list(map(int, input().split()))
i.sort()
bef = i[int((n/2) -1)]
af = i[int(n/2)]
ans = 0
min = af - bef
while(min != 0):
    ans += 1
    min -= 1
print(ans)


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


namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine()
                .Split(' ')
                .Select(x => int.Parse(x))
                .ToArray();
            var n = str[0];
            var y = str[1];
            Money money = null;
            var lists = new List<Money>();
            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j <= n-i; j++)
                {
                    int k = n - j - i;
                    int a = i * 10000 + j * 5000 + k * 1000;
                    if (a == y)
                        money = new Money() { Ichimanen = i, Gosenen = j, Senen = k };
                }
            }

            if (money != null)
                Console.WriteLine(money.Ichimanen + " " + money.Gosenen + " " + money.Senen);
            else
                Console.WriteLine("-1 -1 -1");
            Console.ReadLine();
        }
    }

    class Money
    {
        public int Gosenen = 0;
        public int Ichimanen = 0;
        public int Senen = 0;

        public int Sum()
        {
            return Gosenen * 5000 + Ichimanen * 10000 + Senen * 1000;
        }
    }
}


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

int main() {
  int t, n;
  int price[4] = {6000, 4000, 3000, 2000};
  int i;
  for (i = 0; i < 4; i++) {
    cin >> t >> n;
    cout << price[t - 1] * n << endl;;
  }
  return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <iomanip>

using namespace std;

int debug=1;

//36926037.000000000000

int main(){
    int l;
    cin >> l;
    //double tmp = l * l * l / 27;
    
    double tmp = l * l * l / 27.0;
    
    cout << fixed << setprecision(12) << tmp << endl;

}


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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

int main(){
    int n; cin >> n;
    int a = 0, b = 0, ans = 0, p = 0;
    REP(i, 0, n){
        string s; cin >> s;
        if(s.back() == 'A'){
            a++;      
        }
        if(s[0] == 'B'){
            b++;
        }
        if(s.back() == 'A' && s[0] == 'B'){
            p++;
        }
        REP(l, 0, s.size()){
            if(l+1 < s.size() && s[l] == 'A' && s[l+1] == 'B'){
                ans++;
            }
        }
    }
    if(b < 2 && a < 2 && p == 1){
        cout << ans << endl;
        return 0;
    }
    if(a == p && b == p){
        a--;
    }
    cout << ans + min(max(0, a), b) << endl;
}

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

int main() {
    int a[100],b[100],c[100];
	int sum=0,n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		cin>>b[i];
		sum+=b[i];
	}
	for(int i=1;i<n;i++)
		cin>>c[i];
	for(int i=1;i<n;i++){
		if(a[i]+1==a[i+1])
			sum+=c[a[i]];
	}
	cout<<sum;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <float.h>
typedef long long ll;

int main()
{
    ll x, y;
    ll h, w;

    scanf("%lld %lld", &w, &h);
    scanf("%lld %lld", &x, &y);

    printf("%.*lf ", DBL_DIG, (double)w * (double)h / 2.0);

    if (x == w / 2 &&
        y == h / 2 &&
        w % 2 == 0 &&
        h % 2 == 0) {
        printf("1\n");
    }
    else {
        printf("0\n");
    }

    return 0;
}


Measured memory_bytes: 128
N = int(input())
S = []
for i in range(N):
    S.append(int(input()))
nb10 = ([s for s in S if s%10 != 0])
b10  = ([s for s in S if s%10 == 0])
    
if sum(S)%10!=0:
    print(sum(S))
elif sum(S) ==sum(b10):
    print(0)
else:

    print(sum(S)-sorted(nb10)[0])

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

int main(){
    double A,B;
    cin >> A >> B;
    pair<double, double> a = make_pair(A*12.5, (A+1)*12.5);
    pair<double, double> b = make_pair(B*10, (B+1)*10);
    if(a.second <= b.first) cout << -1 << endl;
    else if(b.second <= a.first) cout << -1 << endl;
    else{
        if(a.first < b.first) cout << b.first << endl;
        else cout << ceil(a.first) << endl;;
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
import itertools
dic={'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
    s=input()
    dic[s[0]]=dic.get(s[0],0)+1
ans=0
pt=['M','A','R','C','H']
for v in itertools.combinations(pt,3):
    ans+=dic[v[0]]*dic[v[1]]*dic[v[2]]
print(ans)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    cout<<t<<s<<endl;
    

    return 0;   
}


 
 


Measured memory_bytes: 256
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

A,B = [0],[0]

for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])

ans,j = 0,m

for i in range(n+1):
    if A[i] > k:
        break
    while B[j] > k - A[i]:
        j -= 1
    ans = max(ans,i+ j)
print(ans)



Measured memory_bytes: 134432
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int n; cin >> n;
    cout << (n%10==n/100 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>

int main() {
	char s[101], t[101];
	scanf("%s%s", s, t);
	int sl = strlen(s), tl = strlen(t);
	std::sort(s, s + sl);
	std::sort(t, t + tl);
	std::reverse(t, t + tl);
	if (std::strcmp(s, t) < 0) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
/* Priyansh Agarwal*/
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define nline "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define debug(x) cout << #x << " " << x <<endl;
#define set_bits __builtin_popcount
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod)
{ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll* fact) {ll val1 = fact[n]; ll val2 = mminvprime(fact[r], m); ll val3 = mminvprime(fact[n - r], m); return ((val1 * val2) % m * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
/*--------------------------------------------------------------------------------------------------------------------------*/
int main()
{
	fastio();
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
	freopen("Error.txt", "w", stderr);
#endif
	ll x, a;
	cin >> x >> a;
	if (x < a)
		cout << 0 << endl;
	else
		cout << 10 << endl;
	return 0;
}


Measured memory_bytes: 3584
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n;
  ll d,a;
  cin >> n >> d >> a;
  vector<pair<ll,ll> > xh(n);
  for(int i=0;i<n;i++){
    cin >> xh[i].first >> xh[i].second;
  }
  sort(xh.begin(),xh.end());
  vector<ll> x(n);
  for(int i=0;i<n;i++) x[i] = xh[i].first;
  vector<ll> e(n);
  vector<int> g(n);
  for(int i=0;i<n;i++){
    g[i] = upper_bound(x.begin(),x.end(),x[i]+2*d)-x.begin()-1;
  }
  for(int i=0;i<n;i++){
    if(i == 0){
      e[0] = (xh[0].second-1)/a+1;
      continue;
    }
    int index = lower_bound(g.begin(),g.end(),i)-g.begin();
    if(index != 0) xh[i].second -= a*(e[i-1]-e[index-1]);
    else xh[i].second -= a*e[i-1];
    e[i] = e[i-1];
    if(xh[i].second > 0){
      e[i] += (xh[i].second-1)/a+1;
    }
  }
  cout << e[n-1] << endl;
  return 0;
}


Measured memory_bytes: 7932
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	int n;
	cin >> n;
	string s[2];
	cin >> s[0] >> s[1];
	for (int i = 0; i < n; i++)
		cout << s[0][i] << s[1][i];
	cout << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


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

using namespace std;

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

    int dig = 0;
    bool flag = true;
    while(N >= 10){
        int a = N % 10;
        if (a != 9){
            flag = false;
        }
        
        N /= 10;
        dig += 1;
    }

    int ans = 9 * dig + N - 1;
    if (flag == true){
        ans++;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import Counter

S = input()
# S = "12345"*40000
N = len(S)

l = [0]*(N+1)
for i in range(N-1, -1, -1):
    l[i] = (l[i+1] + pow(10, N-i, 2019) * int(S[i])) % 2019
    # if i%10000 == 0:
    #     print(i)

# print(list(Counter(l).values()))

r = sum(m*(m-1)//2 for m in Counter(l).values())
print(r)

Measured memory_bytes: 16708
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

int rec(int N, int i, const std::vector<int>& L, int a, int b, int c, int A, int B, int C)
{
    if (i > N) {
        if (a == 0 || b == 0 || c == 0) return 99999999;
        return std::abs(a-A) + std::abs(b-B) + std::abs(c-C) - 30;
    }

    int r0 = rec(N, i+1, L, a, b, c, A, B, C);
    int r1 = rec(N, i+1, L, a + L[i], b, c, A, B, C) + 10;
    int r2 = rec(N, i+1, L, a, b + L[i], c, A, B, C) + 10;
    int r3 = rec(N, i+1, L, a, b, c + L[i], A, B, C) + 10;

    return std::min({r0, r1, r2, r3});
}


int main()
{
    int N, A, B, C;
    std::cin >> N >> A >> B >> C;

    std::vector<int> L(N);
    for (int i = 0; i < N; i++) std::cin >> L[i];

    int ans = rec(N, 0, L, 0, 0, 0, A, B, C);

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

double cost[1010][1010];
double d[1010];
bool used[1010];
int V;

void dijkstra(int s){
	fill(d,d+V,INFl);
	fill(used,used+V,false);
	d[s]=0;
	while(true){
		int v=-1;
		for(int u=0;u<V;u++){
			if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
		}
		if(v==-1)break;
		used[v]=true;
		
		for(int u=0;u<V;u++){
			d[u]=min(d[u],d[v]+cost[v][u]);
		}
	}
}
double xs,ys,xt,yt;
int n;
ll x[1010],y[1010],r[1010];
int main(){
	cin>>x[0]>>y[0]>>xt>>yt;
	r[0]=0;
	cin>>n;
	x[n+1]=xt,y[n+1]=yt;
	r[n+1]=0;
	V=n+2;
	for(int i=1;i<=n;i++)
		cin>>x[i]>>y[i]>>r[i];
	for(int i=0;i<V;i++){
		for(int j=i;j<V;j++){
			double dis2=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
			double rad2=(r[i]+r[j])*(r[i]+r[j]);
			if(dis2<=rad2){
				cost[i][j]=0;
				cost[j][i]=0;
			}else{
				cost[i][j]=sqrt(dis2)-r[i]-r[j];
				cost[j][i]=sqrt(dis2)-r[i]-r[j];
			}
		}
	}
	dijkstra(0);
	printf("%.12f",d[n+1]);
	return 0;
}

Measured memory_bytes: 8192
#include <iostream>

using namespace std;

template <class T> T gcd(T n1, T n2)
{
  if (n1 < n2) {
    T tmp;
    tmp = n1; n1 = n2; n2 = tmp;
  }

  while (n2 != 0) {
    T r;
    r = n1 % n2;
    n1 = n2;
    n2 = r;
    //cout << n1 << ' ' << n2 << endl;
  }
  return n1;
}

int main()
{
  int64_t a, b, c, d, cd, div_c, div_d, div_cd;
  cin >> a >> b >> c >> d;

  div_c = b/c - (a-1)/c;
  div_d = b/d - (a-1)/d;
  cd = c * d / gcd<int64_t>(c, d);
  div_cd = b/cd - (a-1)/cd;

  //cout << div_c << ' ' << div_d << ' ' << cd << ' ' << div_cd << endl;
  cout << b - a + 1 - (div_c + div_d - div_cd) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
int n,m,t;
char ch1[10],ch2[10];
int main()
{
	while(~scanf("%s %s",ch1,ch2)){
		int sum=0;
		for(int i=0;i<strlen(ch1);i++)
		{
			sum=sum*10+ch1[i]-'0';
		}
		for(int i=0;i<strlen(ch2);i++)
		{
			sum=sum*10+ch2[i]-'0';
		}
		int m=(int) sqrt(sum);
		if(m*m==sum) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
from bisect import bisect_right

N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))

ans = 0
for i in range(Q):
  x = bisect_right(S, T[i])
  if(S[x-1] == T[i]):
    ans += 1
    
print(ans)


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

#define ll long long

ll memo[105][100005];

int main() {
	int n, w;
	scanf("%d %d", &n, &w);
	
	int arr[n+5][2];
	
	ll sum = 0;
	for(int i = 1; i <= n; i++) {
		scanf("%d %d", &arr[i][0], &arr[i][1]);
		sum += arr[i][1];
	}
	
	memo[0][0] = 0;
	for(int i = 1; i <= sum; i++) {
		memo[0][i] = (ll)1e13;
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= sum; j++) {
			memo[i][j] = (ll)1e13;
			if(j == 0) {
				memo[i][j] = 0;
			} else if (j-arr[i][1] >= 0) {
				if(memo[i-1][j-arr[i][1]]+arr[i][0] <= w) {
					memo[i][j] = min(memo[i][j], memo[i-1][j-arr[i][1]]+arr[i][0]);
				}
			}
			memo[i][j] = min(memo[i][j], memo[i-1][j]);
//			printf("%lld ", memo[i][j]);
		}
//		printf("\n");
	}
	
	ll maxpos = 0;
	for(int i = 1; i <= sum; i++) {
		if(memo[n][i] != (ll)1e13 && i >= n) {
			maxpos = i;
		}
	}
	printf("%lld\n", maxpos);
//	printf("%lld\n", memo[n][maxpos]);
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    int dp[101][5][5][5][5] = {};
    dp[0][0][0][0][0] = 1;
    REP(i, N){
        REP(j, 5) REP(k, 5) REP(l, 5) FOR(m, 1, 5){
            REP(n, 5) Add(dp[i + 1][j][k][l][m], dp[i][n][j][k][l]);
        }
        REP(j, 5){
            dp[i + 1][j][1][3][2] = 0;
            dp[i + 1][j][3][1][2] = 0;
            dp[i + 1][j][1][2][3] = 0;
            dp[i + 1][1][j][3][2] = 0;
            dp[i + 1][1][3][j][2] = 0;
        }
    }
    int ans = 0;
    REP(j, 5) REP(k, 5) REP(l, 5) REP(m, 5) Add(ans, dp[N][j][k][l][m]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
int main()
{
	int n;
	while (std::cin>>n) {
		int a[4], b[4];
		a[0] = n;
		int eat = 0, bite = 0;
		for (int i = 1; i < 4; i++) {
			std::cin >> a[i];
		}
		for (int i = 0; i < 4; i++) {
			std::cin >> b[i];
		}
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (i == j&&a[i] == b[j]) {
					eat++;
				}
				else if (a[i] == b[j]) {
					bite++;
				}
			}
		}
		std::cout << eat << " " << bite << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

vector < vector<long long> > dp(3005, vector< long long>(3005, 0));
vector <long long> v(3005);

int main()
{
    int n;

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> v[i];

    for (int i = 0; i < n; i++)
        dp[i][i] = v[i];

    for (int i = 1; i < n; i++)
    {
        for (int j = i - 1; j >= 0; j--)
        {
            dp[i][j] = max(v[j] - dp[i][j + 1], v[i] - dp[i - 1][j]);
        }
    }

    cout << dp[ n - 1 ][ 0 ];

    return 0;
}


Measured memory_bytes: 70912
import functools
D, G = map(int, input().split())
G = G // 100
sumn = 0
ns = [0] * (D + 1)
cs = [0] * (D + 1)
for i in range(1, D + 1):
    n, c = map(int, input().split())
    ns[i] = n
    cs[i] = c // 100
    sumn += n

minn = [0] * (D + 1)
for i in range(1, D + 1):
    minn[i] = min(ns[1:i+1])

@functools.lru_cache(maxsize=None)
def f(i, rn):
    if i == 1:
        if ns[1] < rn:
            return -1
        p = rn
        if ns[1] == rn:
            p += cs[1]
        return p
    if rn < minn[i]:
        p = 0
        for j in range(i, 0, -1):
            n = min((ns[j], rn))
            p += j * n
            if n == rn:
                break
            rn -= n
        return p
    maxp = 0
    for n in range(min((ns[i], rn)) + 1):
        p = i * n
        if n == ns[i]:
            p += cs[i]
        np = f(i - 1, rn - n)
        if np >= 0:
            p += np
            if maxp < p:
                maxp = p
    return maxp

mn = 1
mx = sumn
while mn < mx:
    x = mn + ((mx - mn) // 2)
    if G <= f(D, x):
        mx = x
    else:
        mn = x + 1
print(mn)


Measured memory_bytes: 5524
import java.util.*;

class Main {
    public static int canDivide(int a, int b) {
      return (b % a == 0) ? a + b : b - a;
    }
	public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      
      String line = scanner.nextLine();
      String[] values = line.split(" ", 0);
      
      int a = Integer.parseInt(values[0]);
      int b = Integer.parseInt(values[1]);
      
      System.out.println(canDivide(a, b));
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4005;
int n,R[N],G[N],B[N];
char s[N];
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=n;i>=1;i--)
    {
        R[i]=R[i+1]+(s[i]=='R');
        G[i]=G[i+1]+(s[i]=='G');
        B[i]=B[i+1]+(s[i]=='B');
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
    {
        if(s[i]==s[j]) continue;
        if(s[i]!='R'&&s[j]!='R') ans+=R[j+1];
        if(s[i]!='G'&&s[j]!='G') ans+=G[j+1];
        if(s[i]!='B'&&s[j]!='B') ans+=B[j+1];
        if(j+j-i<=n&&s[j+j-i]!=s[i]&&s[j+j-i]!=s[j])
            ans--;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define MAX 1000000
#define INF 1000000000
using namespace std;

int main()
{
	vector<int> dp(MAX, INF), res(MAX, INF), four, odd;
	for (int i = 1; i * (i + 1) * (i + 2) / 6 < MAX; i++) {
		four.push_back(i * (i + 1) * (i + 2) / 6);
		if (i * (i + 1) * (i + 2) / 6 % 2)
			odd.push_back(i * (i + 1) * (i + 2) / 6);
	}
	dp[0] = res[0] = 0;
	for (int j = 0; j < MAX; j++) {
		if (dp[j] != INF) {
			for (int k = 0; k < four.size() && j + four[k] < MAX;k++) {
				dp[j + four[k]] = min(dp[j + four[k]], dp[j] + 1);
			}
		}
	}
	for (int j = 0; j < MAX; j++) {
		if (res[j] != INF) {
			for (int k = 0; k < odd.size() && j + odd[k] < MAX; k++) {
				res[j + odd[k]] = min(res[j + odd[k]], res[j] + 1);
			}
		}
	}
	int n;
	ios::sync_with_stdio(false);
	while (cin >> n, n) {
		cout << dp[n] << ' ' << res[n] << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
        ll N, a, b;
        cin>>N>>a>>b;
        vector <ll> x;
        for(ll i=0;i<N;i++){
                ll xx;
                cin>>xx;
                x.push_back(xx);
        }
        ll res=0;
        for(int i=1;i<N;i++){
                if(a*(x[i]-x[i-1])<b){
                        res+=a*(x[i]-x[i-1]);
                }
                else{
                        res+=b;
                }
        }
        cout<<res<<endl;
        return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 5e2 + 5;

int v[MAXN][MAXN];

void solve(){
	int N, M, n, m;
	scanf("%d%d%d%d", &N, &M, &n, &m);
	if (N % n == 0 && M % m == 0){
		printf("No\n");
		return;
	}
	printf("Yes\n");
	REP(i, 0, N){
		REP(j, 0, M){
			if (i % n == 0 && j % m == 0){
				v[i][j] = INF - 1;
			}
			if (i % n == n - 1 && j % m == m - 1){
				v[i][j] = -INF;
			}
		}
	}
	REP(i, 0, N){
		REP(j, 0, M){
			printf("%d ", v[i][j]);
		}
		putchar('\n');
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <stdio.h>

struct Node {
    int key;
    Node *parent, *left, *right;
};

int n;
Node *root, *NIL;

void insert ( int val ) {
    Node *x = root;
    Node *y = NIL;
    Node *z;
    
    z = new Node();
    z->key = val;
    z->left = NIL;
    z->right = NIL;
    
    while (x != NIL) {
        y = x;
        if ( x->key > z->key) {
            x = x->left;
        } else if ( x->key <= z->key ) {
            x = x->right;
        }
    }
    
    z->parent = y;
    if (z->parent == NIL) {
        root = z;
    } else if ( z->key < y->key) {
        y->left = z;
    } else if ( z->key >= y->key ) {
        y->right = z;
    }
    
//    delete z;
}


void inorder( Node *u ) {
    if ( u == NIL ) return;
    
    inorder( u->left );
    printf( " %d", u->key );
    inorder( u->right );
}

void preorder( Node *u ) {
    if ( u == NIL ) return;
    
    printf(" %d", u->key);
    preorder( u->left );
    preorder( u->right );
}

void print() {
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
}

int main() {
    char moji[10];
    int val;
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", moji);
        if (moji[0] == 'i') {
            scanf("%d", &val);
            insert(val);
        } else if (moji[0] == 'p') {
            print();
        }
    }
    
    
    return 0;
}



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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,l;
    cin>>n>>l;
    Vi a(n);
    vin(a);

    int last=-1;
    REP(i,0,n-1){
        if(a[i]+a[i+1]>=l) last=i+1;
    }
    if(last==-1) cout<<"Impossible"<<endl;
    else{
        cout<<"Possible"<<endl;
        REP(i,1,last) cout<<i<<endl;
        REPR(i,n-1,last) cout<<i<<endl;
        cout<<last<<endl;
    }
    return 0;
}


Measured memory_bytes: 1664
use proconio::input;

fn main() {
    input! {
        n: usize, m: usize,
        a: [usize; n],
    }
    let total: usize = a.iter().sum();
    let limit = total as f64 / (4 * m) as f64;
    let mut cnt = 0;
    for i in 0..n {
        if a[i] as f64 >= limit {
            cnt += 1;
        }
    }
    if cnt >= m {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2164