akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define fill(x, v) memset(x, v, sizeof(x))
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define bas 987625403
#define sqr(x) (x)*(x)  
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> set_t;
#define trace(...) f(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void f(const char* x, t&& val1){
    cout<<x<< " : "<<val1<<endl;
}
template<typename t1, typename... t2> void f(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    f(xd+1, val2...);
}

int main(){

	fastio;
	string cad;
	cin >> cad;
	reverse(cad.begin(),cad.end());
	ll w = 0, ans = 0;
	for(char c : cad){
		if(c == 'W') w++;
		else ans += w;
	}
	cout << ans << endl;
	return 0;
}
//xd

Measured memory_bytes: 720
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

void trace(int A[],int N){
    REP(i,N){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


int main(){
    int n,m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
}


Measured memory_bytes: 256
///
// File:  d.go
// Author: ymiyamoto
//
// Created on Tue May 22 22:21:04 2018
//
package main

import (
	"fmt"
)

var N int
var ts []float64
var vs []float64

func min(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

func main() {
	fmt.Scan(&N)

	ts = make([]float64, N)
	vs = make([]float64, N)

	for i := range ts {
		fmt.Scan(&ts[i])
		ts[i] *= 2
		if i != 0 {
			ts[i] += ts[i-1]
		}
	}

	for i := range vs {
		fmt.Scan(&vs[i])
	}

	equations := make([][]float64, N+2)
	for i := range equations {
		equations[i] = make([]float64, int(ts[len(ts)-1])+1)
	}

	for i := 0; i < N; i++ {
		for j := range equations[i] {
			if i == 0 {
				if 0 <= j && float64(j) <= ts[i] {
					equations[i][j] = vs[i]
				} else if ts[i] < float64(j) {
					equations[i][j] = equations[i][j-1] + 0.5
				}
			} else {
				if ts[i-1] <= float64(j) && float64(j) <= ts[i] {
					equations[i][j] = vs[i]
				} else if ts[i] < float64(j) {
					equations[i][j] = equations[i][j-1] + 0.5
				} else {
					equations[i][j] = vs[i] + (ts[i-1]-float64(j))/2
				}
			}
		}
	}

	for j := range equations[N] {
		equations[N][j] = float64(j) / 2
		equations[N+1][j] = float64(len(equations[N])-1-j) / 2
	}

	time := make([]float64, int(ts[len(ts)-1])+1)
	for i := range time {
		time[i] = 1 << 30
		for n := range equations {
			time[i] = min(time[i], equations[n][i])
		}
	}

	ans := 0.0
	for i := range time {
		if i != 0 {
			ans += float64(time[i-1]+time[i]) * 0.25
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 34560
# A=gets.to_i
# B=gets.split.map(&:to_i)
# C=N.times.map{gets.to_i}
# D=N.times.map{gets.split.map(&:to_i)}
# S=gets.chomp
# MOD=1000000007


N=gets.to_i

list=N.times.map{gets.split.map(&:to_i)}


list.sort_by!{|a,b| -b}


time=list[0][1]
list.each do |a,b|
  time=b if time>b
  time-=a
end
if time<0
  puts 'No'
else
  puts 'Yes'
end

Measured memory_bytes: 23056
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
mam = 0
for i in range(len(a)):
    mam += b[a[i]-1]
for i in range(len(a)-1):
    if a[i] + 1 == a[i + 1]:
        mam += c[a[i]-1]
print(mam)


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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

const int maxn = 100000;

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int n;
    cin >> n;
    vt<pii> f1(maxn + 1), f2(maxn + 1);
    for (int i = 0; i <= maxn; i++) {
        f1[i].se = i;
        f2[i].se = i;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (~i & 1) f1[x].fi++;
        else f2[x].fi++;
    }

    sort(all(f1));
    sort(all(f2));

    int mn = n;
    if (f1[maxn].se != f2[maxn].se)
        mn = min(mn, n - f1[maxn].fi - f2[maxn].fi);
    if (f1[maxn - 1].se != f2[maxn].se)
        mn = min(mn, n - f1[maxn - 1].fi - f2[maxn].fi);
    if (f1[maxn].se != f2[maxn - 1].se)
        mn = min(mn, n - f1[maxn].fi - f2[maxn - 1].fi);
    cout << mn;
}


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


#define M 1046527
#define NIL (-1)
#define L 14
#define ll long long

char H[M][L];
int getChar(char ch){
  if (ch == 'A') return 1;
  else if (ch == 'C') return 2;
  else if (ch == 'G') return 3;
  else if (ch == 'T') return 4;
  else return 0;
}

ll getKey(char str[]) {
  ll sum = 0, p = 1, i;
  for( i = 0; i < strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M;}
int h2(int key){ return 1 + (key % (M-1));}

int find(char str[]) {
  ll key, i,h;
  key = getKey(str);
  for( i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if ( strcmp(H[h], str) == 0) return 1;
    else if ( strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]) {
  ll key, i, h;
  key = getKey(str);
  for( i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if ( strcmp(H[h], str) == 0) return 1;
    else if ( strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for( i = 0; i<M;i++) H[i][0] = '\0';
  scanf("%d", &n);
  for( i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if ( com[0] == 'i') {
      insert(str);
    } else {
      if ( find(str) ) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 17476
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		int sc = 1;

		for (int i = 0; i < n; i++) {
			if (sc <= k) {
				sc *= 2;
			} else {
				sc += k;
			}
		}

		System.out.println(sc);
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

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

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
bool cmp1(int a,int b)
{
    return a>b;
}
struct Point
{
    int x, y;
};
int mod=1e8+7;
int Coins[3010],n,m,color;
bitset<4000005>vis,tmp;
vector<int>v;
int main()
{
//    READ;
//    WRITE;
    int t,tc=1;
    ll x,y;
    int c;
    sf(n);
    int summ=0;
    for(int i=0;i<n;i++)
    {
        sf(Coins[i]);
        summ+=Coins[i];
    }
    sort(Coins,Coins+n);
    int median=(summ+1)/2;
    color=1;
    vis[0]=1;
    int sizee=1;
    int j;
    for(int i=0;i<n;i++)
    {
        vis|=vis<<Coins[i];
    }
    for(int i=median;i<=summ;i++)
    {
        if(vis[i])
        {
            printf("%d\n",i);
            return 0;
        }
    }

    return 0;
}


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

constexpr bool is_even(ll num)
{
    return num % 2 == 0;
}
constexpr bool is_odd(ll num)
{
    return !is_even(num);
}

struct grid {
    ll y;
    ll x;
};

struct coin_move {
    grid from;
    grid to;
};

void main_()
{
    ll H, W;
    cin >> H >> W;
    vector<vector<ll>> ass(H + 1); // 1-origin
    for (ll i = 1; i <= H; i++) {
        ass[i].push_back(0); // 1-origin
        copy_n(istream_iterator<ll>(cin), W, back_inserter(ass[i]));
    }

    vector<coin_move> ans;

    for (ll i = 1; i <= H; i++) {
        for (ll j = 1; j <= W; j++) {
            if (is_odd(ass[i][j])) {
                if (j < W) {
                    // 横へ移動
                    ll x_dash = j + 1;
                    ass[i][j]--;
                    ass[i][x_dash]++;
                    ans.push_back({ { i, j }, { i, x_dash } });
                } else if (i < H) {
                    // 下へ移動
                    ll y_dash = i + 1;
                    ass[i][j]--;
                    ass[y_dash][j]++;
                    ans.push_back({ { i, j }, { y_dash, j } });
                }
            }
        }
    }

    cout << ans.size() << "\n";
    for (auto&& a : ans) {
        cout << a.from.y << " "
             << a.from.x << " "
             << a.to.y << " "
             << a.to.x << "\n";
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 8312
#include <algorithm>
#include <stdio.h>

#define MOD 1000000007
#define ll long long
#define maxn 100000

int f[maxn+1];

int main() {
    int n, m, a, b, nr = 0;
    scanf("%d%d", &n, &m);

    f[0] = 1;
    for (int i = 1; i <= maxn; i++)
        f[i] = 1LL * i * f[i-1] % MOD;
    if (n > m) {
        int x = n;
        n = m;
        m = x;
    }
    if(m - n > 1)
        nr = 0;
    else if(m - n == 1)
        nr = 1LL * f[m] * f[n] % MOD;
    else if(m == n)
        nr = 1LL * f[m] * f[n] % MOD * 2 % MOD;
    else
        nr = 0;
    printf("%d", nr);

    return 0;
}


Measured memory_bytes: 512
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

int h,w,hi,wi;

int main(){
    cin >> h >> w >> hi >> wi;
    if (h%hi == 0 && w%wi == 0){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    int hrep = h/hi + 1;
    int wrep = w/wi + 1;

    if (w%wi){// 横に構成
        REP(i,h) {
            REP(j,w){
                cout << ((j+1)%wi ? wrep : -1 * wrep * (wi-1) - 1);
                if (j!=w-1) cout << " ";
            }
            cout << endl;
        }
    } else {// 縦に構成
        REP(i,h) {
            REP(j,w){
                cout << ((i+1)%hi ? hrep : -1 * hrep * (hi-1) - 1);
                if (j!=w-1) cout << " ";
            }
            cout << endl;
        }
    }
}



Measured memory_bytes: 1280
N = int(input())
H = list(map(int, input().split()))
r_H = list(reversed(H))

for i in range(N-1):
    if r_H[i+1] - r_H[i] > 1:
        print("No")
        exit()
    if r_H[i+1] - r_H[i] == 1:
        r_H[i+1] = r_H[i+1] - 1
print("Yes")

Measured memory_bytes: 20704
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int k = scan.nextInt();
    int s = scan.nextInt();
    long sum = 0;
    int check = s-2*k;
    int initial = (int) Math.max(0,check);

    for (int i=initial;i<=k;i++){
      int current = s-i;
      int start = 0;
      int end = k;
      if (current > 2*k){
        continue;
      }
      else if (current > k){
        start = current-k;
        sum += end-start+1;
      }
      else if (current >= 0){
        end = current;
        sum += end-start+1;
      }
    }
    System.out.println(sum);

  }

}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 lcm(u64 a, u64 b) { return (a / gcd(a, b)) * b; }

int main() {
  u64 H, N;
  cin >> H >> N;
  vector<u64> A(N);
  ArrayInput(A);
  u64 sum = 0;
  for (u64 i = 0; i < N; ++i) {
    sum += A[i];
  }
  if (sum >= H)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <map>
using namespace std;

const int MN = 200005;

int N;
int A[MN];

map<int,int> B;
typedef map<int,int>::iterator IT;

bool check(int M) {
	B.clear();
//	printf("M = %d :\n", M);
	for (int i = 1; i <= N; ++i) {
		if (A[i - 1] >= A[i]) {
			int j = A[i];
			while (j && ++B[j] == M)
				B[j--] = 0;
			if (!j) return 0;
		}
		else {
			IT it = B.end();
			if (it != B.begin()) {
				--it;
				while (it->first > A[i - 1]) {
					IT tmp = it;
					if (it != B.begin()) --it, B.erase(tmp);
					else {B.erase(tmp); break;}
				}
			}
		}
//		for (int j = 1; j <= A[i]; ++j)
//			printf("%c", B[j] + 'a');
//		puts("");
	}
	return 1;
}

int main() {
	int ok = 1;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", A + i);
		if (A[i - 1] >= A[i])
			ok = 0;
	}
	if (ok) return puts("1"), 0;
	int lb = 2, rb = N, mid, ans = -1;
	while (lb <= rb) {
		mid = lb + rb >> 1;
		if (check(mid)) ans = mid, rb = mid - 1;
		else lb = mid + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 9856
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define INF 1000000000

int main() {
	ll n;
	cin>>n;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
	}
	if(v[0]!=0){
		cout << -1 << endl;
		return 0;
	}
	rep(i,0,v.sz-1){
		if(v[i+1]-v[i]>1){
			cout << -1 << endl;
			return 0;
		}
	}
	v.pb(0);
	ll ans = 0;
	ll c0 = v[0];
	ll c1;
	rep(i,1,v.sz){
		c1 = v[i];
		if(c1-c0==1){
			c0 = c1;
		}
		else{
			ans += c0;
			c0 = c1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3444
N, M, X, Y = [int(i) for i in input().split()]
x_pos = [int(i) for i in input().split()]
y_pos = [int(i) for i in input().split()]

left, right = max(x_pos), min(y_pos)
ans = 'War'
for z in range(X + 1, Y + 1):
    if left < z <= right:
        ans = 'No War'
        break
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define vi vector<long long>
#define mkp make_pair
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define watch(x) cout << (#x) << " is " << (x) << endl; cout.flush()
#define endl '\n'
#define _ << ' '
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(min(a, d), min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(max(a, d), max(b, c))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;

int a[4], ok=0;

void R(int cur, int i, string op)
{
    if(ok||(i==4&&cur!=7)) return;
    if(cur==7&&i==4)
    {
        for(int j=0; j<3; j++)
        {
            cout << to_string(a[j]) + op[j];
        }
        cout << a[3] << "=7";
        ok=1;
        return;
    }
    R(cur + a[i], i+1, op+'+');
    R(cur - a[i], i+1, op+'-');
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    for(int i=0; i<4; i++)
    {
        char ch;
        cin >> ch;
        a[i]=ch-'0';
    }
    R(a[0], 1, "");
}


Measured memory_bytes: 256
import os
import sys
from collections import deque
from operator import itemgetter

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, K = list(map(int, sys.stdin.buffer.readline().split()))
TD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

t_seen = [False] * (N + 1)
sushi_seen = [False] * N
TD.sort(key=itemgetter(1), reverse=True)

delicious = 0
que = deque()
for i, (t, d) in enumerate(TD):
    if len(que) >= K:
        break
    if not t_seen[t]:
        que.append(i)
        delicious += d
        t_seen[t] = True
        sushi_seen[i] = True
for i, (t, d) in enumerate(TD):
    if len(que) >= K:
        break
    if not sushi_seen[i]:
        que.appendleft(i)
        delicious += d
        sushi_seen[i] = True

idx = i
type_cnt = sum(t_seen)
ans = delicious + type_cnt ** 2
while idx < que[-1]:
    while idx < N and sushi_seen[idx]:
        idx += 1
    if idx >= N:
        break
    que.appendleft(idx)
    delicious -= TD[que.pop()][1]
    delicious += TD[idx][1]
    type_cnt -= 1
    score = delicious + type_cnt ** 2
    ans = max(ans, score)
    sushi_seen[idx] = True
print(ans)


Measured memory_bytes: 33088
n = int(input())
s = list(input())
l = s[:n]
r = list(reversed(s[n:]))
hashl = {}
hashr = {}
for i in range(1 << n):
    llr = []
    llb = []
    lrr = []
    lrb = []
    for k in range(n):
        if i & (1 << k):
            llr.append(l[k])
            lrr.append(r[k])
        else:
            llb.append(l[k])
            lrb.append(r[k])
    sl = (''.join(llr), ''.join(llb))
    sr = (''.join(lrr), ''.join(lrb))

    if sl not in hashl: hashl[sl] = 1
    else: hashl[sl] += 1
    if sr not in hashr: hashr[sr] = 1
    else: hashr[sr] += 1
ret = 0
for strpair, c in hashl.items():
    if strpair in hashr:
        ret += hashr[strpair] * c
print(ret)

Measured memory_bytes: 125512
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;
 
pub trait InputValue {
    fn parse(s: &str) -> Self;
}
 
pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}
 
pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}
 
pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}
 
macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
    }
}
parse_single_value!(i32, i64, f32, f64, usize, String);
 
macro_rules! parse_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
            fn parse(s: &str) -> ($($t),*) {
                let mut tokens = s.split_whitespace();
                let t = ($($t::parse(tokens.next().unwrap())),*);
                t
            }
        }
    }
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);
 
// ===
 
fn main() {
    let (n, a, b): (i64, i64, i64) = read();
    
    let mut ans : i64 = 0;
    if a > b {
        ans = 0;
    } else if n == 1 {
        if a == b {
            ans = 1;
        } else {
            ans = 0;
        }
    } else {
        ans = (b - a) * (n - 2) + 1;
    }

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    int a, b;
    cin >> a >> b;
    if (a * b % 2) cout << "Odd" << endl;
    else cout << "Even" << endl;
}


Measured memory_bytes: 3596
s = gets.chomp.to_s
case s
when "SUN"
  puts 7
when "MON"
  puts 6
when "TUE"
  puts 5
when "WED"
  puts 4
when "THU"
  puts 3
when "FRI"
  puts 2
when "SAT"
  puts 1
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define p push_back
#define mp make_pair


int main()
{
    ll t;
    t=1;
    while(t--){
       int n,k;
       cin>>n>>k;
       int a[n];
       int sum=0;
       for(int i=0;i<n;i++)cin>>a[i];
       sort(a,a+n);
       for(int i=0;i<k;i++)sum+=a[i];
       cout<<sum<<endl;


    }

}



Measured memory_bytes: 3576
/*
   О НЕТ! ОНИ ДОГОНЯЮТ!!!
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 2e5 + 7;
const int M = 5000 + 1;
const int MOD = 1e9 + 7;
const int ADD = 2000;

int a[M][M], b[M][M];
int x[N], y[N];
int dp[M][M];
int cnt[M][M];
int fact[N];
int rev[N];

inline int add(int a, int b)
{
    return (a + b >= MOD ? a + b - MOD : a + b < 0 ? a + b + MOD : a + b);
}

inline int mul(int a, int b)
{
    return (a * (ll) b) % MOD;
}

int bin(int a, int n)
{
    int res = 1;
    while (n)
    {
        if (n % 2 == 0)
        {
            a = mul(a, a);
            n /= 2;
        }
        else
        {
            res = mul(res, a);
            n--;
        }
    }
    return res;
}

int C(int n, int k)
{
    return mul(fact[n], mul(rev[n - k], rev[k]));
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    fact[0] = 1;
    for (int i = 1; i < N; i++)
    {
        fact[i] = mul(fact[i - 1], i);
    }
    /*
    rev[N - 1] = mul(fact[N - 1], MOD - 2);
    for (int i = N - 2; i >= 0; i--)
    {
        rev[i] = mul(rev[i + 1], i + 1);
    }
    */
    for (int i = 0; i < N; i++)
    {
        rev[i] = bin(fact[i], MOD - 2);
    }
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d", &x[i], &y[i]);
        a[-x[i] + ADD][-y[i] + ADD]++;
        b[x[i] + ADD][y[i] + ADD]++;
    }
    for (int i = 0; i + 1 < M; i++)
    {
        for (int j = 0; j + 1 < M; j++)
        {
            dp[i][j] = add(dp[i][j], a[i][j]);
            dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
            dp[i][j + 1] = add(dp[i][j + 1], dp[i][j]);
        }
    }
    int ans = 0;
    for (int i = 0; i < M; i++)
    {
        for (int j = 0; j < M; j++)
        {
            ans = add(ans, mul(b[i][j], dp[i][j]));
        }
    }
    for (int i = 0; i < n; i++)
    {
        int get = C(x[i] + x[i] + y[i] + y[i], x[i] + x[i]);
        ans = add(ans, -get);
    }
    ans = mul(ans, rev[2]);
    printf("%d\n", ans);
}


Measured memory_bytes: 184064
#include<stdio.h>
int main(){
    int a,b,c,d,e;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    e=c%b;
    switch (e) {
        case 0: if ((c / b-1) * d < a) {printf("Yes");}
            else printf("No");
            break;
        default:   if ((c / b) * d >= a) {
            printf("No");
        } else printf("Yes");
    }
    return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>
#include <string.h>
char a[10005];
int main(void)
{
	int n;
	scanf("%d", &n);
	scanf("%s", a);
	for(int i = 0; i < strlen(a); i++)
	{
		printf("%c", (a[i] - 'A' + n) % 26 + 'A');
	}
	return 0;
}

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

int main(void) {
	int i;
	int N;
	long long int ans, front;
	int *A;
	char buf[128], *ch;
	char *great_buf;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);
	A = (int *)calloc(N, sizeof(int));

	great_buf = (char *)calloc(N*11, sizeof(char));
	fgets(great_buf, N*11, stdin);
	ch = strtok(great_buf, " ");
	A[0] = atoi(ch);
	for(i = 1; i < N; i += 1) {
		ch = strtok(NULL, " ");
		A[i] = atoi(ch);
	}
	free(great_buf);

	ans = 0;
	front = (long long int)A[0];
	for(i = 1; i < N; i += 1) {
		if((long long int)A[i] < front) {
			ans += front - (long long int)A[i];
		} else {
			front = (long long int)A[i];
		}
	}
	free(A);
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
  ll x, y;  cin >> x >> y;
  ll ans = abs(abs(x)-abs(y));
  if(abs(x)==abs(y)){
    if(x!=y) ans +=1;
  }else if(x*y<0) ans += 1;
  else if(x*y==0 && y<x) ans += 1;
  else if(y<x) ans += 2;
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	while(1){
		int a[5],b[4]={0};
		for(int i=0;i<5;i++){
			if(!(cin>>a[i]))	return 0;
			b[a[i]]++;
		}

		if(b[1]==5 || b[2]==5 || b[3]==5 || b[1]*b[2]*b[3]>0)
			for(int i=0;i<5;i++)	cout<<3<<endl;
		else{
			int win;
			if(b[1]==0)	win=2;
			if(b[2]==0)	win=3;
			if(b[3]==0)	win=1;
			for(int i=0;i<5;i++)	cout<<(a[i]==win?1:2)<<endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define vvl vector<vector<ll>>
#define vl  vector<ll>
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||

signed main(){
	ll N,W;
	cin>>N>>W;
	vvl dp(N+10,vl(W+10));
	vl  weight(N+10),value(N+10);
	rep(i,0,N) cin>>weight[i]>>value[i];

	rep(w,0,W+1)	dp[0][w]=0;
	rep(i,0,N){
		rep(w,0,W+1){
			if(w>=weight[i]){
				dp[i+1][w]=max(dp[i][w-weight[i]]+value[i],dp[i][w]);
			}
			else{
				dp[i+1][w]=dp[i][w];
			}
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}


Measured memory_bytes: 87296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  
  ll K;
  cin >> K;
  
  ll ans = 0;
  for(int i = 1;i <= K;i++){
    for(int j = 1;j <= K;j++){
      for(int k = 1;k <= K;k++){
        ans += gcd(i,gcd(j,k));
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

//参照渡しによる解法

void swap( int& a, int& b );

int main(){

 int a, b, c;

 cin >> a >> b >> c;

 if( a > b )
  swap( a, b );
 if( b > c )
  swap( b, c );

 if( a > b )
  swap( a, b );

 cout << a << " " << b << " " << c << endl;

 return 0;

}

void swap( int& a, int& b ){

  int temp = a;
  a = b;
  b = temp;

}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

const int IINF = 2002002002;
const ll LINF = 9009009009009009009LL;

//===

const ll mod = static_cast<int>(1e9 + 7);


int main()
{
	ll N, K;
	cin >> N >> K;
	Vi A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}

	Vi g(N);
	Vi g2(N);

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (A[i] > A[j]) {
				++g[i];
				if (i < j) {
					++g2[i];
				}
			}
		}
	}

	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += g2[i] * K;
		ans %= mod;
		ans += (g[i] * ((K * K - K * (K + 1) / 2) % mod)) % mod;
		ans %= mod;
	}

	cout << ans << endl;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
    cin.sync_with_stdio(false);
    string s, t;
    cin >> s >> t;

    string a = "", b = "";
    rep(i, s.size()) {
        if (i % 2) a += s[i];
        else b += s[i];
    }

    bool ok = false;
    int j = 0;
    rep(i, t.size()) {
        if (a[j] == t[i]) j++;
        if (j == a.size()) break;
    }
    if (j == a.size()) ok = true;

    j = 0;
    rep(i, t.size()) {
        if (b[j] == t[i]) j++;
        if (j == b.size()) break;
    }
    if (j == b.size()) ok = true;

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

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

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  ll n,l; cin>>n>>l;
  ll sum = 0;
  ll a[n]; rep(i,n) cin>>a[i];
  int idx;
  rep(i,n-1){
    if(a[i]+a[i+1]>=l){
      idx = i; break;
    }
    if(i==n-2) return cout<<"Impossible"<<endl, 0;
  }
  cout << "Possible" << endl;
  reps(i,idx) cout << i << endl;
  for(int i=n-1; i>idx; i--) cout << i << endl;

  return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    long n;
    cin >> n;
    // char s[n];
    string s;
    // scanf("%s", &s);
    cin >> s;
    long right_e = 0;
    for (long i = 0; i < n; i++) if (s[i] == 'E') right_e++;
    long min_count = right_e;
    long left_w = 0;
    for (long i = 0; i < n; i++) {
        if (!min_count) break;
        if (s[i] == 'E') right_e--;
        if (s[i ] == 'W') right_e++;
        min_count = min(min_count, right_e + left_w);
    }
    cout << min_count << endl;
    
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	int p[n];
	bool same[n] = {false};
	bool next[n] = {false};
	int count = 0;
	for(int i=0;i<n;i++){
		cin >> p[i];
		if(i==p[i]-1){
			same[i]=true;
			next[i+1]=true;
			if(next[i]==false) count ++;
			else if(same[i]=true) next[i+1]=false;
		}
	}

	cout << count << endl;
	


	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int H, W, s_size;
    cin >> H >> W;
    vector<string> v;
    rep(i, H){
        string s;
        cin >> s;
        v.push_back("#"+s+"#");
        s_size = s.size();
    }

    rep(i,s_size+2){
        cout << "#";
    }
    cout << endl;
    rep(i,H){
        cout << v[i] << endl;
    }

    rep(i,s_size+2){
        cout << "#";
    }
    cout << endl;



    return 0;
}


Measured memory_bytes: 3664
#include<stdio.h>
#include<string.h>

char s[100000];
int n;

void num_to_char( char *s, int *n, int num )
{
	if ( num / 10 > 0 ) num_to_char( s, n, num / 10 );
	s[(*n)++] = '0' + num % 10;
}

int main(void)
{
	int sn;
	int cn;
	char s2[100000];
	int s2n;
	
	while ( 1 ) {
		
		scanf( "%d", &n );
		if ( n == 0 ) break;
		scanf( "%s", s );
		
		while ( n-- ) {
		
			sn = 0;
			s2n = 0;
			cn = 1;
			while ( s[sn] != '\0' ) {
				
				if ( s[sn] == s[sn+1] ) cn++;
				else {
					num_to_char( s2, &s2n, cn );
					s2[s2n++] = s[sn];
					cn = 1;
				}
				
				sn++;
			}
			
			s2[s2n] = '\0';
			
			strcpy( s, s2 );
		}
		
		printf( "%s", s );
		putchar( '\n' );
	}
	
	return 0;
}

Measured memory_bytes: 692
//Code by: Nikhil Shukla, MMMUT GKP
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define V vector
#define pb push_back
#define all x x.begin(),x.end()
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc ll t; cin>>t; while(t--)
#define tc1 ll tt=1; while(tt--)
#define fir first
#define sec second
#define mod 1000000007
#define out1(x) cout<<x<<"\n";
#define out2(x,y) cout<<x<<" "<<y<<"\n";
#define debug() cout<<"I am in\n";
#define Vll vector<long long>
#define FOR(i,x,n) for(ll i=x;i<n;i++)
#define RFOR(i,x,n) for(ll i=x;i>=n;i--)
////////////////////////////////////////////////////////////////////////////////////////
/*vector<ll>graph[100001];
vector<ll>temp;
vector<bool>visited(100001,false);
//long long count=0;
void dfs(long long node,ll dp[])
{
        visited[node]=1;
        for(ll i=0;i<graph[node].size();i++)
        {
            if(!visited[graph[node][i]])
            dfs(graph[node][i],dp);
            dp[node]=max(dp[node],1+dp[graph[node][i]]);
        }
}*/


void solve(string grid[],ll n,ll m)
{
    ll dp[n+1][m+1];
    FOR(i,0,n+1)
    FOR(j,0,m+1)
    dp[i][j]=0;
    dp[1][1]=1;
    FOR(i,1,n+1)
    {
        FOR(j,1,m+1)
        {
            if(grid[i-1][j-1]=='#')
            continue;
            dp[i][j]=max(dp[i][j],(dp[i-1][j]+dp[i][j-1])%mod);
        }
    }
    cout<<dp[n][m]<<"\n";
}
int main()
{
    fast()
    tc1
    {
        ll n,m;
        cin>>n>>m;
        string grid[n];
        FOR(i,0,n)
        {
            cin>>grid[i];
        }
        solve(grid,n,m);
    }
    
    return 0;
}


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

using namespace std;

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

    vector<vector<long long> >v(n+1,vector<long long>(4)),dp(n+1,vector<long long>(4));

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>v[i][j];
        }
    }
    long long ans=INT_MIN;
    for(int i=0;i<3;i++) {
        dp[0][i]=v[0][i];
        if(dp[0][i]>ans) ans=dp[0][i];
    }

    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            if(!j) dp[i][j]=max(dp[i-1][j+1],dp[i-1][j+2])+v[i][j];
            else if(j==1) dp[i][j]=max(dp[i-1][j-1],dp[i-1][j+1])+v[i][j];
            else dp[i][j]=max(dp[i-1][j-1],dp[i-1][j-2])+v[i][j];

            if(dp[i][j]>ans) ans=dp[i][j];
        }
    }
    cout <<ans<<endl;

    return 0;
}




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

int main() {
  int a, b;
  cin >> a >> b;
  for(int i=0; i<1010; i++) {
    if(i*2/25==a&&i/10==b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
N ,M ,X = map(int, input().split())
A = list(map(int,input().split()))
rcost = 0
lcost = 0
for i in range(X):
    if i in A:
        lcost += 1
for  i in range(X + 1, N):
    if i in A:
        rcost += 1
print(min(lcost, rcost))




Measured memory_bytes: 2940
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(){
  string kigo = ".,!? ";
  string a = "abc";
  string d = "def";
  string g = "ghi";
  string j = "jkl";
  string m = "mno";
  string p = "pqrs";
  string t = "tuv";
  string w = "wxyz";
  string syu;
  int keta,n,count;
  int flag1 = 0;
  int flag2 = 0;
  cin >> n;
  string nn;
  for(int i = 0; i < n;i++){
    cin >> nn;
    syu = "";
    for(int i = 0; i < nn.length();i++){
      if(nn[i] == '1'){
        flag1 = 1;
        flag2 += 1;
      }else if(nn[i] == '2'){
        flag1 = 2;
        flag2 += 1;
      }else if(nn[i] == '3'){
        flag1 = 3;
        flag2 += 1;
      }else if(nn[i] == '4' ){
        flag1 = 4;
        flag2 += 1;
      }else if(nn[i] == '5'){
        flag1 = 5;
        flag2 += 1;
      }else if(nn[i]== '6'){
        flag1 = 6;
        flag2 += 1;
      }else if(nn[i] == '7'){
        flag1 = 7;
        flag2 += 1;
      }else if(nn[i] == '8'){
        flag1 = 8;
        flag2 += 1;
      }else if(nn[i] == '9'){
        flag1 = 9;
        flag2 += 1;
      }else if(nn[i] == '0'){
        if(flag1 == 0){
        }else{
          flag2 -= 1;
          if(flag1 == 1){
            syu += kigo[(flag2)%5];
            flag1 = 0;
          }else if(flag1 == 2){
            syu += a[flag2%3];
            flag1 = 0;
          }else if(flag1 == 3){
            syu += d[flag2%3];
            flag1 = 0;
          }else if(flag1 == 4){
            syu += g[flag2%3];
            flag1 = 0;
          }else if(flag1 == 5){
            syu += j[flag2%3];
            flag1 = 0;
          }else if(flag1 == 6){
            syu += m[flag2%3];
            flag1 = 0;
          }else if(flag1 == 7){
            syu += p[flag2%4];
            flag1 = 0;
          }else if(flag1 == 8){
            syu += t[flag2%3];
            flag1 = 0;
          }else if(flag1 == 9){
            syu += w[flag2%4];
            flag1 = 0;
          }
          flag2 = 0;
        }
      }
    }
      cout << syu << endl;
  }
}

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




int main() {
	
    
    string S;
    cin>>S;
    
    if((S[2]==S[3])&&(S[4]==S[5]))
    {
    	cout<<"Yes"<<endl;
    }
    else
    {
    	cout<<"No"<<endl;
    }
    
    
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100009];
int main(){
	int n,flag=0,ans=1;//flag=1 s flag=-1 j
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(i==1) continue;
		if((flag==1)&&a[i]<a[i-1]){
			ans++;
			flag=0;
		}
		else
		if((flag==-1)&&a[i]>a[i-1]){
			ans++;
			flag=0;
		}
		else
		if(flag==0){
			if(a[i]<a[i-1]) flag=-1;
			if(a[i]>a[i-1]) flag=1;
		}
		
	}
	printf("%d\n",ans);
	return 0;
}

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

void solve(){
	int n;
	cin >> n;
	int a[n], b[n], c[n], dp[n][3] = {};
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i] >> c[i];
	} 
	dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0];
	for(int i = 1; i < n; i++){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

Measured memory_bytes: 5964
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  ll n;
  cin >> n;
  vector<ll> k(100001,0);
  ll ans=0;
  rep(i,n){
    ll a;
    cin >> a;
    k[a]++;
    ans+=a;
  }
  int q;
  cin >> q;
  rep(i,q){
    ll b,c;
    cin >> b >> c;
    ans=ans+(c-b)*k[b];
    k[c]+=k[b];
    k[b]=0;
    cout << ans << endl;
  }
}


Measured memory_bytes: 4024
s = list(input())
k = int(input())

j = 1
while j<len(s) and s[j] == s[0]:
    j+=1
if j == len(s):
    print((len(s)*k)//2)
else:
    s += s[:j]
    s = s[j:]

    result = j//2

    i = 1
    while i < len(s):
        if s[i] == s[i-1]:
            result += k-1
            i += 1
        i += 1

    i = 1
    while i < len(s)-j:
        if s[i] == s[i-1]:
            result += 1
            i += 1
        i += 1

    print(result)


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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back

const int N = 1e5 + 10;

int n, mod;
int up[N], down[N], pref[N], suff[N];
vector<int> child[N], vi[N];

void add(int &x, int y) { x = (x + y) % mod; }
void Sup(int pre, int u)    {
    up[u] = 1;
    for(int v: vi[u]) if(v != pre)  {
        Sup(u, v);
        up[u] = 1ll * up[u] * (up[v] + 1) % mod;
    }
}
void Sdown(int pre, int u, int val)  {
    down[u] = (val + 1) % mod;
    int cnt = 0;    pref[0] = 1;
    for(int v: vi[u]) if(v != pre)
        cnt ++, pref[cnt] = 1ll * pref[cnt - 1] * (up[v] + 1) % mod;
    int tmp =  1ll;
    for(int i = vi[u].size() - 1; i >= 0; --i) {
        int v = vi[u][i];
        if(v != pre) {
            cnt --;
            child[u].pb(1ll * pref[cnt] * tmp % mod);
            tmp = 1ll * tmp * (up[v] + 1) % mod;
        }
    }
    reverse(child[u].begin(), child[u].end());
    cnt = -1;
    for(int v: vi[u]) if(v != pre)
        cnt ++, Sdown(u, v, 1ll * child[u][cnt] * down[u] % mod);
}
signed main()
{
    //freopen("test.inp", "r", stdin);
    scanf("%d%d", &n, &mod);
    FOR(i, 1, n - 1) {
        int u, v; scanf("%d%d", &u, &v);
        vi[u].pb(v); vi[v].pb(u);
    }
    Sup(1, 1); Sdown(1, 1, 0);
    //cout << up[3] << ' ' << down[3] << '\n';
    FOR(i, 1, n)    {
        int val = 1ll * up[i] * down[i] % mod;
        printf("%d\n", val);
    }
}


Measured memory_bytes: 21248
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt //最初の整数が読み込まれる
    val c = sc.nextInt //2番目に出てきた整数が読み込まれる
    var a1 = 0
    var c1 = 0
    // val c = sc.nextInt //3番目に出てきた整数が読み込まれる
    if ((a + c) < 1 || (a + c) >= 100000) {
      println("out")
    }
    if ((a + c) > 0 && (a + c) <= 100000){
      a1 = a%2
      c1 = c%2
      if (a1 == c1){
        if (a1 == 1) {
          println("Odd")
        }
        if (a1 == 0) {
          println("Even")
        }
      }
      if (a1 != c1){
        println("Even")
      }
    }
  }
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

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

  int N;
  cin >> N;
  string s;
  cin >> s;
  vl RG(N, 0ll);
  vl GB(N, 0ll);
  vl RB(N, 0ll);
  map<int, ll> mpRB;
  rep(i, 0, N-1) {
    char ch1 = s[i];
    rep(j, i+1, N) {
      char ch2 = s[j];
      if ((ch1 == 'R' && ch2 == 'G') || (ch1 == 'G' && ch2 == 'R')) {
        RG[j]++;
      }
      if ((ch1 == 'G' && ch2 == 'B') || (ch1 == 'B' && ch2 == 'G')) {
        GB[j]++;
      }
      if ((ch1 == 'R' && ch2 == 'B') || (ch1 == 'B' && ch2 == 'R')) {
        RB[j]++;
      }
    }
  }
  rep(i, 1, N) {
    RG[i] += RG[i-1];
    GB[i] += GB[i-1];
    RB[i] += RB[i-1];
  }
  ll ans = 0ll;
  for (int i = N-1; i > 0; i--) {
    char ch = s[i];
    if (ch == 'R') {
      ans += GB[i-1];
    }
    if (ch == 'G') {
      ans += RB[i-1];
    }
    if (ch == 'B') {
      ans += RG[i-1];
    }
  }
  ll cnt = 0ll;
  rep(diff, 1, N) {
    rep(i, 0, N) {
      if (i + 2 * diff > N - 1) break;
      set<char> se;
      se.insert(s[i]);
      se.insert(s[i+diff]);
      se.insert(s[i+2*diff]);
      if (se.size() == 3) {
        cnt++;
      }
    }
  }

  cout << ans -cnt << endl;


  return 0;
};


Measured memory_bytes: 3704