akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
listA = list(map(int, input().strip().split()))


class BCSet:
    B = 0
    C = 0


listBC = []

for i in range(0, M):
    B, C = map(int, input().split())
    new_BCSet = BCSet()
    new_BCSet.B = B
    new_BCSet.C = C
    listBC.append(new_BCSet)


def MurgeSort(left, right):
    if (right-left == 1):
        return
    mid = left + int((right - left) / 2)
    MurgeSort(left, mid)
    MurgeSort(mid, right)
    tmp = []
    for i in range(left, mid):
        tmp.append(listBC[i])
    for i in range(mid, right):
        tmp.append(listBC[mid + right - i - 1])
    iterator_left = 0
    iterator_right = right-left-1
    for i in range(left, right):
        if tmp[iterator_left].C <= tmp[iterator_right].C:
            listBC[i] = tmp[iterator_left]
            iterator_left += 1
        else:
            listBC[i] = tmp[iterator_right]
            iterator_right -= 1


def AMurgeSort(left, right):
    if (right-left == 1):
        return
    mid = left + int((right - left) / 2)
    AMurgeSort(left, mid)
    AMurgeSort(mid, right)
    tmp = []
    for i in range(left, mid):
        tmp.append(listA[i])
    for i in range(mid, right):
        tmp.append(listA[mid + right - i - 1])
    iterator_left = 0
    iterator_right = right-left-1
    for i in range(left, right):
        if tmp[iterator_left] <= tmp[iterator_right]:
            listA[i] = tmp[iterator_left]
            iterator_left += 1
        else:
            listA[i] = tmp[iterator_right]
            iterator_right -= 1


MurgeSort(0, M)
AMurgeSort(0, N)

sum = 0
card_total = 0
cpoint = 0
iadjuster = 0

for i in range(0, N):
    if listA[N - i - 1+iadjuster] >= listBC[M - cpoint - 1].C or cpoint >= M:
        card_total += 1
        sum += listA[N - i - 1+iadjuster]
        if card_total == N:
            break
    else:
        if card_total + listBC[M - cpoint - 1].B > N:
            sum += (listBC[M - cpoint - 1].B-(card_total +
                                              listBC[M - cpoint - 1].B - N)) * listBC[M - cpoint - 1].C
            break
        else:
            card_total += listBC[M - cpoint - 1].B
            sum += listBC[M - cpoint - 1].B * listBC[M - cpoint - 1].C
            cpoint += 1
            iadjuster += 1


print("{}".format(sum))


Measured memory_bytes: 33164
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	set<int> num;
	set<int>::iterator itr;
	for(int i=0;i<N;++i){
		int A;
		cin >> A;
		itr = num.find(A);
		if( itr != num.end() ){
			num.erase( itr );
		}else{
			num.insert( A );
		}
	}

	cout << num.size() << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 4992
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, d;
  cin >> n >> d;

  int x[n][d];

  rep(i, n){
    rep(j, d){
      cin >> x[i][j];
    }
  }

int res = 0;

  for(int i = 0; i < n - 1; ++i){
    for(int j = i + 1; j < n; ++j){
      double sum = 0;
      for(int k = 0; k < d; ++k){
        sum += pow((x[i][k] - x[j][k]), 2);
      }
      sum = sqrt(sum);
      if(ceil(sum) == floor(sum)){
        ++res;
      }
    }
  }

  cout << res << "\n";

  return 0;
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;

//---main---------------------------------------------
int main(){
    //main
    int H,W,Ch,Cw,Dh,Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    Ch--; Cw--; Dh--; Dw--;
    vector<string> S(H);
    rep(i,H) cin >> S[i];

    vector<vector<int>> cmap(H, vector<int>(W, iINF));
    deque<P> q;
    cmap[Ch][Cw] = 0;
    q.emplace_back(Ch,Cw);

    int h0,w0,h1,w1,c;
    int hdir[] = {0,1,0,-1};
    int wdir[] = {1,0,-1,0};
    while(!q.empty()){
        h0 = q.front().first;
        w0 = q.front().second;
        c = cmap[h0][w0];
        q.pop_front();
        
        //if(c != cmap[h0][w0]) continue;

        rep(diri, 4){
            h1 = h0 + hdir[diri];
            w1 = w0 + wdir[diri];
            if(h1<0 || h1 >= H || w1 < 0 || w1 >= W) continue;
            if(S[h1][w1] == '#') continue;
            if(cmap[h1][w1] <= c) continue;
            cmap[h1][w1] = c;
            q.emplace_front(h1,w1);
        }

        for(int dh=-2; dh<=2; dh++){
            for(int dw = -2; dw<= 2; dw++){
                h1 = h0 + dh;
                w1 = w0 + dw;
                if(h1<0 || h1 >= H || w1 < 0 || w1 >= W) continue;
                if(S[h1][w1] == '#') continue;
                if(cmap[h1][w1] <= c+1) continue;
                cmap[h1][w1] = c+1;
                q.emplace_back(h1,w1);
            }
        }
    }

    int ans = cmap[Dh][Dw];
    if(ans == iINF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9544
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, i, j, k, x, best = 0, s;

	cin >> n;
	vector<long long> a(n), b(n);
	s = 0;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = - a[i] - a[i];
		s += a[i];
	}

	sort(b.rbegin(), b.rend());
	for (i = 1; i < n; i++) b[i] += b[i - 1];

	best = s;
	for (i = 2; i <= n; i += 2) best = max(best, s + b[i - 1]);

	cout << best << "\n";


	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  ll x,y;
  cin >> x >> y;
  rep(i,n-1) {
    ll a,b;
    cin >> a >> b;
    ll t=max((x+a-1)/a,(y+b-1)/b);
    x=t*a;
    y=t*b;
  }
  pr(x+y);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b;char op;cin>>a>>op>>b;
    cout << (op=='+'?a+b:a-b)<<ednl;
}



Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto s = readln.chomp;
  auto t = "";

  foreach (c; s)
    switch (c) {
    case '0':
    case '1':
      t ~= c;
      break;
    case 'B':
      t = t.empty ? t : t[0..$-1];
      break;
    default:
      assert(0);
    }

  writeln(t);
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        boolean answer = false;
        for (int i = 0; i < n.length(); i++) {
            if (n.charAt(i) == '9') {
                answer = true;
            }
        }
        if (answer) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); ++i) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

using namespace std;

//arc065 Day Dream
//Sを逆さにする
//Tを逆さにする
//比較する

int main(){
  ll A,B;
  cin >> A >> B;

  ll iMax = -30000;

  iMax = max(iMax, A + B);
  iMax = max(iMax, A - B);
  iMax = max(iMax, A * B);

  cout << iMax << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
int N;
vector<ll> a;
int main(){
	cin >> N;
	a.resize(3*N);
	for(int i=0;i<a.size();i++){
		cin >> a[i];
	}
	sort(all(a));
	ll ans = 0ll;
	for(int i=0;i<N;i++){
		ans += a[a.size()-2*(i+1)];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int N; std::cin >> N;
  for(int a = 1; a <= 9; ++a) {
    if(N%a==0 && N/a<=9) fin("Yes");
  }
  fin("No");
  return 0;
}


Measured memory_bytes: 256
N = int(input())


if N % 2 == 0:
    print(N*(N-1)//2 - N // 2)
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i + j == N+1:
                continue
            print(i,j)
else:
    print(N*(N-1)//2 - (N-1)//2)
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i+j == N:
                continue
            print(i,j)

Measured memory_bytes: 3612
/*
Original problem: 
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9+7;

namespace SOLVE {
    void addmod(ll & x, ll y) {
        x += y;
        if (x >= mod) {
            x -= mod;
        }
    }

    void submod(ll & x, ll y) {
        x -= y;
        if (x < 0) {
            x += mod;
        }
    }

    void main() {
        int n, k;
        cin >> n >> k;
        VI A(n);
        REP(i, 0, n) {
            cin >> A[i];
        }

        VLL dp(k + 2); // number of ways to have dp[i] candies
        dp[k] = 1;

        REP(kid, 0, n) {
            // prefix sum to support O(n * k) complexity
            VLL pref(k + 2);
            REP(candy, 0, k + 1) {
                int lb = max(0LL, candy - A[kid]);
                int ub = candy;
                addmod(pref[lb], dp[candy]);
                submod(pref[ub + 1], dp[candy]);
            }
            REP(i, 1, k + 2) {
                addmod(pref[i], pref[i - 1]);
            }
            dp = pref;
        }

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


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
ll sum[45];
ll n,k;
int main(){
	scanf("%lld%lld",&n,&k);
	ll x;
	for (int i=1;i<=n;i++){
		scanf("%lld",&x);
		ll t=1;
		for (ll j=0;j<=40;j++) {
			if (((t)<=x)&&((t)&x)) sum[j]++;
			t<<=1;
		}
	}
	ll ans=0,t=0;
	ll MAX=1;
	for (int j=0;j<=40;j++) MAX<<=1;
	ans=0;
	for (ll i=40;i>=0;i--){
		MAX>>=1;
		if (t+(MAX)<=k&&(n-sum[i])>(n>>1)){
		//	puts("123123");
			t+=MAX;
			ans+=(n-sum[i])*(MAX);
		}else ans+=sum[i]*MAX;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type st struct {
	a, b int
}

type ch struct {
	c, d int
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	S := make([]st, N)
	for i := 0; i < N; i++ {
		S[i] = st{sc.nextInt(), sc.nextInt()}
	}
	C := make([]ch, M)
	for i := 0; i < M; i++ {
		C[i] = ch{sc.nextInt(), sc.nextInt()}
	}
	for i := 0; i < N; i++ {
		distance := int(1e+10)
		point := 0
		for j := 0; j < M; j++ {
			dis := abs(S[i].a-C[j].c) + abs(S[i].b-C[j].d)
			if dis < distance {
				distance = dis
				point = j + 1
			}
		}
		fmt.Fprintln(wtr, point)
	}

	wtr.Flush()
}


Measured memory_bytes: 640
//郢昴・ﾎｦ郢晏干ﾎ・
#include <bits/stdc++.h>
//#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(),(v).end()
#define PAIR pair<int,int>
using namespace std;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
//



signed main (){
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   int N,M;
   cin >> N >> M;
   int cnt[M];
   fill(cnt,cnt+M,0);
   REP(i,N)
   {
      int K;
      cin >> K;
      REP(j,K)
      {
          
         int A ;
         cin >> A;
         cnt[A-1]++;
      }
   }
   cout << count_if(cnt,cnt+M,[N](auto x){return x == N;}) <<endl;

}



//鬩幢ｽｨ陋ｻ繝ｻ繝ｻ隴崢陝・ｸ楪・､
//隴厄ｽｴ隴・ｽｰ邵ｺ蜉ｱ竊醍ｸｺ繝ｻ・ｰ・ｴ陷ｷ驕ｺ繝ｻ驍擾ｽｯ驕ｨ髦ｪ・・
//闔譴ｧ・ｬ・｡陷医・竊鍋ｸｺ蜉ｱ笳・ｸｺ繝ｻ繝ｻ邵ｺ繝ｻ・らｸｺ蜻趣ｽｳ繝ｻ
//闕ｳﾂ驍ゅ・蝨堤ｹｧ蜑・ｽｽ蜍溷ｱ鍋ｹｧ繧亥ｳｩ隴・ｽｰ邵ｺ蜉ｱ笳・ｸｺ繝ｻ繝ｻSegment Tree(邵ｺ貅倪味邵ｺ諤懷徐陟墓ｶ・logN))
//驕ｽ繝ｻ蟲・ｹｧ蜑・ｽｽ蜍溷ｱ鍋ｹｧ繧亥ｳｩ隴・ｽｰ邵ｺ蜉ｱ笳・ｸｺ繝ｻ繝ｻLazy Segment Tree


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

int main() {
    ll N;
    cin >> N;
    vector<ll> T(5);
    ll mi = (ll) pow(10,15) + 1;
    rep(i,5) {
        cin >> T.at(i);
        mi = min(mi, T[i]);
    }
    if (mi >= N) {
        cout << 5 << endl;
        return 0;
    }
    cout << 5 + (ll)ceil((N - mi) / (double)mi) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <map>
#include <numeric>
#define bogo_sort std::sort
#define bozo_sort std::stable_sort
#define alles(obj) obj.begin(), obj.end()
#define elif else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo std::cout <<
#define read std::cin >>
#define endl std::endl
#define fin << '\n'
#define bash push_back
#define makePair std::make_pair
#define _ << ' ' <<
// type-define
#define Stack std::stack
#define Queue std::queue
#define Set std::set
#define PQueue std::priority_queue
#define Vector std::vector
#define Pair std::pair
#define Map std::map
#define Greater std::greater
using String = std::string;
using llong = long long;
using boolean = bool;
using Pii = Pair<int, int>;
using Vi = Vector<int>;
using Vii = Vector<Pii>;
// utils
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs ( llong n ) { return ( n < 0 ) ? -n : n; }
    boolean isMovable ( int x, int y, int w, int h ) { 
        return ( x >= 0 && y >= 0 && x < w && y < h ); }
}

#define int long long

namespace Rlyeh {

    int H, W;
    char mp[1010][1010];
    int  dp[1010][1010];

    signed call_of_Cthulhu( signed datum ) {

        read H >> W;
        for ( int i = 1; i <= H; i++ ) {
            String tmp;
            read tmp;
            for ( int j = 0; j < W; j++ ) {
                mp[i][j+1] = tmp[j];
            }
        }

        dp[1][1] = 1;

        for ( int i = 1; i <= H; i++ ) {
            for ( int j = 1; j <= W; j++ ) {
                if ( mp[i][j] == '.' ) {
                    dp[i][j] += (dp[i-1][j] + dp[i][j-1]) % 1000000007;
                }
            }
        }
        echo dp[H][W] fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

int main() {
    string s;
    cin >> s;

    string top = s.substr(0,1);
    string middle = s.substr(1, s.size()-2);
    int m = middle.size();
    string end = s.substr(s.size()-1, 1);
    cout << top << m << end << endl;
}

Measured memory_bytes: 3576
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
l=[[0]*26]
t=[[]]
v=[0]
for d in range(D):
    x=[]
    for b in range(len(l)):
        x.extend([(S[d][i]-sum([(d+1-l[b][j])*C[j] for j in range(26) if i!=j]),i,b) for i in range(26)])
    x=sorted(x,key=lambda a:v[a[2]]+a[0])[::-1]
    l2=[]
    t2=[]
    v2=[]
    for _,i,b in x[:40]:
        l2.append(l[b].copy())
        l2[-1][i]=d+1
        t2.append(t[b].copy())
        t2[-1].append(i+1)
        v2.append(v[b]+_)
    l=l2
    t=t2
    v=v2
print(*t[0],sep='\n')

Measured memory_bytes: 9872
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


//

int main()
{
	int n, x;
	vector<int> a;
	cin >> n >> x;

	rep(i, n)
	{
		int tmp;
		cin >> tmp;
		a.pb(tmp);
	}

	sort(a.begin(), a.end());

	int count = 0;
	for (size_t i = 0; i < a.size(); i++)
	{
		if ( a[i] <= x )
		{
			count++;
		}
		else
		{
			break;
		}

		x -= a[i];
	}

	if ( x != 0 && count > 0 && count == n ) count--;

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut indexes: Vec<usize> = Vec::new();
    for i in 0..n {
        let p: usize = iterator.next().unwrap().parse().unwrap();
        if p == (i + 1) {
            indexes.push(p);
        }
    }

    let mut count = 0;
    let mut prev = 0;
    for i in indexes {
        if prev == 0 || prev + 1 != i {
            count += 1;
            prev = i;
        } else if prev + 1 == i {
            prev = 0;
        }
    }

    return count.to_string();
}


Measured memory_bytes: 6396
def c_id(N, M, City):
    City = sorted(City, key=lambda x: (x[0], x[1]))
    # print(City)
    a, b = City[0][0], 0
    for j, (p, y, k) in enumerate(City):
        if p == a:
            # print('a', j, p, y, k)
            b += 1
            City[j] = [p, b, k]
        else:
            # print('b', j, p, y, k)
            a = p
            b = 1
            City[j] = [p, b, k]
    city = sorted(City, key=lambda x: x[2])
    # print(city)

    ans_tmp = []
    for p, q, k in city:
        ans_tmp.append('{0:06d}{1:06d}'.format(p, q))
    ans = '\n'.join(ans_tmp)
    return ans

N, M = [int(i) for i in input().split()]
City = [[int(i) for i in input().split()] + [k] for j, k in enumerate(range(M), 1)]
print(c_id(N, M, City))

Measured memory_bytes: 45388
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NMQ = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M, Q) = (NMQ[0], NMQ[1], NMQ[2]);

        var abcd = new (int, int, int, int)[Q];

        for (int i = 0; i < Q; i++)
        {
            var p = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            abcd[i] = (p[0] - 1, p[1] - 1, p[2], p[3]);
        }

        var maxScore = 0;

        foreach (var A in GetA(N, M))
        {
            var score = 0;

            foreach (var (a, b, c, d) in abcd)
            {
                if(A[b] - A[a] == c)
                {
                    score += d;
                }
            }

            maxScore = Math.Max(maxScore, score);
        }

        WriteLine(maxScore);
    }

    static IEnumerable<int[]> GetA(int N, int M)
    {
        var A = Enumerable.Repeat(1, N).ToArray();
        
        yield return A;

        while (true)
        {
            var end = true;

            for (int i = N - 1; 0 <= i; i--)
            {
                if(A[i] < M)
                {
                    A[i]++;

                    for (int j = i + 1; j < N; j++)
                    {
                        A[j] = A[i];
                    }

                    end = false;

                    break;
                }
                else
                {
                    continue;
                }
            }

            if(end)
            {
                break;
            }

            yield return A;
        }
    }
}


Measured memory_bytes: 28320
def solve():
    mod = 10 ** 9 + 7

    x, y = map(int, input().split())

    sum_ = x + y

    q, r = divmod(sum_, 3)
    if r != 0:
        return 0

    a = (x * 2 - y) // 3

    b = (y * 2 - x) // 3

    if a < 0 or b < 0:
        return 0

    def cmb(n, r):
        return (fact[n] * finv_t[r] * finv_t[n - r]) % mod

    fact = [1, 1]
    inv_t = [0, 1]
    finv_t = [1, 1]
    for i in range(2, q + 1):
        fact.append((fact[-1] * i) % mod)
        inv_t.append((-inv_t[mod % i] * (mod // i)) % mod)
        finv_t.append((finv_t[-1] * inv_t[-1]) % mod)

    return cmb(q, a)


print(solve())


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 1001001001;

int fact(int n){
	int ans = 1;
	rep(i,n){
		ans *= (i+1);
	}
	return ans;
}

int main(){
	int n; cin >> n;
	vi x(n), y(n); rep(i,n) cin >> x[i] >> y[i];
	vector<int> num(n);
	rep(i,n) num[i] = i;
	double ans = 0;
	do {
		int x0 = x[num[0]], y0 = y[num[0]];
		for(int i=1; i<n; i++){
			int x1 = x[num[i]], y1 = y[num[i]];
			ans += sqrt(double((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)));
			x0 = x1; y0 = y1;
		}
	}while(next_permutation(num.begin(), num.end()));
	printf("%.8f",ans / fact(n));

}

Measured memory_bytes: 256
import numpy as np
l_input = [int(e) for e in input().split()]
A = [int(e) for e in input().split()]
A = np.array(A)
N = l_input[0]
M = l_input[1]
A_dash = A-1/(4*M)*sum(A)
cnt = 0
for i in A_dash:
    if i >=0:
        cnt += 1
if cnt >= M:
    print('Yes')
else:
    print('No')

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

int main(){
  int N, a, b; cin >> N >> a >> b;
  int ans = 0;
  for(int i = 1; i <= N; i++){
    int tmp = i, sum = 0;
    while(tmp > 0){
      sum += tmp % 10;
      tmp /= 10; 
    }
    if(sum >= a && sum <= b) ans += i;
  }
  cout << ans << endl;
}

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


int main(){
    int l,r;
    cin >> l >> r;
    if(r - l >= 2018){
        cout << "0" << endl;
    }else{
        int answer = 2019;
        for(int i = l; i <= r - 1 ; i++){
            int tmpi = i % 2019;
            for(int j = l + 1; j <= r; j++){
                int tmpj = j % 2019;
                int tmp = (tmpi * tmpj) % 2019;
                if(tmp < answer)answer = tmp;
            }
        }
        
        cout << answer << endl;
    }
}

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

using ll = long long;

ll N;

int main() {
    cin >> N;
    set<ll> ms;
    for (ll d = 1; d * d <= N; ++d) {
        if (N % d == 0 && d < (N - d) / d) ms.insert((N - d) / d);
    }
    ll ans = 0;
    for (ll m : ms) {
        if (m <= 0) continue;
        ans += m;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>

int main() {
	int a, b, c;
	std::cin >> a >> b >> c;
	int _ = 0;
	for (int i = a; i <= b; i++) {
		if (c % i == 0)
			_++;
		}
	std::cout << _ << std::endl;
	return 0;
}


Measured memory_bytes: 3116
# 高橋君は500円玉をK枚持っています。 これらの総額がX円以上である場合は Yes を、そうでない場合は No を出力してください。
# 標準入力： K X
# 制約：　1≤K≤100,　1≤X≤10^5

inp_word = input()

# コマンドライン引数を変数に入れる
K,X = inp_word.split()

# 総額の保持
sum = 500 * int(K)

# 出力文の作成
if sum >= int(X):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
//bool cmp(long long a, long long b){
//    return a > b;
//}
//int gcd(int a, int b) {
//    int t;
//    while (b != 0) {
//        t = b;
//        b = a % b;
//        a = t;
//    }
//    return a;
//}
//long long levels[100500];
//void dfs(long long current, long long prev, set<long long>* sets){
//    for (auto it:sets[current]){
//        if (prev != it){
//            levels[it] = levels[current] + 1;
//            dfs(it, current, sets);
//        }
//    }
//}
//long long st[10], fin[10];
//int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max, s1;
    long long da, db;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> s;
    if (s[s.length() - 1] == 's'){
        cout << s << "es";
    }else
        cout << s << "s";
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h> 
using namespace std;
int main(){
	string s;
	cin>>s;
	int n=s.length();
	string l="";
	for(int i=n-1;i>=0;--i){
		l+=s[i];
	}
	if(l==s){
		string a=s.substr(0,(n-1)/2);
		string x="";
		for(int i=a.length()-1;i>=0;--i){
			x+=a[i];
		}
		if(x==a){
			string w=s.substr((n+3)/2-1,n-(n+3)/2+1);
			string b="";
			for(int i=w.length()-1;i>=0;--i){
				b+=w[i];
			}
			if(b==w){
				cout<<"Yes";
				return 0;
			}
			else{
				cout<<"No";
				return 0;
			}
		}
		else{
			cout<<"No";
			return 0;
		}
	}
	else{
		cout<<"No";
		return 0;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
long long T, a, M, S;
int main() {
	int i;
	scanf("%d%lld", &n, &T);
	for (i = 1; i <= n; i ++ ) {
		scanf("%lld", &a);
		M = max(M, a);

		printf("%lld\n", max(T - S+M-a, 0ll) / M + 1);

		S += a;
	}
}

Measured memory_bytes: 2752
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i = a;i < b;i++)
#define _rep(i,a,b) for(int i = a;i <= b;i++)
typedef long long ll;

const int maxn = 110;
int a[2][maxn];
int ans[maxn];

int main() {
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++) scanf("%d",&a[0][i]);
	
	int ok = 1;
	int cur = 0;
	int tn = n;
	int tot = n;
	int cnt = 0;
	for(int cou = 0;cou < n;cou++) {
		int f = 0;
		for(int i = tn;i >= 1;i--) {
			if(a[cur][i] == i) {
				f = 1;
				ans[cnt++] = i;
				a[cur][i] = -1;
				tot--;
				break;
			}
		}
		if(f == 0) {
			ok = 0;
			break;
		}

		int m = 0;
		for(int i = 1;i <= tn;i++) {
			if(a[cur][i] != -1) a[cur^1][++m] = a[cur][i];
		}
		cur = cur^1;
		tn = m;
	}
	if(!ok) printf("-1\n");
	else {
		for(int i = n-1;i >= 0;i--) printf("%d\n",ans[i]);
	}
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;

int second();

//愚直
int main(){
    if(true){
        second(); return 0;
    }
    ll L, R = 0;
    cin >> L >> R;
    ll MOD = 2019;
    ll min = MOD;
    //分配法則 (i*j)%n = (i%n * j%n)%n
    for(ll i=L; i<R+1; ++i){
        for(ll j=i+1; j<R+1; ++j){
            ll tmp = (i*j)%MOD;
            if(tmp < min) min = tmp;
        }
    }
    cout << min << endl;
    return 0;
}

int second(){
    ll L, R = 0;
    cin >> L >> R;
    ll MOD = 2019;
    ll min = MOD;
    //分配法則 (i*j)%n = (i%n * j%n)%n
    if(R-L<MOD){
        for(ll i=L; i<R+1; ++i){
            for(ll j=i+1; j<R+1; ++j){
                ll tmp = (i*j)%MOD;
                if(tmp < min) min = tmp;
                if(min==0){//最小値
                    goto END_OF_LOOP;
                }
            }
        }
    }    
    else{
        min = 0;
        //cout << R-L << endl;
    }

    END_OF_LOOP:
    cout << min << endl;
    return 0;
}

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

using namespace std;

int main(){
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	int n_max = -101, m_min = 101;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		n_max = max(n_max, k);
	}
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		m_min = min(m_min, k);
	}
	x = max(x, n_max);
	y = min(y, m_min);
	if (x < y) {
		cout << "No War" << endl;
		return 0;
	}
	cout << "War" << endl;
    return 0;
}


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

const int N = 8;
const int FREE = -1;
const int EXIST = 1;
int col[N], row[N], dpos[2*N], dneg[2*N];

void putQueen(int i){
    if (i == N){
        for (int j = 0; j < N; j++){
            for (int k = 0; k < N; k++){
                if (row[j] == k){
                    printf("Q");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        return;
    }
    //既にQueenが置いてあれば次の行へ進む
    if (row[i] != FREE) putQueen(i+1);
    else{
        for (int j = 0; j < N; j++){
            if (row[i] == FREE && col[j] == FREE && dpos[i+j] == FREE && dneg[i-j+N-1] == FREE){
                row[i] = j;
                col[j] = i;
                dpos[i+j] = dneg[i-j+N-1] = EXIST;
                putQueen(i+1);
                row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
            }
        }
    }
}

int main(){
    int n, i, j;
    cin >> n;
    for (i = 0; i < N; i++) row[i] = col[i] = FREE;
    for (i = 0; i < 2*N; i++) dpos[i] = dneg[i] = FREE;
    while(n--){
        cin >> i >> j;
        row[i] = j;
        col[j] = i;
        dpos[i+j] = dneg[i-j+N-1] = EXIST;
    }
    putQueen(0);

    return 0;
}



Measured memory_bytes: 3104
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>


int main(){
	int h,n,sum=0;
	cin >> h >> n;
	int temp;
	rep(i,n){cin >> temp;sum+=temp;}
	if(sum>=h)cout << "Yes";
	else cout << "No";
}



Measured memory_bytes: 768
import sys
sys.setrecursionlimit(10**8)

N = int(input())
*a, = map(int, input().split())

s = [0]*N
s[0] = a[0]
for i in range(1, N):
    s[i] += s[i-1]+a[i]
s = [0]+s

dp = [[0]*(N+1) for _ in range(N+1)]


def solve(l, r):
    if l == r:
        return 0
    if dp[l][r] > 0:
        return dp[l][r]

    n = float('inf')
    m = s[r+1]-s[l]
    for i in range(l, r):
        n = min([n, solve(l, i)+solve(i+1, r)+m])
    dp[l][r] = n
    return n


print(solve(0, N-1))


Measured memory_bytes: 45660
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(input):
    [takahashi, aoki, count] = string_to_int(input)

    if count > takahashi:
        count -= takahashi
        takahashi = 0
    else:
        takahashi -= count
        count = 0
        return "{} {}".format(takahashi, aoki)

    if count > aoki:
        return "0 0"
    else:
        aoki -= count
        return "{} {}".format(takahashi, aoki)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(input())
    print(ret)


Measured memory_bytes: 38256
import itertools as its

N = int(input())
P = []
on_piramid = None
for _ in range(N):
    p = tuple(map(int, input().split()))
    P.append(p)
    if on_piramid == None and p[2] >= 1:
        on_piramid = p

for x, y in its.product(range(101), range(101)):
    h = on_piramid[2] + abs(x-on_piramid[0]) + abs(y-on_piramid[1])
    for i in range(N):
        if P[i][2] != max(h - abs(x - P[i][0]) - abs(y - P[i][1]), 0):
            break
    else:
        print(x, y, h)
        exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<"LBWNB    "<<x<<"---\n"
#define pb push_back
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mp make_pair
#define p() puts("")
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
const int mod=998244353;
//const int mod=1e9+7;
const int inf=1e9+7;
const int maxn=4e3+10;
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}

int t,n,m,k;
char a[maxn];
int b[maxn],c[maxn],d[maxn];
bool f[3];
int main(){
    scanf("%d%s",&n,a+1);
    per(i,n,1) b[i]=b[i+1]+(bool)(a[i]=='R');
    per(i,n,1) c[i]=c[i+1]+(bool)(a[i]=='G');
    per(i,n,1) d[i]=d[i+1]+(bool)(a[i]=='B');
    ll s=0;
    rep(i,1,n) rep(j,i+1,n){
        if(a[i]==a[j]) continue;
        memset(f,0,sizeof f);
        if(a[i]=='R'||a[j]=='R') f[0]=1;
        if(a[i]=='G'||a[j]=='G') f[1]=1;
        if(a[i]=='B'||a[j]=='B') f[2]=1;
        if(f[0]==0) s+=b[j+1]-(bool)(j+j-i<=n&&a[j+j-i]=='R');
        if(f[1]==0) s+=c[j+1]-(bool)(j+j-i<=n&&a[j+j-i]=='G');
        if(f[2]==0) s+=d[j+1]-(bool)(j+j-i<=n&&a[j+j-i]=='B');
    }
    printf("%lld\n",s);
    return 0;
}




//const int M=1<<20;
//ll t1[M*2+5],t2[M*2+5],ans,ca[M],cb[M];
//inline void upd(int i){t1[i]=t1[i<<1]+t1[i<<1|1];t2[i]=max(t2[i<<1],t1[i<<1]+t2[i<<1|1]);}
//inline void add(int i,int v){for(t1[i+=M]+=v;i>>=1;upd(i));}
//int n,m,p,x,y,i,j;
//struct mons{int x,y,z;}a[M];
//int main(){
//	for(i=0;i<M;++i)ca[i]=cb[i]=1ll<<60;ans=-(1ll<<60);
//	scanf("%d%d%d",&n,&m,&p);
//	for(i=1;i<=n;++i)scanf("%d%d",&x,&y),ca[x]=min(ca[x],(ll)y);
//	for(i=1;i<=m;++i)scanf("%d%d",&x,&y),cb[x]=min(cb[x],(ll)y);
//	for(i=0;i<M;++i)t2[i+M]=-cb[i];for(i=M-1;i;--i)upd(i);
//	for(i=1;i<=p;++i)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
//	sort(a+1,a+p+1,[&](const mons&a,const mons&b){return a.x<b.x;});
//	for(i=0,j=1;i<M;++i){
//		for(;j<=p && a[j].x<i;++j)add(a[j].y,a[j].z);
//		ans=max(ans,t2[1]-ca[i]);
//	}
//	printf("%lld\n",ans);
//	return 0;
//}


Measured memory_bytes: 3872
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <cstring>
#include <stdio.h>

using namespace std;

typedef long long int lli;

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

	lli p = N / (A + B);
	lli result = A * p;

	lli rest = N - p * (A + B);
	if (rest < A) {
		result += rest;
	}
	else {
		result += A;
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;

int n,m,ans=0,tot=0;
int jc[500005];

inline int quick_power(int a,int b)
{
	int res=1;
	for (;b;b=b>>1,a=(a*a)%mod)
	{
		if (b&1)  res=(res*a)%mod;
	}
	return res;
}

inline int ny(int k)
{
	return quick_power(k,mod-2);
}

inline int C(int n,int m)
{
	return ((jc[n]*ny(jc[m]))%mod*ny(jc[n-m]))%mod;
}

inline int A(int n,int m)
{
	return (jc[n]*ny(jc[n-m]))%mod;
}

inline void init()
{
	jc[0]=1;
	for (int i=1;i<=500000;i++)  jc[i]=(jc[i-1]*i)%mod;
}

signed main()
{
	cin>>n>>m;
	init();
	for (int i=0;i<=n;i++)
	{
		int now=(A(m-i,n-i)*C(n,i))%mod;
		if (i%2==0)  tot=(tot+now)%mod;
		else tot=((tot-now)%mod+mod)%mod;
	}
	tot=(tot*A(m,n))%mod;
	cout<<tot<<endl;
	
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll h,w;
	cin >> h >> w;
	if(w==1 || h==1) cout << 1 << endl;
	else cout << (h*w%2?w*h/2+1:w*h/2) << endl;
	return 0;
}

Measured memory_bytes: 256
function main(input) {
  input=input.trim();
  const x = parseInt(input.split(" ")[0], 10);
  const y = parseInt(input.split(" ")[1], 10);
  const z = parseInt(input.split(" ")[2], 10);
  var deff=x-2*z
  var kazu1=Math.floor(deff/(y+z))
  if(deff-kazu1*(y+z)>=y){
    console.log(kazu1+1);
  }else{
    console.log(kazu1);
  }


}



main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include<bits/stdc++.h>
#define speed ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define endl '\n'
 
using namespace std;
 
main()
{
  speed;
  int n,i;
  cin>>n;
  int l[n];
  for (i=0;i<n;i++)
    cin>>l[i];
  int ctr=0;
  for (i=0;i<n;i++)
  {
    if (l[i]!=i+1)
    {
      if (l[l[i]-1]!=(i+1))
      {
        ctr=3;
        break;
      }
      else
        ctr++;
    }
  }
  if (ctr==0 || ctr==2)
    cout<<"YES\n";
  else
    cout<<"NO\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <malloc.h>
#include <cstdlib>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tr_policy.hpp>
//using namespace __gnu_pbds;

#define ll				long long
#define double			long double
#define pb 				push_back
#define endl 			'\n'
#define F				first
#define S				second
#define mod				(int)1000000007
#define mp              make_pair
#define ios 			ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inf				1e18
#define mem(a,x)		for(int i=0;i<(int)(sizeof(a)/sizeof(a[0]));i++) a[i] = x;
#define trace(a)		cout<<(#a)<<" --> "<<a<<endl
#define trace2(a,b)		{trace(a);trace(b);cout<<"------------------\n";}
#define trace3(a,b,c)	{trace(a);trace(b);trace(c);cout<<"------------------\n";}
#define trace4(a,b,c,d) {trace(a);trace(b);trace(c);trace(d);cout<<"------------------\n";}
#define M_PI           	3.14159265358979323846
#define T				pair<int,int>
//#define ordered_set 	tr<T, null_type,less<T>, rb_tr_tag,tr_order_statistics_node_update>


void run(){
	int n,m;
	cin>>n>>m;
	int a[m];
	for(int i=0;i<m;i++)
		cin>>a[i];
	for(int i=0;i<m;i++)
		n-=a[i];
	if(n>=0)
		cout<<n;
	else
		cout<<-1;
}

signed main(){
	ios;
//	int t;
//	cin>>t;
//	for(int i=1;i<=t;i++)
//		cout<<"Case #"<<i<<": ", run();
	run();
	return 0;
}


Measured memory_bytes: 3680
#include <cstdio>
#include <algorithm>
using namespace std;
const int Maxn=200005;
int L,n,a[Maxn];
long long ans;
long long oddL[Maxn],evenL[Maxn];
long long oddR[Maxn],evenR[Maxn];
int main()
{
	scanf("%d %d",&L,&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	a[n+1]=L;
	for (int i=1;i<=n+1;i++) oddL[i]=oddL[i-1]+a[i-1]+a[i],evenL[i]=evenL[i-1]+a[i]+a[i];
	for (int i=n+1;i>0;i--) oddR[i]=oddR[i+1]+L-a[i]+L-a[i-1],evenR[i]=evenR[i+1]+L-a[i-1]+L-a[i-1];
	for (int i=1;i<=n+1;i++)
	{
		int mn=min(i-1,n+1-i);
		long long res=0;
		if (mn>0) res+=oddL[i-1]-oddL[i-mn-1]-2LL*mn*a[i-mn-1]+evenR[i+1]-evenR[i+mn+1]-2LL*mn*(L-a[i+mn]);
		if (i-1>n+1-i) res+=1LL*(2*mn+1)*a[i-mn-1];
		else if (i-1<n+1-i) res+=1LL*(2*mn)*(L-a[i+mn]);
		ans=max(ans,res);res=0;
		if (mn>0) res+=evenL[i-1]-evenL[i-mn-1]-2LL*mn*a[i-mn-1]+oddR[i+1]-oddR[i+mn+1]-2LL*mn*(L-a[i+mn]);
		if (i-1>n+1-i) res+=1LL*(2*mn)*a[i-mn-1];
		else if (i-1<n+1-i) res+=1LL*(2*mn+1)*(L-a[i+mn]);
		ans=max(ans,res);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7168