akhauriyash/Code-Regression huggingface dataset:
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[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int t = Integer.parseInt(sa[1]);
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]);
			int b = Integer.parseInt(sa[1]);
			if (b <= t) {
				ans = Math.min(ans, a);
			}
		}
		br.close();

		if (ans == Integer.MAX_VALUE) {
			System.out.println("TLE");
		} else {
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
void findNumberOfDigits(long n, long base)
{

    long dig = (long)(floor( log(n) /log(base)) + 1);
    cout<< dig<<endl;
}
int main()
{
    long n,base;
    cin>>n>>base;
    findNumberOfDigits(n, base);
    return 0;
}


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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);
ll modpow(ll, ll, ll);
ll com(ll, ll);
ll modinv(ll, ll);

/*
const int MAX = 1e9 + 10;

ll fact[MAX], fact_inv[MAX];

// 繰り返し二乗法
ll power(ll a, ll b) {
    ll res = 1;
    while(b > 0) {
        if(b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

ll comb(ll n, ll r) {
    return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}
*/

//================ Main Loop ================
int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = modpow(2, n, MOD);
    ans--;
    if(ans < 0) ans += MOD;
    /*
    fact[0] = 1;
    // 階乗の計算
    rep(i, n)
        fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_inv[n] = power(fact[n], MOD - 2);
    // 逆元の計算
    for(int i = n - 1; i >= 0; i--)
        fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
    // nCrの計算
    ll rm = comb(n, a) + comb(n, b);
    */
    ll rm = com(n, a) + com(n, b);
    rm %= MOD;
    ans -= rm;
    if(ans < 0) ans += MOD;
    cout << ans << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll com(ll n, ll r) {
    ll res = 1;
    for(int k = 1; k <= r; k++) {
        res = res * (n - (k - 1)) % MOD;
        res = res * modinv(k, MOD) % MOD;
    }
    return res;
}

ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}

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

using namespace std;

typedef long long int ll;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main() {

    fastio();

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

    int x,y, count = 0;
    while(n--)
    {
        cin >> x >> y;
        ll xs = (ll)x*x;
        ll ys = (ll)y*y;

        double dist = (double) sqrt(xs + ys);

        if(dist <= d) count++;
    }

    cout << count << "\n";

    return 0;
}

Measured memory_bytes: 3688
#include <iostream>
using namespace std;
int main(void){
    int k, len;
    long long ans = 0;
    string s;
    cin >> s >> k;
    len = s.length();
    if(k == 1){
        for(int i=1;i<len;i++){
            if(s[i] == s[i-1]){
                ans++;
                s[i] = '.';
            }
        }
    }else{
        int u = -1;
        for(int i=1;i<len;i++){
            if(s[i] != s[i-1]){
                u = i;
                break;
            }
        }
        if(u == -1){
            ans = (long long)k*len;
            ans /= 2;
        }else{
            long long v = 0, w = 0;
            string t = s + s;
            for(int i=1;i<len;i++){
                if(t[i] == t[i-1]){
                    v++;
                    i++;
                }
            }
            for(int i=1;i<len*2;i++){
                if(t[i] == t[i-1]){
                    w++;
                    i++;
                }
            }
            ans = (w-v) * (k-1) + v;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト
#define DEBUG_

typedef long long ll;
const double EPS = 1e-9;
const ll INF = ((1LL<<62)-(1LL<<31));
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
template<typename T, typename U> using mapv = map<T,vector<U>>;

#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define contains(S,x) find(ALL(S),x) != S.end()
ll llceil(ll a,ll b) { return (a+b-1)/b; }
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; }
template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); }

///// DEBUG
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");}
os<<"}";return os;}
template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;}
os<<"}";return os;}
template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;}
os<<"}";return os;}
void dump_func(){DUMPOUT<<endl;}
template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";}
dump_func(std::move(tail)...);}
#ifndef LOCAL
#undef DEBUG_
#endif
#ifdef DEBUG_
#define DEB
#define dump(...)                                                          \
DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
        << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
        << endl                                                            \
        << "    ",                                                         \
    dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

//////////

int main() {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

    ll N; string S;
    cin>>N>>S;

    auto dp = genarr(N+10,N+10,0LL);
    ll ans = 0;

    rep(i,N) {
        rep(j,N) {
            if (S[i] != S[j]) continue; 

            chmax(dp[i+1][j+1],dp[i][j]+1);
            if (dp[i+1][j+1] <= j-i && i<j) {
                chmax(ans,dp[i+1][j+1]);
            }
        }
    }

    dump(dp);

    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 199680
package main

import (
	"fmt"
	"sort"
)

func main() {
	s := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&s[i])
	}

	sort.Ints(s)
	fmt.Println(s[0] + s[1])
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i < n - 2; i++) {
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;

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

	ll n;
	cin >> n;
	if (n == 2) {
		cout << 1 << '\n'; return 0;
	}
	ll tmp = n - 1;
	ll ans = 1;
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			if (n / i != i) {
				ll cnt = n / i;
				while (cnt %i == 0)cnt /= i;
				if (cnt % i == 1) {
					ans += 1;
				}
			}
			else if (n / i == i) {
				ans += 1;
			}
		}
	}
	// 3 , 4 2
	ans += 1;
	for (ll i = 2; i * i <= tmp; i++) {
		if (tmp % i == 0) {
			if (tmp / i == i) { ans += 1; }
			else
				ans += 2;
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
a, b = input().split()

a_1 = int(a)

b_1 = int(b[0])*100
b_10 = int(b[2])*10
b_100 = int(b[3])

ans = a_1 * b_1
ans += (a_1 * b_10)
ans += (a_1 * b_100)

print(ans//100)

Measured memory_bytes: 9184
// kid_kb //
	
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ull unsigned long long int
#define lower(str) transform(str.begin(),str.end(),str.begin(),::tolower);
#define upper(str) transform(str.begin(),str.end(),str.begin(),::toupper);
#define mod 1000000007
#define SORT(vec) sort(vec.begin(),vec.end());
#define pb push_back
#define csb __builtin_popcount
#define msb(n) (ll)(log2(n))
#define DIG(n) floor(log10(n))+1
#define kb ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ptr(arr) for(auto i:arr)cout<<i<<" ";
#define ptr2(vec) for(auto i:vec){for(auto j: i){cout<<j<<" ";}cout<<endl;}
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mem(a,val) memset(a,val,sizeof(a))
//cout<<fixed<<setprecision(8)<<endl;
	
void solve(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;

	ll a1=a*d;
	ll a2=a*c;
	ll a3=b*d;
	ll a4=b*c;

	cout<<max({a1,a2,a3,a4})<<endl;
}
int main()
{
	kb
	ll t;
	t=1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



Measured memory_bytes: 3664
str = gets.chomp
q = gets.to_i

q.times do
    order, a, b, rep = gets.split
    f = a.to_i
    t = b.to_i
    case
    when order == "print"
        puts str[f..t]
    when order == "reverse"
        tmp1 = f > 0 ? str[0...f] : ""
        tmp2 = str[f..t].reverse
        tmp3 = (t + 1) <= (str.size - 1) ? str[(t + 1)..(str.size - 1)] : ""
        str = tmp1 + tmp2 + tmp3
    when order == "replace"
        tmp1 = f > 0 ? str[0...f] : ""
        tmp2 = (t + 1) <= (str.size - 1) ? str[(t + 1)..(str.size - 1)] : ""
        str = tmp1 + rep + tmp2
    end
end


Measured memory_bytes: 9096
n=int(input())
A=[int(i) for i in input().split()]
dp=1

for i in range(n):
    now=A[i]
    dp=dp|(dp<<now)

for i in range((sum(A)+1)//2,sum(A)+1):
    if dp&(1<<i)>0:
        print(i)
        break

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

int main() {
  int H,W;
  cin>>H>>W;
  int C[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>C[i][j];
    }
  }
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        if(C[i][j]>C[i][k]+C[k][j]) C[i][j]=C[i][k]+C[k][j];
      }
    }
  }
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        if(C[i][j]>C[i][k]+C[k][j]) C[i][j]=C[i][k]+C[k][j];
      }
    }
  }  
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        if(C[i][j]>C[i][k]+C[k][j]) C[i][j]=C[i][k]+C[k][j];
      }
    }
  }   
  int temp;
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>temp;
      if(temp != -1) ans+=C[temp][1];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCoder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;



//繰り返し2乗法
//N^aの、Mで割った余りを求める。
//M = 1000000007 (1e9 + 7) など。
//M = 1000000009 (1e9 + 9) もある。
//M = 998244353 もある。

ll my_pow(ll N, ll a, ll M) {
	ll tempo;
	if (a == 0) {
		return 1;
	}
	else {
		if (a % 2 == 0) {
			tempo = my_pow(N, a / 2, M);
			return (tempo * tempo) % M;
		}
		else {
			tempo = my_pow(N, a - 1, M);
			return (tempo * N) % M;
		}
	}
}




signed main() {
	int N; cin >> N;
	vector<int> A(N);
	rep(i, N) cin >> A.at(i);

	bool able = true;
	vector<int> position(N);

	rep(i, N) {
		position.at(A.at(i))++;
	}

	if (N % 2 == 1) {
		if (!position.at(0) == 1) able = false;
		if (N != 1 && able) {
			for (int i = 1; i < N; i++) {
				if (i % 2 == 1 && position.at(i) != 0) {
					able = false;
					break;
				}
				if (i % 2 == 0 && position.at(i) != 2) {
					able = false;
					break;
				}
			}
		}
		
	}
	else {
		for (int i = 0; i < N; i++) {
			if (i % 2 == 0 && position.at(i) != 0) {
				able = false;
				break;
			}
			if (i % 2 == 1 && position.at(i) != 2) {
				able = false;
				break;
			}
		}
	}

	if (!able) cout << 0 << endl;
	else {
		ll res = my_pow(2, N / 2, large_P);
		cout << res << endl;
	}

}

Measured memory_bytes: 1792
#include <iostream>

int main(){
  int mini = 100;
  int maxi = 1;
  

  for(int i=0;i<3;i++){
     int t;
     std::cin>>t;
      mini = mini  < t ? mini : t;
      maxi = maxi < t ? t: maxi;
    }
   std::cout << maxi - mini;


  return 0;
}

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

int main() {
    int a, b, i, c=0;
    cin >> a >> b;

    for (i=a; i<=b; i++) {
        if((i%10)==(i/10000)&&(i/10)%10==(i/1000)%10) c++;
    }
    cout << c << endl;
}

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

int main(){
	int max,min;
	int ten,sum;
	int n;
	
	while(cin>>n,n!=0){
		max=0;min=1000;
		for(int i=0;i<n;i++){
			sum=0;
			for(int j=0;j<5;j++){
				cin>>ten;
				sum+=ten;
			}
			if(max<sum)max=sum;
			if(min>sum)min=sum;
		}
		cout<<max<<" "<<min<<endl;
	
	}


}

Measured memory_bytes: 1164
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int scan; // scanf result
  ull n; // to input 
  ull amount;
  ull count;

  scan = scanf("%llu", &n);
  amount = 100;
  count = 0;
  while (amount < n)
  {
    amount *= (1 + 0.01);
    count++;
  }
   
  printf("%llu", count); 
  return (0);
}


Measured memory_bytes: 1736
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;



signed main(){
    int a,b;
    cin >> a >> b;
    cout << (a+b)/2 << endl;
}


Measured memory_bytes: 3100
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
A_cards = []
B_cards = []
flag = 'A'
for card in A:
    if flag == 'A':
        flag = 'B'
        A_cards.append(card)
    elif flag == 'B':
        flag = 'A'
        B_cards.append(card)
print(sum(A_cards) - sum(B_cards))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define boost  ios_base::sync_with_stdio(0);
#define N 1000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define fo(i,a,b) for(i = a; i < b; i++)
#define foe(i, a,b) for(i = a; i <= b; i++)
#define tc long long int t; cin >> t; while(t--)
#define vect vector <ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll>>
#define be begin
#define en end

int main(){
    boost;
    ll i;
    ll n,k;
    cin >> n >> k;
    ll w[n],v[n];
    ll e = 0;
    for(i=0;i<n;i++){
        cin >> w[i] >> v[i];
        e+=v[i];
    }
    ll dp[e+1];
    for(i=0;i<=e;i++){
        dp[i]=1000000000000;
    }
    dp[0]=0;
    ll j;
    for(i=0;i<n;i++){
        for(j=e-v[i];j>=0;j--){
            dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
        }
    }
    ll ans=0;
    for(i=0;i<=e;i++){
        if(dp[i]<=k){
            ans=max(ans,(ll)i);
        }
    }
    cout<<ans << endl;;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int n,m,a[20000]={},i,sum=0,ans=0;
    char token[100000]={};
    fgets(token, sizeof(token), stdin);
    n=atoi(strtok(token, " "));m=atoi(strtok(NULL, " "));
    fgets(token, sizeof(token), stdin);
    a[0]=atoi(strtok(token, " "));
    for (i=1; i<m; i++) a[i]=atoi(strtok(NULL, " "));
    for (i=0; i<m; i++) sum+=a[i];
    ans=n-sum;
    if(ans<0) printf("%d", -1);
    else printf("%d",ans);
    return 0;
}



Measured memory_bytes: 1880
# 2019 6/12
# ABC129 C Typical Stairs
# fn: ways from 0 to n
# f(n) = f(n-1) + f(n-2)
# DP

import sys

N, M = list(map(int, input().split()))
if M > 0:
    broken = set(map(int, sys.stdin))
else:
    broken = set()

dp = [0] * (N + 1)

dp[0] = 1
dp[1] = 1 if 1 not in broken else 0

MOD = 10 ** 9 + 7

for i in range(2, N + 1):
    if i in broken:
        continue
    dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

print(dp[N])

Measured memory_bytes: 11884
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);
            int iK = int.Parse(sS[2]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            for(int i = 0; i < iK; i++)
            {
                if (i % 2 == 0) { iB += iA / 2; iA = iA / 2; }
                else { iA += iB / 2; iB = iB / 2; }
            }

            // 出力
            System.Console.WriteLine("{0} {1}", iA.ToString().Trim(), iB.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll a,b,c,x,y; cin >> a>>b>>c>>x>>y;
    ll dif = max(x,y) - min(x,y);
    ll res = a*x+b*y;
    res = min(res,max(x,y)*2*c);
    if(x > y)res = min(res,min(x,y)*2*c+a*dif);
    else res = min(res,min(x,y)*2*c+b*dif);
    out(res);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  while (1) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  return 0;
}


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

string s;
char f[2] = { 'L','R' };

int main()
{
	cin >> s;
	for (size_t i = 0; s[i]!='\0'; i++)
	{
		if (s[i] == f[i % 2])
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int top, s[1000];

void push(int x){
  s[++top] = x;
}

int pop(){
  top--;
  return s[top+1];
}

int main(){
  int a, b;
  top = 0;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(a + b);
    } else if ( s[0] == '-' ){
      b = pop();
      a = pop();
      push(a-b);
    } else if ( s[0] == '*' ){
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n", pop());

  return 0;
}


Measured memory_bytes: 2684
sa = list(input())
sb = list(input())
sc = list(input())
turn = "A"
while len(sa) >= 0 and len(sb) >= 0 and len(sc) >= 0:
    if turn == "A":
        if len(sa) == 0:
            break
        turn = sa.pop(0).upper()
    elif turn == "B":
        if len(sb) == 0:
            break
        turn = sb.pop(0).upper()
    else:
        if len(sc) == 0:
            break
        turn = sc.pop(0).upper()

print(turn)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	int n=s.size();
	cout<<s.substr(0,n-8)<<endl;
}



Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int a[] = new int[4];
		for (int i=0;i<s.length();i++ ) {
			switch (s.charAt(i)) {
			case  'N': a[0]++;break;
			case  'E': a[1]++;break;
			case  'S': a[2]++;break;
			case  'W': a[3]++;break;
			}
		}
		if ((a[0]>0&&a[2]>0)||(a[0]==0&&a[2]==0)) {
			if ((a[1]>0&&a[3]>0)||(a[1]==0&&a[3]==0)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			System.out.println("No");
		}
		return ;
	}
}

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

int main()
{
	int k, s, x, y, z, ans=0;
	cin >> k >> s;
	for (x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			z = s - x - y;
			if (z < 0 || k < z) continue;
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
n=int(input())
l=len(str(n))
dp=[[0]*9 for i in range(9)]
count=0
for i in range(1,n+1):
    x,y=int(str(i)[0]),int(str(i)[-1])
    if x!=0 and y!=0:
        dp[x-1][y-1]+=1
for i in range(9):
    for j in range(9):
        count+=dp[i][j]*dp[j][i]
print(count)

Measured memory_bytes: 40684
a = input()
b = input()

tmp1 = len(a)
tmp2 = len(b)

s = ''

if tmp1 > tmp2:
    for i in range(tmp1):
        if i+1 == tmp1:
            s += a[i]
        else:
            s += a[i]
            s += b[i]
else:
    for i in range(tmp2):
            s += a[i]
            s += b[i]

print(s)

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

int linearSearch(int *,int);

int n;

int main(){
  int q,s[10000],t[500],i,j,count;

  count = 0;
  
  scanf("%d",&n);
  if(n < 1 || 10000 < n)exit(0);
  for(i = 0; i < n; i++){
    scanf("%d",&s[i]);
    if(s[i] < 0 || 1000000000 < s[i])exit(0);
  }
  
  scanf("%d",&q);
  if(q < 1 || 500 < q)exit(0);
  for(i = 0; i < q; i++){
    scanf("%d",&t[i]);
    if(t[i] < 0 || 1000000000 < t[i])exit(0);
  }
  
  for(i = 0; i < q; i++){
    for(j = 0; j < q; j++){
      if(i == j)continue;
      if(t[i] == t[j])exit(0);
    }
  }
  for(i = 0; i < q; i++){
    if(linearSearch(s,t[i]) == 1)count++;
  }
  printf("%d\n",count);
  
  return 0;
}

int linearSearch(int *s , int t){
  int i;
  
  for(i = 0; i < n; i++){
    if(s[i] == t)return 1;
  }
  
  return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n, sum = 0;
	cin >> n;
	vector<int> l(n);
	for (int i = 0; i < n; i++){
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	for (int i = 0; i < n-1; i++){
		sum += l[i];
	}
	if (sum > l[n-1]) cout << "Yes" << endl;
	else cout << "No" << endl;
 	return 0;
 }

Measured memory_bytes: 256
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()


yn = {False: 'No', True: 'Yes'}
YN = {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():
    N = I()
    ans = 0

    for i in range(1, N+1):
        if i % 3 == 0:
            pass
        elif i % 5 == 0:
            pass
        elif i % 5 == 0 and i % 3 == 0:
            pass
        else:
            ans += i

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69036
using System;
namespace pro
{




    class MainClass
    {
        public static void Main()
        {

            string s = Console.ReadLine();
            bool b = true;
            
            for (int i =0;i< s.Length-1; i += 2)
            {
                if (s[i] == 'R'|| s[i] == 'U' || s[i] == 'D' )
                {
                  
                }
                else
                {
                    b = false;
                }
            }
            for (int i = 1; i < s.Length - 1; i += 2)
            {
                if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
                {

                }
                else
                {
                    b = false;
                }
            }
            if (s.Length == 1 && s[0] == 'L')
            {
                Console.WriteLine("No");
            }
            else if (b)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }





        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return 
#define endl         "\n" 

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(l,r)     ((l)+((r)-(l))/2) 

#define fo(i,a,b)    for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

int n,k;
const ll maxn = 2e5+5;
ld a[maxn+5];

bool apxeq(double a, double b, double absEpsilon = 1e-12,
           double relEpsilon = 1e-8) {
  // Check if the numbers are really close -- needed when comparing numbers near
  // zero.
  double diff = abs(a - b);
  if (diff <= absEpsilon)
    return true;
    re false;
}

bool pos(ld len){
    ll req = 0;
    fo(i,0,n-1){
        ld q = a[i]/len;
        req += ceil(q-1);
        if(req>k)re 0;
    }
    re 1;
}

void solve()
{
    rd(n,k);
    read(a,n);
    ld l=1;
    ld r = 0;
    for(int i=0;i<n;i++)r = max(r,(ld)a[i]);
    ld m = l+(r-l)/2;
    ld ans = r;
    
    while(l<=r and r-l>0.1 and m>=1){
        m = mid(l,r);
        if(pos(m)){
            ans = m;
            r = m - 0.5;
        }
        else{
            l = m + 0.5;
        }
        m = mid(l,r);
    }
    ll realans = round(ans);
    cout<<realans<<endl;
}


void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    return 0;
}

Measured memory_bytes: 6868
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

template <class F>
int min_element(int i0, int i1, F f) {
    auto m = f(i0);
    int j = i0;
    for (int i = i0 + 1; i < i1; i++) {
        auto t = f(i);
        if (t < m) m = t, j = i;
    }
    return j;
}

int main() {
    int a[50], b[50], c[50], d[50];
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int j = 0; j < m; j++) {
        cin >> c[j] >> d[j];
    }

    for (int i = 0; i < n; i++) {
        int j = min_element(0, m, [&](int j) {
            return abs(a[i] - c[j]) + abs(b[i] - d[j]);
        });
        cout << j + 1 << '\n';
    }

    return 0;
}


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

int main()
{
    int N,M,i,c=0;
    double x,sum=0;
    cin>>N>>M;

    int a[N];
    for(i=1; i<=N; i++)
    {
        cin>>a[i];;
        sum+=(double)a[i];
    }

    x=sum/(4*M);

    for(i=1; i<=N; i++)
    {
        if(a[i]>=x)
        {
            c++;
            if(c==M)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;

    cout << (n - 1) / 2 << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
from heapq import *
n=int(input())
s=[[]for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
def f(a):
    p=[float("INF")for i in range(n+1)]
    p[a],q=0,[[0,a]]
    while q:
        i,j=heappop(q)
        for w in s[j]:
            if p[w]>i+1:
                p[w]=i+1
                heappush(q,[i+1,w])
    else:
        return p[1:]
s1,t1=f(1),f(n)
a,b=0,0
for i in range(n):
    if s1[i]<=t1[i]:
        a+=1
    else:
        b+=1
print("Fennec" if a>b else "Snuke")

Measured memory_bytes: 32208
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect


def solve():
    n, k = map(int, input().split())
    al = [int(i) for i in input().split()]

    ans = sum(abs(i) for i in al)
    flag0 = 0 in al
    if flag0:
        k -= 1
        n -= 1
        if k == 0:
            print(0)
            return
        al.remove(0)
    nc = bisect.bisect_left(al, 0)
    for i in range(n):
        if i < 0 or i + k - 1 >= n:
            break
        if al[i] < 0 and al[i + k - 1] < 0:
            t1 = abs(al[i])
        else:
            t1 = min(abs(al[i]) * 2 + abs(al[i + k - 1]),
                     abs(al[i]) + abs(al[i + k - 1]) * 2)
        if al[i] > 0 and al[i + k - 1] > 0:
            t2 = abs(al[i + k - 1])
        else:
            t2 = min(abs(al[i]) * 2 + abs(al[i + k - 1]),
                     abs(al[i]) + abs(al[i + k - 1]) * 2)
        t = min(t1, t2)
        ans = min(ans, t)
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 62800
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int line[][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}};

int main()
{
    for(;;){
        vector<int> a(10);
        for(int i=0; i<10; ++i){
            cin >> a[i];
            if(a[i] == -1)
                return 0;
        }

        vector<int> b(10);
        for(int i=0; i<10; ++i)
            b[i] = i + 1;

        int ret = 0;
        do{
            bool ng = false;
            for(int i=0; i<10; ++i){
                if(a[i] != 0 && a[i] != b[i])
                    ng = true;
            }
            if(ng)
                continue;

            vector<int> sum(10, 0);
            for(int i=0; i<8; ++i){
                int tmp = 0;
                for(int j=0; j<3; ++j)
                    tmp += b[line[i][j]];
                ++ sum[tmp % b[9]];
            }
            if(count(sum.begin(), sum.end(), 0) == 9)
                ++ ret;
        }while(next_permutation(b.begin(), b.end()));

        cout << ret << endl;
    }
}

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

#define int ll
#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

ll pow(ll x, ll y) {
	if(y == 0)
	return 1;
	ll temp = pow(x, y/2);
	temp = (temp*temp);
	if(y%2 == 1)
		temp *= x;
	return temp;
}

int32_t main() {
	int n;
	string s;
	cin >> n >> s;
	// vvi pref(n, vi(3, 0));
	// vvi suff(n, vi(3, 0));
	int pref[3] = {0}, suff[3] = {0};
	for(int i = 1; i < n; i++) {
		if(s[i] == 'R')
			suff[0] += 1;
		else if(s[i] == 'G')
			suff[1]++;
		else
			suff[2]++;
	}
	int res = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'R') {
			res += pref[1]*suff[2] + pref[2]*suff[1];
			for(int j = 1; ; j++) {
				if(i + j >= n || i - j < 0)
					break;
				if(s[i + j] == 'G' && s[i - j] == 'B')
					res--;
				if(s[i + j] == 'B' && s[i - j] == 'G')
					res--;
			}
			pref[0]++;
			if(i + 1 < n) {
				if(s[i + 1] == 'R')
					suff[0]--;
				else if(s[i + 1] == 'G')
					suff[1]--;
				else
					suff[2]--;
			}
		}
		if(s[i] == 'G') {
			res += pref[0]*suff[2] + pref[2]*suff[0];
			for(int j = 1; ; j++) {
				if(i + j >= n || i - j < 0)
					break;
				if(s[i + j] == 'R' && s[i - j] == 'B')
					res--;
				if(s[i + j] == 'B' && s[i - j] == 'R')
					res--;
			}
			pref[1]++;
			if(i + 1 < n) {
				if(s[i + 1] == 'R')
					suff[0]--;
				else if(s[i + 1] == 'G')
					suff[1]--;
				else
					suff[2]--;
			}
		}
		if(s[i] == 'B') {
			res += pref[1]*suff[0] + pref[0]*suff[1];
			for(int j = 1; ; j++) {
				if(i + j >= n || i - j < 0)
					break;
				if(s[i + j] == 'G' && s[i - j] == 'R')
					res--;
				if(s[i + j] == 'R' && s[i - j] == 'G')
					res--;
			}
			if(i + 1 < n) {
				if(s[i + 1] == 'R')
					suff[0]--;
				else if(s[i + 1] == 'G')
					suff[1]--;
				else
					suff[2]--;
			}
			pref[2]++;
		}
	}
	cout << res;
}


Measured memory_bytes: 3640
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

string S;
vector<int> vec;

int N, K;
int A[1 << 18], B[1 << 18];

// (pos, 合計, 差分)
long long mod = 998244353;
long long dp[309][309][309];
long long ru1[309][309][309];
long long ru2[309][309][309];

void init(int pos) {
	for (int i = 0; i <= 300; i++) {
		for (int j = 0; j <= 300; j++) {
			if (i >= 1) ru1[pos][i][j] = ru1[pos][i - 1][j];
			ru1[pos][i][j] += dp[pos][i][j];
			if (ru1[pos][i][j] >= mod) ru1[pos][i][j] -= mod;
			if (i >= 1 && j >= 1) ru2[pos][i][j] = ru2[pos][i - 1][j - 1];
			ru2[pos][i][j] += dp[pos][i][j];
			if (ru2[pos][i][j] >= mod) ru2[pos][i][j] -= mod;
		}
	}
}

void solve(int pos, int sum, int diff) {
	// 自分の方が少ない場合
	long long b1 = ru1[pos - 1][sum][diff];
	long long b2 = 0; if (sum - A[pos] >= 0) b2 = ru1[pos - 1][sum - A[pos]][diff];
	dp[pos][sum][diff] += (b1 - b2 + mod) % mod;

	// 自分の方が多い場合
	if (sum - A[pos] >= 0) {
		long long c1 = ru2[pos - 1][sum - A[pos]][diff];
		dp[pos][sum][diff] += c1;
	}
	dp[pos][sum][diff] %= mod;
}

int main() {
	// 入力
	cin >> S >> K;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '0') vec.push_back(i);
	}
	if (vec.size() == 0) {
		cout << "1" << endl;
		return 0;
	}

	// 前準備
	A[1] = vec[0];
	for (int i = 0; i < (int)vec.size() - 1; i++) {
		A[i + 2] = vec[i + 1] - vec[i] - 1;
	}
	A[vec.size() + 1] = S.size() - 1 - vec[vec.size() - 1];
	N = vec.size() + 1;

	// 累積和
	for (int i = 1; i <= N; i++) B[i] = B[i - 1] + A[i];

	// DP の計算
	dp[0][0][0] = 1; init(0);
	for (int i = 1; i <= N; i++) {
		for (int j = B[i]; j <= B[N]; j++) {
			for (int k = 0; k <= B[N]; k++) {
				solve(i, j, k);
			}
		}
		init(i);
	}

	// 答え
	long long Answer = 0;
	for (int i = 0; i <= min(B[N], K); i++) {
		Answer += dp[N][B[N]][i];
		Answer %= mod;
	}
	cout << Answer << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<ll,int> P; 

int H,W;
ll p;
int main(){
	cin >> W >> H;
	vector<P> v(W+H);
	for(int i=0;i<W+H;i++){
		cin >> p;
		if(i<W) v[i] = P(p,1);
		else v[i] = P(p,-1);
	}
	sort(v.begin(),v.end());
	int X = H+1,Y = W+1;
	ll ans = 0;
	int i = 0;
	while(X>0 && Y>0 && i<H+W){
		if(v[i].second==1 && X>0){
			ans += v[i].first*X;
			Y--;
		}else if(v[i].second==-1 && Y>0){
			ans += v[i].first*Y;
			X--;
		}
		i++;
	}
	cout << ans << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    vector<int> city(N);
    
    for(int i=0; i<M; i++){
        cin >> a.at(i) >> b.at(i);
        city.at(a.at(i)-1)++;
        city.at(b.at(i)-1)++;
    }
    for(int i=0; i<N; i++) cout << city.at(i) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 2e5+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 256
public class Main {


  private static void solve() {
    int n = ni();
    if (n == 25) {
      System.out.println("Christmas");
    } else if (n == 24) {
      System.out.println("Christmas Eve");
    } else if (n == 23) {
      System.out.println("Christmas Eve Eve");
    } else if (n == 22) {
      System.out.println("Christmas Eve Eve Eve");
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 21204
time=0
n=int(input())
todo=[]*n

for i in range(n):
  a,b=map(int, input().split())
  todo.append([b,a])

todo.sort()
d=True

for i in range(n):
  time += todo[i][1]
  if todo[i][0]<time:
    d=False
    break

if d:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38416