akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9+7;
const ll mod= 1e9 + 7;

ll C[15];
vector<ll> A[15];
ll ans = INF;


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

	ll N, M, X; cin >> N >> M >> X;

	FOR(i, 0, N) {
		A[i].resize(M);
		cin >> C[i];
		FOR(j, 0, M)cin >> A[i][j];
	}


	FOR(i, 0, 1 << N) {
		vector<ll> p(M);
		ll cur = 0;
		ll num = i;
		ll cost = 0;


		FOR(j, 0, N) {
			if (num % 2 == 1) {//購入
				cost += C[j];
				FOR(k, 0, M)p[k] += A[j][k];
				
			}

			num /= 2;
		}

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

		if (p[0] >= X) {
			ans = min(ans, cost);
		}


	}

	if(ans!=INF)cout << ans << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int abs_diff(int m6,int m7){
    int w=m6-m7;
    if(w<0){
        w=0-w;
    }
    return w;
}
int min1(int c4,int c5){
    if(c4>c5){
        return c5;
    }
    else{
        return c4;
    }
}
int main(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int j=0;j<n;j++){
        cin>>arr[j];
    }
    int dp[n]={-1};
    dp[0]=0;dp[1]=abs_diff(arr[1],arr[0]);
    for(int j=2;j<n;j++){
        int min1=INT_MAX;
        for(int z=j-1;z>=j-k && z>=0;z--){
                int f=abs_diff(arr[z],arr[j])+dp[z];
                if(f<min1){
                    min1=f;
                }
        }
        dp[j]=min1;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


typedef  long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;


#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=2e5+5;
int mod=1e9+7;

ll mul (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll add (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a+b+mod)%mod;
}
ll fastpow(ll b, ll p)
{
    if(p==0)
        return 1;
    ll ans=fastpow(b,p/2);
    ans=mul(ans,ans);
    if(p%2)ans=mul(ans,b);
    return ans;
}
int arr[N];

int main()
{
    FIO
    set<pair<int,int>>st;
    int n;
    cin>>n;
    int co=0;
    set<pair<int,int>> ::iterator it;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
}
for(int i=n-1;i>=0;i--)
{
    int x=arr[i];
    it=st.upper_bound({x,1e9});
    if(it==st.end())
    {
       /// cout<<"notfound "<<x<<endl;
        co++;
        st.insert({x,co});
    }
    else
    {
    ///    cout<<"found--> "<<it->first<<" "<<it->second<<" \n";
        int f=it->second;
        st.erase(it);
        st.insert({x,f});

    }

}
        cout<<co;

    return 0;
}

Measured memory_bytes: 8612
N,K = gets.split.map(&:to_i)
ans = 0
N.downto(1) do |n|
	if  n>=K
		ans += 1.0
		next
	end
	c = Math.log2(K/n.to_f).ceil
	ans += (1/2.0)**c
end
print sprintf("%.12f", ans/N.to_f)

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef unordered_set <char> sc;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

int N,Q;
string str;
sc merge(sc i,sc j){
	if (i.size() > j.size()) swap(i,j);
	
	aFOR(a,i){
		j.insert(a);
	}
	
	return j;
}

struct node{
	int s,e,m;
	node *l,*r;
	sc val;
	
	node(int ss,int ee){
		s = ss; e = ee; m = (s+e)/2;
		
		if (s == e) val.insert(str[s]);
		else{
			l = new node(s,m);
			r = new node(m+1,e);
			val = merge(l->val,r->val);
		}
	}
	
	void upd(int p,char v){
		if (s == e && e == p){
			val.clear();
			val.insert(v);
			return;
		}
		
		
		if (p > m) r->upd(p,v);
		else l->upd(p,v);
		
		val = merge(l->val,r->val);
	}
	
	sc qry(int a,int b){
		if (a <= s && e <= b) return val;
		if (a > e || b < s) return sc {};
		
		return merge(l->qry(a,b),r->qry(a,b));
	}
}*root;

int main(){
	fast;
	cin>>N>>str>>Q;
	
	root = new node(0,N-1);
	
	
	
	FOR(i,0,Q-1){
		int t,a; cin>>t>>a;
		a--;
		if (t == 1){
			char b; cin>>b;
			root->upd(a,b);
		}else{
			int b; cin>>b;
			b--;
			cout<<root->qry(a,b).size()<<'\n';
		}
	}
	
	
}



Measured memory_bytes: 242716
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    b = 0
    count = 1
    for i in range(N-1):
        if b == 0:
            if a[i+1]-a[i] > 0:
                b = 1
            elif a[i+1] == a[i]:
                continue
            else:
                b = -1
        elif b == 1:
            if a[i+1]-a[i] >= 0:
                continue
            else:
                count += 1
                b = 0
        else:
            if a[i+1] <= a[i]:
                continue
            else:
                count += 1
                b = 0
                
    print(count)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 12992
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n, m = nm()
if m >= 2 * n:
    c = m - 2 * n
    print(n + (c // 4))
else:
    print(m // 2)


Measured memory_bytes: 3316
from itertools import accumulate

maxL = 10**3

N = int(input())
Ls = list(map(int, input().split()))

nums = [0] * (2*maxL+1)
for L in Ls:
    nums[L] += 1

accNums = list(accumulate(nums))

ans = 0
for A in range(1, maxL+1):
    if nums[A] == 0: continue
    for B in range(A+1, maxL+1):
        if nums[B] == 0: continue
        ans += nums[A] * nums[B] * (accNums[A+B-1]-accNums[B])

for A in range(1, maxL+1):
    if nums[A] < 2: continue
    ans += nums[A] * (nums[A]-1) // 2 * (accNums[2*A-1]-nums[A])

for A in range(1, maxL+1):
    if nums[A] < 3: continue
    ans += nums[A] * (nums[A]-1) * (nums[A]-2) // 6

print(ans)


Measured memory_bytes: 3188
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>H(N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	int n = 0;
	for (int i = 0; i < N - 1; i++) {
		if (H[i] >= H[i + 1]) {
			n++;
		}
		else {
			n = 0;
		}
		chmax(ans, n);
	}
	cout << ans << endl;
}


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

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

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    
    int ans = INF;
    
    rep(i, max(x, y) + 1){
        ans = min(ans, 2 * c * i + max(0, x - i) * a + max(0, y - i) * b);
    }
    
    cout << ans <<endl;

    return 0;
}

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

int main(){
  string S; cin>>S;
  rep(i,3){
    if(S[i]==S[i+1]){
      cout<<"Bad\n";
      return 0;
    }
  }
  cout<<"Good\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int selectionSort(int A[],int N){
	int i,j,sm,count=0,p;
	for(i = 0; i<N; i++){
		sm = i;
		for(j = i+1; j<N; j++){
			if(A[sm]>A[j]){
				sm = j;
			}
		}
		swap(A[i],A[sm]);
		if(i!=sm)count++;
	}
	return count;
}

int main(){
	int A[100],N,count;
	cin >> N;
	for(int i = 0; i<N; i++)cin >> A[i];
	count = selectionSort(A,N);

	for(int i = 0; i<N; i++){
		if(i>0)cout << " ";
		cout << A[i];
	}
	cout << endl << count << endl;

	return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    //fast;
    int n,p;
    cin>>n;
    p=ceil((float)n/1000);
    cout<<p*1000-n;
}


Measured memory_bytes: 3628
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
	int N, M;
	cin >> N >> M;
	vector<int> vec(N);
	int64_t x = 0;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		vec.at(i) = tmp;
		x += tmp;
	}
//	x = x / (4 * M);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (vec.at(i)*4*M >= x) ans++;
	}
	if (ans >= M) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    int N, M, C;
    cin >> N >> M >> C;
    int *B = new int[M];
    int **A = new int*[N]; 
    rep(i,N) A[i] = new int[M];
    rep(j,M) cin >> B[j];
    rep(i,N) rep(j,M) cin >> A[i][j];
    int cnt = 0;
    int sum = C;
    rep(i,N) {
        rep(j,M) sum += A[i][j]*B[j];
        if(sum>0) cnt++;
        sum = C;
    }
    cout << cnt << endl;
	return 0;
}

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

if 400 <= N <= 599:
    print(8)
elif 600 <= N <= 799:
    print(7)
elif 800 <= N <= 999:
    print(6)
elif 1000 <= N <= 1199:
    print(5)
elif 1200 <= N <= 1399:
    print(4)
elif 1400 <= N <= 1599:
    print(3)
elif 1600 <= N <= 1799:
    print(2)
elif 1800 <= N <= 1999:
    print(1)


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

using namespace std;

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

    int K, X;
    cin >> K >> X;
    for (int i = X - K + 1; i < X + K - 1; ++i) cout << i << " ";
    cout << X + K - 1 << '\n';
}

Measured memory_bytes: 256
var c = inp => { console.log(inp) };
var is_kaibun = s => {
    var ln = s.length;
    var ans = true;
    for (var i = 0, l = (ln - 1) / 2; i < l; i++) {
        // console.log(s[i])
        // console.log(s[ln - i - 1])
        if (s[i] != s[ln - i - 1]) {
            ans = false;
            break;
        }
    }
    return ans;
}
var s = require("fs").readFileSync("/dev/stdin", "utf8").slice(0, -1)
var ln = s.length;
var ans = is_kaibun(s)
    && is_kaibun(s.slice(0, (ln - 1) / 2))
    && is_kaibun(s.slice((ln + 1) / 2), ln);
console.log(ans ? "Yes" : "No");

Measured memory_bytes: 11468
#include<stdio.h>

int main (){
    int a;
    scanf("%d",&a);
    
  if(a == 22){
  	printf("Christmas Eve Eve Eve");
  }else if(a == 23){
    printf("Christmas Eve Eve");
  }else if(a == 24){
    printf("Christmas Eve");
  }else if(a == 25){
    printf("Christmas");
  } 
    return 0;
  
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<cmath>
using namespace std;

typedef long long ll;

int main(int, char**)
{
    int n;
    cin >> n;

    // 偶数はi/2個かi/2-1個の選び方しかありえない
    // 奇数はi/2+1個かi/2個の選び方しかありえない
    vector<ll> max_choice(n+1,0);   // 偶数からi/2個 or 奇数からi/2+1個 選んだ場合の総和の最大値
    vector<ll> min_choice(n+1,0);   // 偶数からi/2-1個 or 奇数からi/2個 選んだ場合の総和の最大値

    ll tmp;
    for (int i = 1; i <= n; i++) {
        cin >> tmp;
        if (i == 1) {
            max_choice[i] = tmp;
            min_choice[i] = 0;
        } else if (i == 2) {
            max_choice[i] = max(max_choice[i-1], tmp);
            min_choice[i] = 0;
        } else if (i % 2 == 0) {
            max_choice[i] = max(max_choice[i-1], max_choice[i-2] + tmp);
            min_choice[i] = max(min_choice[i-1], min_choice[i-2] + tmp);
        } else {
            max_choice[i] = max_choice[i-2] + tmp;
            min_choice[i] = max(max_choice[i-1], min_choice[i-2] + tmp);
        }
    }

    if (n % 2 == 0)
        cout << max_choice[n] << endl;
    else
        cout << min_choice[n] << endl;

    return 0;
}

Measured memory_bytes: 6396
s = input()
ls = len(s)
ans = [1]*ls
for i in range(ls-2):
    if s[i:i+2] == "RR":
        ans[i+2] += ans[i]
        ans[i] = 0

for i in range(ls-1, 1, -1):
    if s[i-1:i+1] == "LL":
        ans[i-2] += ans[i]
        ans[i] = 0

print(*ans)

Measured memory_bytes: 10872
<?php
while(true) {
	fscanf(STDIN, "%d", $n);
	if($n == 0)
		break;
// 	echo $n;
	fscanf(STDIN, "%d", $m);
// 	echo $m;
	$input = array(array(), array(), array(), array(),);
	for($i=0 ; $m>$i ; $i++) {
		fscanf(STDIN, "%d,%d,%d", $a, $b, $d);
		$input[$a][$b] = $d;
		$input[$b][$a] = $d;
	}

	$already = array_pad(array(), $n, false);
	$already[0] = true;

	$result = 0;
	while(true) {
		$f = false;
		foreach ($already as $k => $flg) {
			if(! $flg){
				$f = true;
			}
		}
		if(! $f)
			break;

		$index = 0;
		$tmp = PHP_INT_MAX;
		for($i = 0 ; $i < $n ; $i++) {
			if(! $already[$i])
				continue;

			foreach ($input[$i] as $key => $val) {
				if($tmp > $val && ! $already[$key]) {
					$index = $key;
					$tmp = $val;
				}
			}
		}
		$already[$index] = true;
		$result += $tmp;
	}
	echo (($result - (($n-1) * 100)) / 100)."\n";
}

Measured memory_bytes: 16464
#include <bits/stdc++.h>
using namespace std;
int n;
int a[20];
int x[20][20];
int y[20][20];

int counter (int x){
  if (x==0) return 0;
  return counter (x >> 1) + (x & 1);
}
int main(){

cin>>n;
for (int i=1; i<=n; i++){
  cin>>a[i];

    for (int j=1; j<=a[i]; j++){
      cin>>x[i][j]>>y[i][j];

  }
}

int ans=0;
for (int bits=1; bits< (1 << n); bits++){
  bool check=true;
  for (int i=1; i<=n; i++){
    if (!(bits & (1<<(i-1)))) continue;
    for (int j=1; j<=a[i]; j++){
      if (((bits>>(x[i][j]-1))&1)^y[i][j]) check=false;
    }
  }
  if (check)ans=max(ans, counter(bits));
}
cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int P,Q,R;
   cin>>P>>R>>Q;
   int S[3]={P+Q,Q+R,R+P};
   int min=P+R+Q;
   for(int i=0;i<3;i++){
       if(S[i]<min){
           min=S[i];
       }
   }
   cout<<min<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////

int main(){
    int n;scanf("%d",&n);
    printf("0\n");fflush(stdout);
    int l=0,r=n;
    int lp=2,rp=2;
    char s[15];
    scanf("%s",s);
    if(s[0]=='V')lp=0;
    else if(s[0]=='M'){
        lp=1;rp=1;
    }
    if(lp==0){
        return 0;
    }
    
    while(1){
        int m=(l+r)/2;
        printf("%d\n",m);
        fflush(stdout);
        scanf("%s",s);
        if(s[0]=='V')return 0;
        int mp;
        if(s[0]=='M')mp=1;
        else mp=2;
        int a=0;
        if(lp==mp)a++;
        if((m-l)%2==0)a++;
        if(a==1){
            r=m;
            rp=mp;
        }else{
            l=m;
            lp=mp;
        }
    }
    return 0;
}


Measured memory_bytes: 852
int main(){
    int A;
    int temp;
    scanf("%d",&A);
    
    if(A/100==1) temp=900;
    if(A/100==9) temp=100;
  
    if(A/10%10==1) temp=temp+90;
    if(A/10%10==9) temp=temp+10;
  
    if(A%10%10==1) temp=temp+9;
    if(A%10%10==9) temp=temp+1;
  
    printf("%d\n",(temp));  
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define INF 1000000000
#define MOD 1000000007

void solve() {
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, 1, n+1) {
        ll x = n / i;
        ans += i * (x * (x + 1) / 2);
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3520
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

int main()
{
	INT N;
	cin >> N;
	vector<INT> a(N);

	for (size_t i = 0; i < N; i++)
	{
		cin >> a[i];
		a[i]--;
	}

	auto cnt = 0;
	for (size_t i = 0; i < N; i++)
	{
		if (a[i] != i)
		{
			if (a[a[i]] != i)
			{
				cout << "NO" << endl;
				return 0;
			}
			cnt++;
		}
	}
	
	if (cnt != 2 && cnt != 0)
	{
		cout << "NO" << endl;
	}
	else
	{
		cout << "YES" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    int l[h][w];
    for(int i=0; i<h; i++){
        cin >> s[i];
    }
    
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j]=='#'){
               l[i][j] = 99;
            }
            else{
                int a = 0;
                if(0<=i-1 && i-1<=h-1 && 0<=j-1 && j-1<=w-1){
                    if(s[i-1][j-1]=='#'){
                   a++;
                    }
                }
                if(0<=i-1 && i-1<=h-1 && 0<=j && j<=w-1){
                    if(s[i-1][j]=='#'){
                   a++;
                    }
                }
                if(0<=i-1 && i-1<=h-1 && 0<=j+1 && j+1<=w-1){
                    if(s[i-1][j+1]=='#'){
                   a++;
                    }
                }
                if(0<=i && i<=h-1 && 0<=j-1 && j-1<=w-1){
                    if(s[i][j-1]=='#'){
                   a++;
                    }
                } 
                if(0<=i && i<=h-1 && 0<=j+1 && j+1<=w-1){
                    if(s[i][j+1]=='#'){
                   a++;
                    }
                }
                if(0<=i+1 && i+1<=h-1 && 0<=j-1 && j-1<=w-1){
                    if(s[i+1][j-1]=='#'){
                   a++;
                    }
                }
                if(0<=i+1 && i+1<=h-1 && 0<=j && j<=w-1){
                    if(s[i+1][j]=='#'){
                   a++;
                    }
                }
                if(0<=i+1 && i+1<=h-1 && 0<=j+1 && j+1<=w-1){
                    if(s[i+1][j+1]=='#'){
                   a++;
                    }
                }
                l[i][j] = a;
            }
        }
    }
    
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(l[i][j]==99){
                cout << "#";
            }
            else{
                cout << l[i][j];
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;

  int t1 = h1 * 60 + m1;
  int t2 = h2 * 60 + m2;
  
  int a = t2 - t1;
  cout << a - k << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p1=1000000007;
int n;
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--) {
        string s;cin>>s;
        int n=s.size();
        int k;cin>>k;
        ll ans=0;
        if(k==1){
            for(int i=1;i<n;i++){
                ans=ans+9;
            }
            int c=s[0]-'0';
            for(int i=1;i<=c;i++)ans++;
        }
        else if(k==2){
            for(int i=2;i<n;i++){
                ans=ans+9*9*(i-1);
            }
            string temp;temp.resize(n);
            for(int i=1;i<=9;i++){
                temp[0]=i+'0';
                for(int j=1;j<n;j++){
                    for(int k=1;k<=9;k++){
                        temp[j]=k+'0';
                        if(temp<=s)ans++;
                    }
                    temp[j]='0';
                }
            }
        }
        else{
            for(int i=3;i<n;i++){
                ans=ans+(9*9*9*(i-1)*(i-2))/2;
            }
            string temp;temp.resize(n);
            for(int i=1;i<=9;i++){
                temp[0]=i+'0';
                for(int j=1;j<n;j++){
                    for(int k=j+1;k<n;k++){
                        for(int l=1;l<=9;l++){
                            for(int m=1;m<=9;m++){
                                temp[j]=l+'0';
                                temp[k]=m+'0';
                                if(temp<=s)ans++;
                            }
                        }
                        temp[k]='0';
                    }
                    temp[j]='0';
                }
            }
        }
        cout<<ans;
    } 
    return 0;   
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int h = 0;
        while(true){
            String in = scanner.nextLine();
            StringBuilder m = new StringBuilder(in);

            if(m.toString().equals("-")){
                break;
            }

            for(int i = Integer.parseInt(scanner.nextLine()); i > 0; i--){
                h = Integer.parseInt(scanner.nextLine());
                String sub = m.substring(0, h);
                m.delete(0, h);
                m.append(sub);
            }
            System.out.println(m.toString());
        }

        scanner.close();
    }
}



Measured memory_bytes: 26136
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int a = sc.nextInt();
        final int b = sc.nextInt();
        final int t = sc.nextInt();

        System.out.println((int)Math.floor((t+0.5) / a) * b);
    }
}


Measured memory_bytes: 23252
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int N,K;
  char S[51];

  scanf("%d %d", &N,&K);
  scanf("%s", S);

  S[K-1] = S[K-1] - 'A' + 'a';

  printf("%s\n",S);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007



int main() {

  long long Q,H,S,D,N;
  cin >> Q >> H >> S >> D >> N;

  long long q = Q*8,h = H*4,s = S*2;
  long long mini2 = min(q,min(h,min(s,D)));

  long long ans = N / 2 * mini2;
  if(N%2!=0) ans += min(q/2,min(h/2,S));

  cout << ans << endl;
}


Measured memory_bytes: 256
C = []

for _ in range(3):
    C.append(list(map(int, input().split())))

def f():
    for i in range(2):
        if not C[i + 1][0] - C[i][0] == C[i + 1][1] - C[i][1] == C[i + 1][2] - C[i][2]:
            return False
    for i in range(2):
        if not C[0][i + 1] - C[0][i] == C[1][i + 1] - C[1][i] == C[2][i + 1] - C[2][i]:
            return False
    return True

if f():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <stdio.h>

int main()
{
    int N, i, j, flag = 0, mini;
    int x[105];
    scanf("%d",&N);
    for(i = 0;i < N;i++)
        scanf("%d",&x[i]);
    for(i = 0;i < N - 1;i++)
    {
        mini = i;
        for(j = i;j < N;j++)
        {
            if(x[j] < x[mini])
                mini = j;
        }
        int t = x[i];
        x[i] = x[mini];
        x[mini] = t;
        if(i != mini)
            flag++;
    }
    for(i = 0;i < N;i++)
    {
        if(i > 0) printf(" ");
        printf("%d",x[i]);
    }
    printf("\n%d\n",flag);
    return 0;
}


Measured memory_bytes: 2080
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;

const int ch_MAX = 1200;
char ch[ch_MAX],CH[ch_MAX];

int input(){
	int length = 0;
	for (;; length++){
		scanf("%c",&ch[length]);
		if (ch[length] == '\n')break;
	}
	return length;
}

void changeCH(int length){
	for (int i = 0; i < length; i++){
		bool flag = islower(ch[i]);
		if (flag==true)CH[i] = toupper(ch[i]);
		else CH[i] = tolower(ch[i]);
		cout << CH[i];
	}
	cout << endl;
}

int main(){
	int length;
	
	length = input();

	changeCH(length);

	return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
string place[20];
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0},n,m;
int serch(int y,int x)
{
	int ans=1;
	place[y][x]='#';
	for(int i=0,ax,ay;i<4;i++)if((ay=dy[i]+y)<m&&(ax=dx[i]+x)<n&&ay>=0&&ax>=0&&place[ay][ax]=='.')ans+=serch(ay,ax);
	return ans;
}
int main() {
	while(cin>>n>>m,n,m){
		for(int i=0;i<m;i++)cin>>place[i];
		for(int i=0;i<m;i++)for(int j=0;j<n;j++)if(place[i][j]=='@')cout<<serch(i,j)<<endl;
	}
}

Measured memory_bytes: 1232
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        String s = sc.next();
        int n = s.length();
        int [] c = new int[n + 1];
        for (int i = 1; i <= n; i++) c[i] = s.charAt(i - 1) - '0';
        if (c[n] == 1 || c[1] == 0 || c[n - 1] == 0) {
            out.println(-1);
            out.close();
            return;
        }
        boolean ok = true;
        for (int i = 1; i <= n - 1; i++) if (c[i] != c[n - i]) ok = false;
        if (!ok) {
            out.println(-1);
            out.close();
        }
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 1; i < n; i++) if (c[i] == 1) a.add(i);
        ArrayList<Edge> res = new ArrayList<>();
        int root = 1; int sz = n; int cur = 2;
        Collections.sort(a, Comparator.reverseOrder());
        int idx = 0;
        while (idx < a.size()) {
            for (int i = 0; i < sz - a.get(idx) - 1; i++) {
                res.add(new Edge(root, cur++));
            }
            int nextRoot = cur;
            res.add(new Edge(root, cur++));
            root = nextRoot; sz = a.get(idx);
            ++idx;
        }
        for (Edge e: res) out.println(e.a + " " + e.b);
        out.close();
    }

    static class Edge {
        int a; int b;
        Edge(int a, int b) {
            this.a = a; this.b = b;
        }
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 59124
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


n = gif
a = []
rep n do
a << gif-1
end
count = 0
cr = 0
list = array n, false
jd = false
loop {
cr = a[cr]
count += 1
if list[cr]
  break
elsif cr == 1
  jd = true
  break
else
  list[cr] = true
end
}

puts jd ? count : -1

Measured memory_bytes: 6196
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a)
#define MAX 100005
using namespace std;
typedef long long ll;
int main()
{
    int l,r,d,ans=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
        if(i%d==0)
        ans++;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n;
    string s;
    cin >> n;
    s = to_string(n);

    if (s[0] == '1' && n % 10 == 0)
        cout << 10 << endl;
    else
    {
        int ans = 0;
        for (int i = 0; i < s.size(); i++)
        {
            ans += n % 10;
            n /= 10;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	rep(i, 3) if (s[i] == '1') ans++;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
typedef tuple<ll,int,int,int,int,int,int,int>T;
#define PI 3.14159265358979
const int MAX = 510000;
const int MOD = 1000000007;
//この設定だとn<10^7が限界。maxの０を一個増やせば100msかかるが一桁増やせる。
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll N,M;
  cin>>N>>M;
  vector<ll>A(M);
  ll use[10]={0,2,5,5,4,5,6,3,7,6};
  rep(i,M){
  	cin>>A[i];
  } 
  string dp[11000];
  rep(i,11000){dp[i]="-";}
  dp[0]="";
  for(int i=0;i<=10000;i++){
    if(dp[i]=="-"){continue;}
  	for(auto a:A){
      ll p=dp[i+use[a]].size(),q=dp[i].size();q++;
      if(dp[i+use[a]]=="-"){dp[i+use[a]]=dp[i]+(char)(a+'0');continue;}
      if(p<q){
      	dp[i+use[a]]=dp[i]+(char)(a+'0');
      }
      else if(p==q){
      	dp[i+use[a]]=max(dp[i]+(char)(a+'0'),dp[i+use[a]]);
      }
    }
  }
  cout<<dp[N];
} 


Measured memory_bytes: 45696
s = input()
n = 0
while True:
    llist = input().split(" ")
    if llist[0] == "END_OF_TEXT":
        print(n)
        break
    else:
        i = len(llist)
        for m in range(0,i):
            m = int(m)
            if llist[m].lower() == s:
                n += llist[m].lower().count(s)
        continue


Measured memory_bytes: 5556
function Main(input) {
  var A = parseInt(input.split(" ")[0]);
  var B = parseInt(input.split(" ")[1]);
  var C = parseInt(input.split(" ")[2]);
  var output = C - (A - B);
  if(output < 0){
     console.log(0);
     }else{
      console.log(output); 
     }
  
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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


int ans=0;
int N, M, Q;
vector<int> A;
vector<int> a, b, c, d;

void dfs(int idx, int pre){
    // Aを直接書き換えてOK。
    if(idx == N){
        int tmp = 0;
        for(int i=0;i<Q;i++){
            if(A.at(b.at(i)-1)-A.at(a.at(i)-1) == c.at(i)){
                tmp += d.at(i);
            }
        }
        ans = max(ans, tmp);

    }else{
        for(int i=pre;i<=M;i++){
            A.at(idx) = i;
            dfs(idx+1, i);
        }
    }

}

int main(){
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    A.resize(N);

    for(int i=0;i<Q;i++){
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }

    dfs(0, 1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3664
import sys

sys.setrecursionlimit(10 ** 7)
debug = True

debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()

INF = 10 ** 18
MOD = 10 ** 9 + 7

def main():
    N = II()
    S = SI()

    mark = [-1 for i in range(N)]

    from collections import defaultdict
    posd = defaultdict(list)

    for i, c in enumerate(S):
        posd[c].append(i)

    for i in range(N):
        si = S[i]

        # headの文字の位置のリスト
        pos_list = posd[si]

        for pos in pos_list:
            if pos >= i:
                # 自分より前のところだけを探す
                continue

            # この場合は直前により長いシーケンスを見ているので見なくていい
            if pos > 0 and S[pos - 1] == S[i - 1]:
                continue

            # どこまであうかをやっていく
            for j in range(N):
                # 前回見たシーケンスは見ない
                # 自分のところまで来てたらやめる
                if pos+j == i:
                    break
                # 突き抜けたらやめる
                if i+j == N:
                    break

                you = pos + j
                me = i + j

                # 違ったらやめる
                if S[you] != S[me]:
                    break

                # 同じなら、マークする
                mark[you] = max(mark[you], j)

    dprint(mark)
    print(max(mark)+1)



main()

Measured memory_bytes: 44908
#include <cstdio>

using namespace std;

int v[200010],v1[200010];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&v[i]);
    int st=1,dr=n;
    for(int i=n;i>=1;i--)
    {
        int nr=n-i+1;
        if(nr%2==1) {v1[st]=v[i];st++;}
        else {v1[dr]=v[i];dr--;}
    }
    for(int i=1;i<=n;i++)
        printf("%d ",v1[i]);
    return 0;
}


Measured memory_bytes: 3712
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

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

const int nmax = 2e5+7;

int main()
{
    optimizeIO();

    int n;
    cin>>n;

    int v = ((n+999)/1000)*1000;

    cout<<v-n<<endl;

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  long long b;
  long long e;
  bool flg = true;
  for(int i = 0; i < s.length(); i++){
    if(flg){
      if(s[i] == 'A'){
        b = i;
        flg = false;
      }
    }
    else
      if(s[i] == 'Z') e = i;
  }
  cout << e-b+1LL << endl;
  return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    string s;cin>>s;
    ll cnt=0,ans=0;
    REP(i,s.size()){
        if(s[i]=='B') cnt++;
        else ans+=cnt;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s;
  cin >> s;
  int n = len(s);
  int m = 0;
  rep(i,0,n) {
    m += s[i]-'0';
    m %= 9;
  }
  if (m == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int ans = 1; char now = s[0];
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == now) {
			i++;
			now = '*';
			if (i >= s.size())break;
		}
		else {
			now = s[i];
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        long a;
        cin >> a;
        if(a % 2 == 1) cnt++; 
    }

    if(cnt % 2 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}
 

Measured memory_bytes: 256
import math
import numpy as np

N = int(input())
x = [0] * N
y = [0] * N

count = 0

for a in range(N):
    x[a],y[a] = (int(num) for num in input().split())
    
for b in range(N):    
    for c in range(N):
        count += np.sqrt((x[b]-x[c])*(x[b]-x[c]) + (y[b]-y[c])*(y[b]-y[c]))
        
ans = count * int(math.factorial(N-1)) / int(math.factorial(N))
print(ans)

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

int n, r;
int head, val[51], nxt[51];

int main() {
	while (cin >> n >> r, n) {
		head = 0;
		for (int i=0; i<n; ++i) {
			val[i] = n-i;
			nxt[i] = i+1;
		}
		
		for (int i=0; i<r; ++i) {
			int p, c;
			cin >> p >> c;
			if (p == 1) continue;
			
			int it_p = head;
			while (p>2) it_p = nxt[it_p], --p;
			
			int it_c = it_p;
			while (c) it_c = nxt[it_c], --c;
			
			int tmp = head;
			head = nxt[it_p];
			nxt[it_p] = nxt[it_c];
			nxt[it_c] = tmp;
		}
		
		cout << val[head] << endl;
	}
}


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

const int MAX_N = 3010;
const int inf = 1LL << 60;

int a[MAX_N];

int N; int memo[MAX_N][MAX_N];

int dfs(int s, int t){ 
  
  if(memo[s][t] != -inf){ return memo[s][t];}
  //常にs<=tである約束に注意
  if( s == t ){ 
    if(N%2){return a[s];} //太郎でも二郎でも、これを返すしかもうない
    else{ return -a[s];}
  }
  
  bool side = false;
  if( (N-t+s)%2 ){ //太郎の番
    side = !side;
  }
  
  int res;
  
  if(side){ 
    res = max(dfs(s+1,t)+a[s],dfs(s,t-1)+a[t]);
  }
  else{
    res = min(dfs(s+1,t)-a[s],dfs(s,t-1)-a[t]);
  }
  
  return memo[s][t] = res;
}

  
  
signed main(void){ 
  
  cin >> N;
  
  for(int i = 0; i < N; i++){ cin >> a[i];} 
  
  for(int i = 0; i < MAX_N; i++){
    for(int j = 0; j < MAX_N; j++){ 
      memo[i][j] = -inf;
    }
  }
  
  cout << dfs(0,N-1) << endl;
  
  return 0;
}

Measured memory_bytes: 71168
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

KK = 10**5+5

N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

dp = [0 for i in range(KK)]

for i in range(KK):
    for j in a:
        if i-j >= 0 and dp[i-j] == 0: dp[i] = 1

if dp[K] == 1:
    print("First")
else:
    print("Second")

Measured memory_bytes: 80204