akhauriyash/Code-Regression huggingface dataset:
K, T = map(int, raw_input().split())
nums = [int(t) for t in raw_input().split()]

max_1 = max(nums)
nums.remove(max_1)
sum_remain = sum(nums)
if sum_remain >= max_1-1:
    print 0
else:
    print (max_1 - sum_remain - 1)
    

Measured memory_bytes: 2568
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
  int N;
  cin>>N;
  vector<int> k;
  while(N){
    k.push_back((N-1)%26);
    N=(N-1)/26;
  }
  for(int i=k.size()-1;i>=0;i--)cout<<(char)('a'+k[i]);
}
signed main(){
		ios_base::sync_with_stdio(0);cin.tie(0);
    int T=1;
    //cin>>T;
    while(T--)solve();
}

Measured memory_bytes: 3592
#include<iostream>
#include<bits/stdc++.h> 
#include<string>
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define IN insert
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define NL cout<<endl
#define ll long long int
#define ld long double
#define vl vector<ll>
#define sl set<ll>
#define ml map<ll,ll>
#define sc set<char>
#define li list<ll>
#define vp vector<pair<ll, ll> >
#define vs vector<string>
#define ss set<string>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define REPIT(it,a) for(auto it=a.begin();it!=a.end();it++)
#define DB(x) cout<<"Debug "<<x<<endl
#define N 1e16
#define mod (ll)1000000007
using namespace std;

int main()
{

ios::sync_with_stdio(0);
cin.tie(0);
ll n;
cin>>n;
ll h[n];
REP(i,0,n) cin>>h[i];
vl dp(n,N);
dp[0]=0;
REP(i,0,n){
 REP(j,1,3){
  if(i+j<n)
   dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
 }
}
cout<<dp[n-1]<<endl;
return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void);

int main(void)
{
    int H, W, i, j;

     while(1){
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0){
            break;
        }
            for(i = 0; i < H; i++){
                for(j = 0; j < W; j++){
                    printf("#");
                }
                printf("\n");
            }
        printf("\n");
    }
    return(0);
}


Measured memory_bytes: 2132
n = int(input())

t_score = h_score=0

for i in range(n):
    taro, hanako = input().split()
    if taro==hanako:
        t_score+=1
        h_score+=1
    elif taro < hanako:
        h_score+=3
    else:
        t_score+=3

print("%d %d" %(t_score,h_score))


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

map<int,int> a;
int ans,n,i,x;

int main(){
    cin >> n;
    for(i=1;i<=n;i++){
    	cin >> x;
    	a[x]++;
    }	
    for(map<int,int>::iterator it=a.begin();it!=a.end();it++) {
        if(it->second<it->first)
			ans+=it->second;
        else if(it->second>it->first)
			ans+=it->second-it->first;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4736
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
vector<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
vector<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    ll k; cin >> k;
    ll m = 7;
    int ans = -1;
    rep(i, k+1) {
        //cout << m << endl;
        m %= k;
        if (m == 0) {
            ans = i + 1;
            break;
        }
        m *=10;
        m += 7;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {a:usize,b:usize}
    println! {"{}",
    if a * b % 2 == 0 {
        "Even"
    }else{
        "Odd"
    }
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

ll n;
int furui[1000000]={};
int sosu[1000000];

int main(){
  scanf("%lld",&n);
  ll ind=2;
  int ind2 =0;
  int flag=1;
  //make sosu map
  while(ind<1000000){
    while(ind<1000000 && furui[ind]==1){
      ind++;}
    if(ind>=1000000) break;
    sosu[ind2]=ind;
    ind2++;
    for(int i=1;i*ind<1000000;i++){
      furui[i*ind]=1;}
  }
  /*for(ll i=0;i<ind2;i++){
    printf("%d\n",sosu[i]);}*/
  ll ans=0;
  for(int i=0;i<ind2;i++){
    int count=0;
    while(n%sosu[i]==0){
      n/=sosu[i];
      count++;}
    int njo=1;
    while(count-njo>=0){
      count-=njo;
      njo++;}
    ans += njo-1;
  }
  if(n>1000000){
    ans+=1;}
  printf("%lld\n",ans);
  
  
  return 0;
}


Measured memory_bytes: 5944
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x)) 
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
int w[100];
int v[100];
ll dp[110][100010];
int main() {
  int N, W;
  cin >> N >> W;
  rep(i, N)
    cin >> w[i] >> v[i];
  rep(i, N){
    rep(j, W+1){
      if(j - w[i] >= 0){
        chmax(dp[i+1][j], dp[i][j-w[i]] + v[i]);
      }
      chmax(dp[i+1][j], dp[i][j]);
    }
  }
    
  cout << dp[N][W] << endl;
}


Measured memory_bytes: 79360
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    k, s = i_map()

    count = 0

    for x in range(k+1):
        for y in range(k+1):
            z = s - x - y
            if z >= 0 and z <= k:
                count += 1

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string b;
  cin >> b;
  if ( b.at(0) == 'A' ) cout << 'T' << endl;
  else if ( b.at(0) == 'T' ) cout << 'A' << endl;
    else if ( b.at(0) == 'C' ) cout << 'G' << endl;
      else if ( b.at(0) == 'G' ) cout << 'C' << endl;
}


Measured memory_bytes: 256
#include<iostream>

int main()
{
	int x, y;
	std::cin >> x >> y;
	int absx = std::abs(x), absy = std::abs(y);
	int ret = {};
	if (x >= 0)
	{
		if (absx > absy)
		{
			++ret;
			x = -x;
		}
	}
	else
	{
		if (absx < absy)
		{
			++ret;
			x = -x;
		}
	}
	int a = std::abs(absx - absy);
	x += a;
	ret += a;
	if (x != y)
	{
		++ret;
	}
	std::cout << ret << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int,int> >
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1<<30;
const double eps = 1e-13;

int x[200009];
LL rs[200009];
vector<LL> dc;
int fw[200009];

void up(int x,int uv){
	for(x++;x<200009;x+=x&(-x))fw[x]+=uv;
}

int qu(int x){
	int ans=0;
	for(x++;x;x-=x&(-x))ans+=fw[x];
	return ans;
}

int main(){
	DRI(n);DRI(k);
	REP(i,n){
		RI(x[i]);x[i]-=k;
		rs[i+1]=rs[i]+x[i];
	}
	REP(i,n+1)dc.PB(rs[i]);
	sort(ALL(dc));
	dc.resize(unique(ALL(dc))-dc.begin());
	LL ans=0;
	//for(LL i:dc)printf(" %lld ",i);
	REP(i,n+1){
		rs[i]=lower_bound(ALL(dc),rs[i])-dc.begin()+1;
		ans+=qu(rs[i]);
		//printf("%lld ",rs[i]);
		up(rs[i],1);
	}
	printf("%lld",ans);
}


Measured memory_bytes: 5104
n=int(input())
a=list(map(int,input().split()))
ans=0

plus=[0]*1000000
minus=[0]*1000000

for i in range(n):
  ene=i+1
  pin=a[i]
  pl,mi=ene+pin,ene-pin
  if 0<=pl<1000000:
    plus[pl]+=1
  if 0<=mi<1000000:
    minus[mi]+=1
  
for i in range(1000000):
  ans+=plus[i]*minus[i]
  

print(ans)

Measured memory_bytes: 114444
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    H, W = map(int, input().split())
    f = []
    for _ in range(H):
        f.append(input())

    ans = [[0] * W for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if f[y][x] == "#":
                ans[y][x] = "#"
                continue
            num = 0
            for i in range(8):
                ny, nx = dy8[i] + y, dx8[i] + x
                if inside(ny, nx, H, W) and f[ny][nx] == "#":
                    num += 1

            ans[y][x] = num

    for line in ans:
        print(*line, sep="")


if __name__ == '__main__':
    main()


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

using namespace std;

const long long INF = 1e18;

int n,x,a[2005],i;

int main(){
	scanf("%d%d", &n, &x);
	for(i = 0; i < n; i++)
	scanf("%d", &a[i]);
	
	long long res = INF;
	
	for(int ii = 0; ii < n; ii++){
		deque <int> d;
		long long now = (long long)ii * x;
		for(i = n - ii; i < n; i++){
			while(d.size() && a[d.back()] >= a[i])
			d.pop_back();
			d.push_back(i);
		}
		for(i = 0; i < n; i++){
			while(d.size() && (i - d.front() + n) % n > ii)
			d.pop_front();
			while(d.size() && a[d.back()] >= a[i])
			d.pop_back();
			d.push_back(i);
			now += a[d.front()];
		}	
		res = min(res, now);
	}
	printf("%lld\n", res);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	cout<<n*n*n<<endl;
}

Measured memory_bytes: 256
S = input()
n = len(S)

C = [1] * n
for i in range(n):
    if S[i] == 'R' and S[i + 1] == 'R':
        C[i + 2] += C[i]
        C[i] = 0
for i in range(n - 1, -1, -1):
    if S[i] == 'L' and S[i - 1] == 'L':
        C[i - 2] += C[i]
        C[i] = 0

print(' '.join(map(str, C)))

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main () {
    double x1,y1,x2,y2;
    scanf("%lf", &x1);
    scanf("%lf", &y1);
    scanf("%lf", &x2);
    scanf("%lf", &y2);
    double distance = 0.0;
    distance = sqrt(pow(x2-x1,2) + pow(y2-y1,2));
    printf("%lf\n", distance);
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n, q;
    string s;
    cin >> n;
    cin >> s;
    cin >> q;
    set<int> data[26];
    rep(i, n) {
        int v = s[i] - 'a';
        data[v].insert(i);
    }
    
    rep(i, q) {
        int id;
        cin >> id;
        if (id==1) {
            int iq;
            char cq;
            cin >> iq >> cq;
            iq--;
            int v = s[iq] - 'a';
            data[v].erase(iq);
            s[iq] = cq;
            v = cq - 'a';
            data[v].insert(iq);
        }
        else {
            int lq, rq;
            cin >> lq >> rq;
            lq--;
            rq--;
            int cnt = 0;
            rep(j, 26) {
                auto it = data[j].lower_bound(lq);
                if (it!=data[j].end()&&*it<=rq) {
                    cnt ++;
                }
            }
            cout << cnt << endl;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 26244
n,k=map(int,input().split())
m=10**9+7
p=1
for i in range(1,n+1):p=(p*(2*n-i)*pow(i,m-2,m))%m
if k>=n:
    print(p)
else:
    c,d=1,1
    for i in range(1,k+1):c=(c*(n-i)*pow(i,m-2,m))%m
    for i in range(1,k+1):d=(d*(n-i+1)*pow(i,m-2,m))%m
    for i in range(k+1,n):
        c=(c*(n-i)*pow(i,m-2,m))%m
        d=(d*(n-i+1)*pow(i,m-2,m))%m
        p=(p-c*d)%m
    print(p)

Measured memory_bytes: 41052
# include <stdio.h>

void bubbleSort(int a[], int n) {
  int cnt = 0;
  int s = 0;

  for (int i = 0; i < n - 1; i++) {
    for(int j = n - 1; j > i; j--) {
      if (a[j - 1] > a[j]) {
        // swap
        s = a[j - 1];
        a[j - 1] = a[j];
        a[j] = s;
        cnt++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      printf("%d", a[n - 1]);
    } else {
      printf("%d ", a[i]);
    }
  }
  printf("\n");
  printf("%d\n", cnt);
}

int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  bubbleSort(a, n);

  return 0;
}



Measured memory_bytes: 2056
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 10;
int n, k;
LL fact[maxn], fact_inv[maxn];
LL qpow(LL a, LL b)
{
    LL res = 1;
    a %= MOD;
    while(b)
    {
        if(b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
void preprocess()
{
    fact[0] = 1;
    for(int i = 1; i < maxn; i++)
        fact[i] = fact[i-1] * i % MOD;
    fact_inv[maxn-1] = qpow(fact[maxn-1], MOD - 2);
    for(int i = maxn - 2; i >= 0; i--)
        fact_inv[i] = fact_inv[i+1] * (i + 1) % MOD;
}
LL comb(int m, int n)   // n选m
{
    return fact[n] * fact_inv[m] % MOD * fact_inv[n-m] % MOD;
}
int main()
{
    preprocess();
    scanf("%d %d", &n, &k);
    LL ans = 0;
    for(int i = 0; i <= min(n - 1, k); i++)
        ans = (ans + comb(i, n) * comb(n - i - 1, n - 1) % MOD) % MOD;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  lli n, k;
  scanf("%lld %lld", &n, &k);

  lli cnt = 0;
  for ( lli a = 1; a <= n; a++ ) {
    if ( 2 * a % k == 0 )
      cnt += powl(((n-a) / k + (a-1) / k + 1), 2);
  }
  printf("%lld\n", cnt);
  return 0;
}


Measured memory_bytes: 128
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll A,B,N;cin>>A>>B>>N;
    ll m=min(B-1,N);
    ll a=A*m/B;
    ll b=A* (m/B);
    cout<<a-b<<"\n";
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
//#include<string.h>
//#include<math.h>
//#include<time.h>
//#include<ctype.h>
#define P(type,x) fprintf(stdout,"%"#type"\n" ,(x))
//#define N 100000000
int main(){
	int A[32] = { 1,1,2 }, i,n;
	for (i = 3; i < 31; i++) A[i] = A[i - 1] + A[i - 2] + A[i - 3];
	for(;~fscanf(stdin,"%d",&n),n;P(d,A[n]/3650+((A[n]%3650)!=0)));
	return 0;
}

Measured memory_bytes: 604
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)

const int maxn=2e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}
ll n ;
ll arr[maxn];
int main(){
	migmig;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> arr[i];
	}
	sort(arr,arr+n);
	for(int  i = 0 ; i < n-1 ;i++){
		if(arr[i]==arr[i+1]){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}



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

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

const ll INF = 1LL << 60;

vector<int> dp(100010, 0);

int main() {
    int n;
    cin >> n;
    vector<int> A(n + 1);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &A[i]);
    }

    int l = 1;
    dp[1] = A[1];
    for (int i = 2; i <= n; i++) {
        if (dp[l] < A[i]) {
            dp[++l] = A[i];
        } else {
            auto itr = lower_bound(dp.begin() + 1, dp.begin() + l + 1, A[i]);
            *itr = A[i];
        }
    }

    cout << l << endl;

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(A+B >= C) {
    cout << B+C << endl;
    return 0;
  }
  cout << (A+B)+B+1 << endl;
  return 0;
}

Measured memory_bytes: 256
//12-5 イルミネーション
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<stack>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<cassert>
using namespace std;
#include<boost/multiprecision/cpp_int.hpp>
namespace boost_multiprecision = boost::multiprecision;
#define LL long long
#define CINT boost_multiprecision::cpp_int
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while(true)

int W,H;
int mp[110][110];
vector< pair<int,int> > build;
bool m[110][110];

void solve(int x, int y){
    if(x-1>=0 && mp[x-1][y]==0 && m[x-1][y]==false){
        m[x-1][y] = true;
        solve(x-1,y);
    }
    if(x+1<W && mp[x+1][y]==0 && m[x+1][y]==false){
        m[x+1][y] = true;
        solve(x+1,y);
    }
    if(y-1>=0 && mp[x][y-1]==0 && m[x][y-1]==false){
        m[x][y-1] = true;
        solve(x,y-1);
    }
    if(y+1<H && mp[x][y+1]==0 && m[x][y+1]==false){
        m[x][y+1] = true;
        solve(x,y+1);
    }
    if(y%2==1){
        if(x-1>=0 && y-1>=0 && mp[x-1][y-1]==0 && m[x-1][y-1]==false){
            m[x-1][y-1] = true;
            solve(x-1,y-1);
        }
        if(x-1>=0 && y+1<H && mp[x-1][y+1]==0 && m[x-1][y+1]==false){
            m[x-1][y+1] = true;
            solve(x-1,y+1);
        }
    }
    else{
        if(x+1<W && y-1>=0 && mp[x+1][y-1]==0 && m[x+1][y-1]==false){
            m[x+1][y-1] = true;
            solve(x+1,y-1);
        }
        if(x+1<W && y+1<H && mp[x+1][y+1]==0 && m[x+1][y+1]==false){
            m[x+1][y+1] = true;
            solve(x+1,y+1);
        }
    }
    
}

int main(){
    cin >> W >> H;
    for(int i=0; i<H+4; i++){
        for(int j=0; j<W+4; j++){
            mp[j][i] = 0;
            m[j][i] = false;
        }
    }
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> mp[j+2][i+2];
            if(mp[j+2][i+2]==1) build.push_back(make_pair(j+2,i+2));
        }
    }
    W += 4;
    H += 4;

    m[0][0] = true;
    solve(0,0);

    LL ans = 0;
    for(int i=0; i<build.size(); i++){
        int x = build[i].first;
        int y = build[i].second;
        if(x-1>=0 && m[x-1][y]==true){
            ans++;
        }
        if(x+1<W && m[x+1][y]==true){
            ans++;
        }
        if(y-1>=0 && m[x][y-1]==true){
            ans++;
        }
        if(y+1<H && m[x][y+1]==true){
            ans++;
        }
        if(y%2==1){
            if(x-1>=0 && y-1>=0 && m[x-1][y-1]==true){
                ans++;
            }
            if(x-1>=0 && y+1<H && m[x-1][y+1]==true){
                ans++;
            }
        }
        else{
            if(x+1>=0 && y-1>=0 && m[x+1][y-1]==true){
                ans++;
            }
            if(x+1>=0 && y+1<H && m[x+1][y+1]==true){
                ans++;
            }
        }
        
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
int main(){
	char S[11];
	scanf("%s", S);
	if(S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I'){
		printf("Yes\n");
	}
	else printf("No\n");
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using cd = complex<ld>;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int nv, ne;
  cin >> nv >> ne;
  vector<vector<int>> g(nv, vector<int>(nv, 1'000'000'000));
  for (int i = 0; i < ne; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    --u;
    --v;
    g[u][v] = g[v][u] = c;
  }
  for (int i = 0; i < nv; i++) {
    g[i][i] = 0;
  }
  auto init = g;
  for (int k = 0; k < nv; k++) {
    for (int i = 0; i < nv; i++) {
      for (int j = 0; j < nv; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  int res = 0;
  for (int i = 0; i < nv; i++) {
    for (int j = i + 1; j < nv; j++) {
      if (init[i][j] == 1'000'000'000) {
        continue;
      }
      bool ok = true;
      for (int u = 0; u < nv; u++) {
        for (int v = u + 1; v < nv; v++) {
          if (g[u][i] + init[i][j] + g[j][v] == g[u][v]) {
            ok = false;
            break;
          }
          if (g[u][j] + init[i][j] + g[i][v] == g[u][v]) {
            ok = false;
            break;
          }
        }
      }
      res += ok;
    }
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 3672
def main(argv)
  (n, m) = gets.chomp.split(' ').map(&:to_i)
  a = gets.chomp.split(' ').map(&:to_i)
  
  s = [0] * (a.size + 1)
  n.times { |i| s[i + 1] = s[i] + a[i] }
  
  h = {}
  (n + 1).times do |i| 
    x = s[i] % m
    if h[x] == nil then
      h[x]  = 1
    else
      h[x] += 1
    end
  end
  
  t = 0
  h.each do |x, n|
    t += n * (n - 1) / 2
  end
  puts t.to_s
end

if self.to_s === 'main' then
  main(ARGV)
end

Measured memory_bytes: 13452
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, c = 0;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  for(int i = 0; i < N; i += 2) {
    if(a.at(i) / 2 * 2 != a.at(i)) {
      c++;
    }
  }
  cout << c << endl;
}

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

int main(int argc, char const *argv[]) {
  int N, A;
  cin >> N;
  cin >> A;
  N %= 500;
  if (N <= A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
#define fore(e, u, v) for (int p = e.g[u], v = e[p].y; p; v = e[p = e[p].nxt].y)
const int maxN = 107;
typedef long long LL;
const LL INF = (1LL<<63)-1;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

struct Vec {
	int g[maxN], te;
	struct edge {int y, nxt;} e[maxN << 1];
	inline void push(int x, int y) { e[++te] = (edge){y, g[x]}; g[x] = te; }
	inline void link(int x, int y) { push(x, y), push(y, x); }
	inline edge& operator [] (int x) { return e[x]; }
}e;

int n;
int ans[maxN];

int mxdep(int x, int fa) {
	int res = 1;
	fore (e, x, y) if (y != fa) 
		res = max(res, mxdep(y, x) + 1);
	return res;
}

void pre(int x, int fa, int dep) {
	int cnt = 0;
	fore (e, x, y) if (y != fa) {
		pre(y, x, dep+1);
		++cnt;
	}
	ans[dep] = max(ans[dep], max(cnt, 1));
}

LL gao(int l) {
	LL res = 1;
	rep (i, 1, l) res = res * ans[i];
	return res;
}

int main() {

	n = ri();
	For (i, 1, n) e.link(ri(), ri());

	int mi = n+1;
	rep (i, 1, n) {
		int tp = mxdep(i, 0);
		if (tp < mi) mi = tp;
	}
	rep (x, 1, n) fore (e, x, y) if (x < y) {
		int tp = max(mxdep(x, y), mxdep(y, x));
		if (tp < mi) mi = tp;
	}

	LL res = INF;
	rep (i, 1, n) {
		int tp = mxdep(i, 0);
		if (tp == mi) {
			memset(ans, 0, sizeof ans);
			int cnt = 0;
			fore (e, i, y) { 
				pre(y, i, 1);
				++cnt;
			}
			res = min(res, cnt * gao(mi-1));
		}
	}
	rep (x, 1, n) fore (e, x, y) if (x < y) {
		int tp = max(mxdep(x, y), mxdep(y, x));
		if (tp == mi) {
			memset(ans, 0, sizeof ans);
			pre(x, y, 1);
			pre(y, x, 1);
			res = min(res, 2 * gao(mi));
		}
	}
	printf("%d %lld\n", mi, res);

	return 0;
}


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

int h[100005];

int main(void){
	cin.tie(0);ios::sync_with_stdio(false);
    int n,k,ans=999999999;cin>>n>>k;
    for(int i=0;i<n;i++)cin>>h[i];
    sort(h,h+n);
    for(int i=0;i<=n-k;i++){
			ans=min(ans,h[i+k-1]-h[i]);
	}
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 640
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: i64 = it.next().unwrap().parse().unwrap();
    let x: i64 = it.next().unwrap().parse::<i64>().unwrap();
    let d: i64 = it.next().unwrap().parse::<i64>().unwrap();
    if d == 0 {
        let mut set = std::collections::BTreeSet::new();
        for i in 0..(n + 1) {
            let m = x * i - x * (n - i);
            set.insert(m);
        }
        println!("{}", set.len());
        return;
    }
    let mut map = std::collections::BTreeMap::<i64, Vec<(i64, i64)>>::new();
    for i in 0..(n + 1) {
        let m = x * i - x * (n - i);
        let v = (m % (2 * d).abs() + 2 * d.abs()) % (2 * d.abs());
        let po = map.entry(v).or_insert(vec![]);
        let (l, r) = if d >= 0 {
            let l = i * (i - 1) / 2 * d;
            let r = n * (n - 1) / 2 * d - (n - i) * (n - 1 - i) / 2 * d;
            (l, r)
        } else {
            let l = i * (i - 1) / 2 * d;
            let r = n * (n - 1) / 2 * d - (n - i) * (n - 1 - i) / 2 * d;
            (r, l)
        };
        let s = n * (n - 1) / 2 * d;
//        println!("{}: {} {}", i, m + 2 * l - s, m + 2 * r - s);
        po.push((m + 2 * l - s, m + 2 * r - s));
    }
    let mut ans = 0;
    for (_, a) in map {
        let mut a = a;
        a.sort();
        a.reverse();
        let mut now = a.pop().unwrap();
        while let Some((l, r)) = a.pop() {
            if l <= now.1 {
                now.1 = std::cmp::max(now.1, r);
            } else {
                ans += (now.1 - now.0) / (2 * d.abs()) + 1;
                now = (l, r);
            }
        }
        ans += (now.1 - now.0) / (2 * d.abs()) + 1;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 37116
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

#define pll pair<ll,ll>

ll f(ll n) {
  if (n % 2)
    return ((n + 1) / 2) % 2;
  else {
    return ((n / 2) % 2) ^ n;
  }
}
 
int main() {
  ll a, b;
  cin >> a >> b;
  cout << (f(a - 1) ^ f(b)) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int ex,i,j,high[10];


    for(i = 0;i < 10;i++){
        scanf("%d",&high[i]);
    }

    for(i = 0;i < 10;i++){
        for(j = i + 1;j < 10;j++){
            if(high[i] > high[j]){
                ex = high[i];
                high[i] = high[j];
                high[j] = ex;
            }
        }
    }

    printf("%d\n%d\n%d\n",high[9],high[8],high[7]);
    return 0;
}

Measured memory_bytes: 2672
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    char c;
    cin >> c;
    if('a' <= c && c <= 'z') cout << 'a' << endl;
    else cout << 'A' << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n, k; cin >> n >> k;
    vector<ll> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    if(k >= n){
        cout << 0 << endl;
        return 0;
    }

    sort(h.rbegin(), h.rend());

    ll ans = 0;
    for(int i=k; i<n; i++) ans += h[i];
    cout << ans << endl;

    return 0;
}


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

int main() {
    int N;
    vector<string> s(N);
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> s[i];
    }
    int ans = 0;
    int rightB = 0;
    int leftA = 0;
    int both = 0;
    for (int i = 0; i < N; ++i) {
        int j = 0;
        // while(j < s[i].size() && s[i][j] != 'A' && s[i][j] != 'B') j++;
        if(s[i][j] == 'B') rightB++;

        int l = s[i].size() - 1;
        // while(l >= 0 && s[i][l] != 'A' && s[i][l] != 'B') l--;
        if(s[i][l] == 'A') leftA++;

        if(s[i][j] == 'B' && s[i][l] == 'A') both++;

        for (int k = 0; k < s[i].size() - 1; ++k) {
            if(s[i][k] == 'A' && s[i][k+1] == 'B') ans++;
        }
    }
    ans = ans + min(rightB,leftA);
    if(rightB == both && leftA == both && both != 0) ans--;
    cout << ans << endl;
    return 0;
}

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

struct node { int id,x; }h[510];

int a[250010],num[510],n;
bool bo[250010];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline bool cmp(node x,node y) { return x.id<y.id; }

int main()
{
	n=rd();
	for (int i=1;i<=n;i++) num[i]=rd();
	for (int i=1;i<=n;i++) h[i]=(node){num[i],i},bo[num[i]]=true,a[num[i]]=i;
	sort(h+1,h+n+1,cmp);
	int now=1;
	for (int i=1;i<=n;i++)
	{
		int hh=h[i].x-1;
		for (int j=1;j<=hh;j++)
		{
			while (bo[now]) now++;
			bo[now]=true;a[now]=h[i].x;now++;
		}
	}
	now=n*n;
	for (int i=n;i;i--)
	{
		int hh=n-h[i].x;
		for (int j=1;j<=hh;j++)
		{
			while (bo[now]) now--;
			bo[now]=true;a[now]=h[i].x;now--;
		}
	}
	for (int i=1;i<=n;i++)
	{
		int hh=0;
		for (int j=1;j<num[i];j++) if (a[j]==i) hh++;
		if (hh!=i-1) { puts("No");return 0; }
	}
	puts("Yes");
	for (int i=1;i<=n*n;i++) printf("%d ",a[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 2432
(n,),a=$<.map{|l|l.split.map &:to_i}
a=[i=0]+a
puts a.map{|v|s=*"node %d:"
d=i,v
i>1&&(s<<:parent
d<<a[i/2])
j=2*i
n>=j&&(s<<:left
d<<a[j])
n>j&&(s<<:right
d<<a[j+1])
s<<p
i+=1
s*" key = %d, "%d}[1,$$]

Measured memory_bytes: 6180
#! python3
# stable_sort.py

import copy

def num_from_card(card):
    return int(card[1:])

def bubble_sort(A, N):
    A_ = copy.copy(A)
    flag = True
    while flag:
        flag = False
        for i in range(N-1, 0, -1):
            if num_from_card(A_[i]) < num_from_card(A_[i-1]):
                A_[i-1], A_[i] = A_[i], A_[i-1]
                flag = True
    return A_

def selection_sort(A, N):
    A_ = copy.copy(A)
    for i in range(N-1):
        minj = i
        for j in range(i, N):
            if num_from_card(A_[j]) < num_from_card(A_[minj]):
                minj = j
        if i != minj:
            A_[i], A_[minj] = A_[minj], A_[i]
    return A_

def is_stable(A, sorted_A, N):
    A_nums = [int(x[1:]) for x in A]
    same_num = [x for x in set(A_nums) if A_nums.count(x) > 1]
    A_symbols, sorted_A_symbols = [], []
    flag = 'Stable'
    for num in same_num:
        if [card[0] for card in A if int(card[1:]) == num] != [card[0] for card in sorted_A if int(card[1:]) == num]:
            flag = 'Not stable'
            break
    return flag

N = int(input())
cards = [x for x in input().split(' ')]

bubble_sorted = bubble_sort(cards, N)
selection_sorted = selection_sort(cards, N)

print(' '.join(bubble_sorted))
print(is_stable(cards, bubble_sorted, N))
print(' '.join(selection_sorted))
print(is_stable(cards, selection_sorted, N))


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;


int main(){
	int n;
	int b[100],a[110];
	cin>>n;

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

	int ans=b[0]+b[n-2];
	for (int i = 0; i < n-2; i++){
		ans+=min(b[i],b[i+1]);
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
N, M, C = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

ans = 0

N.times do
  a = gets.split.map(&:to_i)
  sum = C
  [a, b].transpose.each do |x, y|
    sum += x*y
  end
  ans += 1 if sum > 0
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main()

{
    int n;
    string s;
    cin>>n>>s;
    if(count(s.begin(),s.end(),'R') > count(s.begin(),s.end(),'B')) {
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
from collections import deque
from copy import deepcopy

H, W = [int(i) for i in input().split()]
raw_grid = [list(input()) for _ in range(H)]
grid = deepcopy(raw_grid)

queue = deque()
queue.append((0, 0, 0))
count = None
while queue:
    ny, nx, steps = queue.popleft()
    if not (0 <= ny < H and 0 <= nx < W):
        continue
    if grid[ny][nx] == "#":
        continue
    grid[ny][nx] = "#"
    if ny == H - 1 and nx == W - 1:
        count = steps
    for dy, dx in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        queue.append((ny+dy, nx+dx, steps+1))

if count is None:
    ans = -1
else:
    ans = 0
    for line in raw_grid:
        ans += line.count(".")
    ans -= 2
    ans -= (count - 1)

print(ans)


Measured memory_bytes: 41456
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n], A = 0;
    for (int i = 0; i < n; i++) cin >> a[i], A ^= a[i];
    for (int i = 0; i < n; i++) cout << (A ^ a[i]) << ' ';
    cout << endl;
}


Measured memory_bytes: 4344
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
 
int N;
vector<int> v;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  v.resize(3);
  cin >> v[0] >> v[1] >> v[2];
  sort(all(v));
  int res = 0, c=0, p1, p2;
  for(int i=0; i<3; ++i)
    if((v[i]%2) == 0){
     if(c == 0)
       p1 = i, p2 = i;
     else p2 = i;
      ++c;
    }
  if(c==1){
    if(p1 == 0){
      ++v[1], ++v[2];
    }
    else if(p1 == 1){
      ++v[0], ++v[2];
    }
    else{
      ++v[0], ++v[1];
    }
    ++res;
  }
  else if(c == 2){
    if(p1 == 0){
      if(p2 == 1) ++v[0], ++v[1];
      if(p2 == 2) ++v[0], ++v[2];
    }
    else{
      ++v[1],  ++v[2]; 
    }
    ++res;
  }
  res += (v[2] - v[0])/2;
  res += (v[2] - v[1])/2;
  cout << res << "\n";
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define all(v) v.begin(),v.end()
#define fi first
#define se second
const int inf = 1e9;
int mod = 1e9+7;

int a[30];
signed main(){
	int x, y;
	repi(i,1,13)a[i+1] = i;a[1] = 13;
	scanf("%lld%lld", &x, &y);
	if(a[x] == a[y])printf("Draw\n");
	else if(a[x] > a[y])printf("Alice\n");
	else printf("Bob\n");
	return 0;
}

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

#define LMAX 102

int main(void){
	char sa[LMAX],sb[LMAX],sc[LMAX],turn,temp,winner;
	int i,la,lb,lc;
	scanf("%s %s %s",sa,sb,sc);
	la=strlen(sa);
	lb=strlen(sb);
	lc=strlen(sc);
	temp='a';
	while(la<LMAX){
		turn=temp;
		if(turn=='a'){
			if(la>0){
				temp=sa[0];
				for(i=0;sa[i]!='\0';i++){
					sa[i]=sa[i+1];
				}
			}else{
				winner='A';
				break;
			}
		}
		if(turn=='b'){
			if(lb>0){
				temp=sb[0];
				for(i=0;sb[i]!='\0';i++){
					sb[i]=sb[i+1];
				}
			}else{
				winner='B';
				break;
			}
		}
		if(turn=='c'){
			if(lc>0){
				temp=sc[0];
				for(i=0;sc[i]!='\0';i++){
					sc[i]=sc[i+1];
				}
			}else{
				winner='C';
				break;
			}
		}
		la=strlen(sa);
		lb=strlen(sb);
		lc=strlen(sc);
		turn=temp;
	}
	printf("%c\n",winner);
	return 0;
}

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

int main() {
    string S;
    long K;
    cin>>S>>K;
    vector<int>arr;
    int tmp = 1;
    bool check = true;
    for(int i=1;i<S.size();++i){
        if(S[i]==S[i-1])tmp++;
        else {
            check = false;
            arr.push_back(tmp);
            tmp = 1;
        }
    }
    if(tmp>0)arr.push_back(tmp);
    int s, t;
    if(S[0]==S[S.size()-1]){
        s = arr[0];
        t = arr[arr.size()-1];
        arr[0] += arr[arr.size()-1];
        arr.pop_back();
    }
    /**
    for(int i=0;i<arr.size();++i){
        cout<<arr[i]<<" ";
    }
    cout<<endl;
    **/
    if(!check){
    long ans = 0;
    if(S[0]==S[S.size()-1]){
        for(int i=1;i<arr.size();++i){
            ans += arr[i]/2*K;
        }
        ans += arr[0]/2*(K-1) + s/2 + t/2;
    }
    else{
        for(int i=0;i<arr.size();++i){
            ans += arr[i]/2*K;
        }
    }
    cout<<ans<<endl;
    }
    else{
        cout<<K*S.size()/2<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

long long int cal_pattern(int from, int until, int count, std::vector<std::vector<std::vector<long long int>>> &memo, const std::vector<long long int>& pieces, const long long int sum, const long long int y) {
	if (--count < 0) return from == until ? 1 : 0;
	if (memo[from][until][count] >= 0) return memo[from][until][count];
	long long int s = 0;
	long long int result = 0;
	for (auto i = from; i != until; i = (i + 1) % pieces.size()) {
		s += pieces[i];
		if (s + y >= sum / 5) {
			result += cal_pattern((i + 1) % pieces.size(), until, count, memo, pieces, sum, y);
		}
	}
	return memo[from][until][count] = result;
}
long long int solve(const std::vector<long long int>& pieces, const long long int y) {
	const auto sum = std::accumulate(pieces.begin(), pieces.end(), 0LL);
	std::vector<std::vector<std::vector<long long int>>> memo(pieces.size(), std::vector<std::vector<long long int>>(pieces.size(), std::vector<long long int>(5, -1)));
	long long int result = 0;
	for (auto from = 0; from < pieces.size(); ++from) {
		long long int s = pieces[from];
		for (auto size = 1; size < pieces.size(); ++size) {
			if (s + y >= sum / 5) result += cal_pattern((from + size) % pieces.size(), from, 4, memo, pieces, sum, y);
			s += pieces[(from + size) % pieces.size()];
		}
	}
	return result / 5;
}

int main() {
	int n, y; std::cin >> n >> y;
	std::vector<long long int> pieces(n); for (auto& p : pieces) std::cin >> p;
	std::cout << solve(pieces, y) << std::endl;
}


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, 3) {
        if (s[i] == 'o') {
            cnt++;
        }
    }

    // 処理
    cout << 700 + cnt * 100 << endl;

    // 出力

    return 0;
}


Measured memory_bytes: 256