akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = input()

count_if_all_white = 0
for c in S:
    if c == "#":
        count_if_all_white += 1

l_count = 0
r_count = sum([1 for c in S if c == "."])
count_if_contain_black = l_count+r_count
for c in S:
    if c == "#":
        l_count += 1
    else:
        r_count -= 1
        
    count_if_contain_black = min(count_if_contain_black, l_count+r_count)

print(min(count_if_all_white, count_if_contain_black))

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

int A[100005], B[100005], C[100005];

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

    int N;
    cin >> N;

    for(int i=1; i<=N; i++)
        cin >> A[i];
    
    for(int i=1; i<=N; i++)
        B[i] = __gcd(B[i-1], A[i]);
    
    for(int i=N; i>=1; i--)
        C[i] = __gcd(C[i+1], A[i]);

    int ans = 0;

    for(int i=1; i<=N; i++)
        ans = max(ans, __gcd(B[i-1], C[i+1]));

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1408
S, T = input(), input()
M = [[0]*26 for _ in range(26)]
a = ord('a')

for s,t in zip(S,T):
    M[ord(s)-a][ord(t)-a]=1

f = True
for i in range(26):
    sr, sc = 0, 0
    for j in range(26):
        sr += M[i][j]
        sc += M[j][i]

    if sr>1 or sc>1:
        f = False
        break

print('Yes' if f else 'No')

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

bool is_palindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main() {

    string S;
    cin >> S;

    int a = (S.size() - 1) / 2;
    int b = (S.size() + 1) / 2;

    if (is_palindrome(S) && is_palindrome(S.substr(0, a)) && is_palindrome(S.substr(b))) {
        cout << "Yes" << endl;

    } else {
        cout << "No" << endl;
    }


    return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a.begin(),a.end());
  cout<<a[n-1]-a[0]<<endl;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;



template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    ll H; cin >> H;
    int count = 0;
    while(H != 0){
        H /= 2;
        // printf("H = %lld\n", H);
        count ++;
    }
    cout << (1ll<<count) - 1 << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    for(int i = 0; i<n; i++) {
        cin >> s[i];
    }
    int cnt;
    while (true) {
        bool cont = false;
        for (int i = 0; i<n; i++) {
            if (s[i] % 2 != 0) cont = true;
            s[i] = s[i] / 2;
        }
        if(cont) break;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import bisect

N=int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

count=0
for i in range(N):
    a_cand = bisect.bisect_right(A,B[i]-1)
    c_cand = N-bisect.bisect_right(C,B[i])
    count += a_cand*c_cand
print(count)


Measured memory_bytes: 29172
#include<bits/stdc++.h>
#define lld long long int
#define faster ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector< lld > 

using namespace std;


int main(){

  int n;
  cin>>n;
  vi input(n);
  for(int i = 0;i<n;i++) cin>>input[i];
  
  int ans = 0;
  for(int i = 0;i<n;i++)
    while(input[i]%2 == 0)ans++,input[i] = input[i]/2;
  
  cout<<ans<<endl;

}

Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Scanner;

public class Main {
  	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean ans = true;

		HashSet<Integer> hs = new HashSet<>();

		for(int i=0;i<N;i++){
			int ai = sc.nextInt();

			if(hs.contains(ai)){
				ans = false;
				break;
			}

			hs.add(ai);
		}

		if(ans){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}


	}
}

Measured memory_bytes: 99792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

s = input()

print(len(s)//2 - s.count("p"))

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> v;
void solve()
{
  for(ll i=0;i<=130;i++)
    v.push_back(i*i);
}
int main()
{
  solve();
  int a,b;
  cin>>a>>b;
  ll c[a][b];
  for(ll i=0;i<a;i++)
  {
    for(ll j=0;j<b;j++)cin>>c[i][j];
  }
  ll sum=0;
  for(ll i=0;i<a;i++)
  {
    ll count=i+1;
    while(count<a)
    {
     ll p=0;
    for(ll j=0;j<b;j++)
    {
      p+=(c[count][j]-c[i][j])*(c[count][j]-c[i][j]);
    }
    //cout<<p<<endl;
      for(ll j=0;j<v.size();j++)
      {
          
        if(p==v[j])
        {
          sum++;
          break;
        }
        if(v[j]>p)
          break;
      }
      count++;
    }
  }
  cout<<sum;
}
     
  

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int p, q;
	
	while(scanf("%d%d", &p, &q) != EOF){
		int minimum;
		int maximum;
		int loop = false;
		map<int, int> memo;
		for(maximum=0; p; ++maximum){
			p *= 10;
			if(memo.count(p)){
				loop = true;
				minimum = memo[p];
				break;
			}else{
				memo[p] = maximum;
				printf("%d", p/q);
				p %= q;
			}
		}
		putchar('\n');
		
		if(loop){
			rep(i, maximum)
				putchar(i<minimum ? ' ' : '^');
			putchar('\n');
		}
	}
}

Measured memory_bytes: 0
/* ***********************************************************************************************************
                Created By - TANISHQ GUPTA (tanishq_code_c)                                   
   ************************************************************************************************************/
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>



using namespace std;

#define int             long long
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

void stringsplitter(string s, string delim,string arr[]){
    char *ptr = strtok((char *)s.c_str(), (char *)delim.c_str());
    int i=0;
    while(ptr!=NULL){
        arr[i]=((string)ptr);
        ptr = strtok(NULL,(char *)delim.c_str());
        i++;
    }
}

int string_to_int(string s){
    int ans = 0;
    int p=1;
    for(int i=s.size()-1;i>=0;i--){
        ans += (s[i]-'0')*p;
        p *= 10;
    }
    return ans;
}


void t_c_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    
    int n; cin >> n;
    string s; cin >> s;
    if(s.size()>n){
        for(int i=0;i<n;i++) cout << s[i];
        cout << "..." << endl;
    }
    else{
        cout << s << endl;
    }

}



int32_t main()
{
    t_c_c();
    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
  set<string> q;
  int n;
  cin>>n;
  for(int i =0;i < n; ++i){
    string s;
    cin>>s;
    q.insert(s);
  }
  cout<<q.size()<<endl;
  return 0; 
}

Measured memory_bytes: 19104
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

a = 0
b = 0
import itertools
for r in list(itertools.permutations(range(1, n+1))):
  for i in range(n):
    if r[i] < p[i]:
      a += 1
      break
    elif r[i] > p[i]:
      break
    else:
      continue
  for i in range(n):
    if r[i] < q[i]:
      b += 1
      break
    elif r[i] > q[i]:
      break
    else:
      continue
      
print(abs(a-b))

Measured memory_bytes: 46704
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

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

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

struct dat{
	int d, r, c;
};

int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};

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

	int h, w;
	cin >> h >> w;

	int sr, sc;
	cin >> sr >> sc;
	sr--; sc--;

	int gr, gc;
	cin >> gr >> gc;
	gr--; gc--;

	vector<string> s(h);
	rep(i, h) cin >> s[i];

	int INF = 1e9;
	vector<vector<int>> dist(h, vector<int>(w, INF));

	auto c = [](dat a, dat b){
		return a.d > b.d;
	};

	priority_queue<dat, vector<dat>, decltype(c)> q(c);
	q.push({0, sr, sc});
	dist[sr][sc] = 0;
	
	while(!q.empty()){

		dat dt = q.top();
		q.pop();
		int r = dt.r;
		int c = dt.c;

		if(dist[r][c] < dt.d) continue;
		if(r == gr && c == gc) continue;

		rep(i, 4){
			int nr = r + dr[i];
			int nc = c + dc[i]; 
			if(0 <= nr && nr < h && 0 <= nc && nc < w && s[nr][nc] == '.'){
				if(dist[nr][nc] > dist[r][c]){
					dist[nr][nc] = dist[r][c];
					q.push({dist[nr][nc], nr, nc});
				}
			}
		}

		for(int i = -2; i <= 2; i++){
			for(int j = -2; j <= 2; j++){
				if(i == 0 && j == 0) continue;
				int nr = r + i;
				int nc = c + j;
				if(0 <= nr && nr < h && 0 <= nc && nc < w && s[nr][nc] == '.'){
					if(dist[nr][nc] > dist[r][c] + 1){
						dist[nr][nc] = dist[r][c] + 1;
						q.push({dist[nr][nc], nr, nc});
					}
				}
			}
		}
	}

	if(dist[gr][gc] == INF){
		cout << -1 << endl;
	}else{
		cout << dist[gr][gc] << endl;
	}

}


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

using namespace std;

//AOJ GRL_1_Cの問題
//こっちの方がより一般的かも

const long long inf = 1LL << 62;

int warshall_floyd(int n, vector<vector<long long>> &d, vector<vector<long long>> &GG) {
	for (int k = 0; k < n; k++) {       // 経由する頂点
		for (int i = 0; i < n; i++) {    // 始点
			if (d[i][k] == inf) { continue; }
			for (int j = 0; j < n; j++) {  // 終点
				if (d[k][j] == inf) { continue; }
				if (i == j) { continue; }
				
				if (GG[i][j] > d[i][k] + d[k][j]) {
					cout << -1 << endl;
					//cout << i << j << k << endl;
					return -1;
				}
				if (GG[i][j] == d[i][k] + d[k][j]) {
					d[i][j] = inf;
				}
				//				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

			}
		}
	}
	return 0;
}


int main() {

	int v; //頂点数
	cin >> v ;

	vector<vector<long long>> G(v, vector<long long>(v, inf));
	int in1;
	for (int i = 0; i < v; i++) {
		for (int j = 0; j < v; j++) {
			cin >> in1;
			G[i][j] = in1;
			if (i == j) { G[i][j] = inf; }
		}
	}
	vector<vector<long long>> GG(v, vector<long long>(v, inf));
	GG = G;
	if (warshall_floyd(v, G,GG) == -1) {
		return 0;
	}

	//こっからはこの問題専用。
	long long res = 0;
	for (int i = 0; i < v; i++) {
		for (int j = 0; j < v; j++) {
			if (G[i][j]!=inf) {
				res += G[i][j];
			}
		}
	}

	cout << res/2 << endl;

	return 0;

}

Measured memory_bytes: 5060
'use strict'

const main = (input) => {
    input = input.split('\n')
    const N = parseInt(input[0])
    const a = input.slice(1, N + 1).map(v => parseInt(v - 1))
    let nextIndex = 0
    for(let i = 1; i <= N; i++){
        if(a[nextIndex] === 1){
            console.log(i)
            return
        }
        nextIndex = a[nextIndex]
    }
    console.log(-1)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 18776
import math

d, g = map(int, input().split()) 
num = []
comp = []
for i in range(d):
    p, c = map(int, input().split())
    num.append(p)
    comp.append(p * (i + 1) * 100 + c)

ans = 9999999999999
for i in range(1 << d):
    pos = i
    cnt = 0
    total = 0
    last = -1
    for j in range(d):
        if pos % 2 == 1:
            total += comp[j]
            cnt += num[j]
        else:
            last = j
        pos //= 2
    if total >= g:
        ans = min(ans, cnt)
    elif last == -1:
        continue
    else:
        rem = g - total
        if rem <= num[last] * (last + 1) * 100:
            cnt += math.ceil(rem / ((last + 1) * 100))
            ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<vector<int> >in(n+1,vector<int>(n+1));
    rep(i,n)rep(j,n){
      char d;
      cin>>d;
      int a;
      if(d=='.')a=1;
      else a=0;
      in[i+1][j+1]=a;
    }
    rep(i,n)rep(j,n)in[i+1][j+1]+=in[i][j+1]+in[i+1][j]-in[i][j];
    /*rep(i,n+1){
      rep(j,n+1)cout<<" "<<in[i][j];
      cout<<endl;
   }*/
    int ma=n;
    while(ma>=0){
      bool h=false;
      loop(i,ma,n+1){
	loop(j,ma,n+1){
	  if(ma*ma==in[i][j]-in[i-ma][j]-in[i][j-ma]+
				   in[i-ma][j-ma]){
	    h=true;
	    break;
	  }
	}
	if(h)break;
      }
      if(h)break;
      ma--;
    }
    cout<<ma<<endl;
  }
}

Measured memory_bytes: 5028
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

string s;
string presub;
int k;
signed main(){
    cin >> s;
    int len = sz(s);
    int i = 0;
    while(1){
        FOR(j,1,len){
            if(i + j > len) goto FINAL;
            string q = s.substr(i,j);
            if (q != presub){
                presub = q;
                k++;
                i += j;
                cerr << q << endl;
                break;
            }
        }
    }
FINAL:
    cout << k << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
#define w(x) int x; cin>>x; while(x--)

long long int give(long long int n)
{
    long long int ans=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            ans++;
            if(n/i !=i)
                ans++;
        }

    }
    return ans;
}

int main()
{
  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output3.txt","w",stdout);
   #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n; int a[n],b[n],flag=0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        cin>>b[i];
    }
    for(int i=2;i<n;i++)
    {
        int u=a[i],v=b[i];
        int e=a[i-1],f=b[i-1];
        int c=a[i-2],d=b[i-2];
        if(u==v && e==f && c==d)
        {
            flag=1;
            break;
        }  
    }
    if(flag)
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 3696
#include <stdio.h>
#include <stdlib.h>
void Quicksort_rand(int A[], int L, int R);

int main(void)
{
	int i, j, N, T, cost[110], time[110], c;

	scanf("%d %d", &N, &T);
	j = 1;
	for (i = 1; i <= N; i++) {
		scanf("%d %d", &c, &time[i]);
		if (time[i] <= T) {
			cost[j] = c;
			j++;
		}
	}

	if (j == 1) {
		printf("TLE");
		return 0;
	}

	Quicksort_rand(cost, 1, j-1);
	printf("%d", cost[1]);


	return 0;
}

void Quicksort_rand(int A[], int L, int R)/*A[L]~A[R]までソート*/
{
	if (L < R)
	{
		int r, tmp, p = L, k = L + 1;

		srand(0);
		r = rand() % (R - L + 1) + L;//pivotを選択

		//pivotを先頭に置く
		tmp = A[L];
		A[L] = A[r];
		A[r] = tmp;

		//左の翼と右の翼に分ける
		while (k <= R) {
			if (A[k] < A[L]) {
				tmp = A[k];
				A[k] = A[p + 1];
				A[p + 1] = tmp;
				p++;
			}
			k++;
		}

		//pivotを左右の翼の境目に置く
		tmp = A[L];
		A[L] = A[p];
		A[p] = tmp;

		//左右の翼で再帰
		Quicksort_rand(A, L, p - 1);
		Quicksort_rand(A, p + 1, R);
	}
	return;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(),(v).end())
#define RSORT(v) sort((v).rbegin(),(v).rend())
const ll MOD = 1000000007;

ll gcd(ll a, ll 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;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

void solve(long long N){
    ll ans = 1;
    REP(i,N){
        ans = mulMod(ans,i+1);
    }   

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
res=n
for i in range(n+1):
    cc,t = 0,i
    while t>0:
        cc += t%6
        t //= 6
    t = n-i
    while t>0:
        cc += t%9
        t //= 9
    if res>cc:
        res=cc
print(res)


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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)5e5 + 123, mod = (int)1e9 + 7, inf = (int)1e9;
int n, k, a[N], b[N], t[4*N], cnt[N], c[N];
vector< int > up[N];

void upd(int v, int tl, int tr, int pos, int val){
	if(tl == tr){
		t[v] = val;
		return ;
	}
	int tm = (tl + tr) / 2;
	if(pos <= tm)
		upd(v + v, tl, tm, pos, val);
	else
		upd(v + v + 1, tm + 1, tr, pos, val);
	t[v] = min(t[v + v], t[v + v + 1]);
}
int get(int v, int tl, int tr, int l, int r){
	if(r < tl || tr < l)
		return inf;
	if(l <= tl && tr <= r)
		return t[v];
	int tm = (tl + tr) / 2;
	return min(get(v + v, tl, tm, l, r), get(v + v + 1, tm + 1, tr, l, r));
}

int main(){    

	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		b[a[i]] = i;
	}
	a[n + 1] = b[n + 1] = n + 1;
	for(int i = 1; i <= n; i++)
		upd(1, 1, n, i, n + 1);
	for(int i = n; i >= 1; i--){
		int x = b[i];
		int l = get(1, 1, n, x - k + 1, x);
		int r = get(1, 1, n, x, x + k - 1);
		upd(1, 1, n, x, i);
		/*
		for(int i = 1; i <= n; i++)
			cerr << get(1, 1, n, i, i) << " ";
		cerr << endl;
		*/
		cerr << b[i] << " " << l << " " << r << endl;
		
		up[b[l]].pb(i);
    	up[b[r]].pb(i);
    }
    
    priority_queue< int > q;
    vector< int > ans;
    q.push(n + 1);
    
    while(!q.empty()){
    	int v = q.top();
    	ans.pb(v);
    	q.pop();
    	for(int i = 0; i < up[v].size(); i++){
    		int x = up[v][i];
    		cnt[x]++;
    		if(cnt[x] == 2)
    			q.push(b[x]);
    	}	
    }
    
    reverse(ans.begin(),ans.end());
    
    for(int i = 0; i < n; i++)
    	c[ans[i]] = i + 1;
    for(int i = 1; i <= n; i++)
    	cout << c[i] << endl;
	return 0;
}
//sdsad

Measured memory_bytes: 48496
n = int(input())
p = input().split()

s = 0
for i in range(n-2):
  if max(int(p[i]), int(p[i+1]), int(p[i+2])) != int(p[i+1]) and min(int(p[i]), int(p[i+1]), int(p[i+2])) != int(p[i+1]):
    s += 1

print(s)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll>as(a);
    vector<ll>bs(b);
    vector<ll>cs(c);
    rep(i,a)
    {
        cin>>as[i];
    }

    rep(i,b)
    {
        cin>>bs[i];
    }

    rep(i,c)
    {
        cin>>cs[i];
    }

    sort(as.begin(),as.end());
    sort(bs.begin(),bs.end());
    vector<ll> aan(x);
    vector<ll> ban(y);
    vector<ll> eat;
    rep(i,x)
    {
        eat.push_back(as[a-x+i]);
    }
    rep(i,y)
    {
        eat.push_back(bs[b-y+i]);
    }
    rep(i,c)
    {
        eat.push_back(cs[i]);
    }
    sort(eat.begin(),eat.end(),greater<ll>());
    ll ans=0;
    rep(i,x+y)
    {
        ans+=eat[i];
    }
    cout<<ans;
    
}


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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;

int n, sum;
bitset<2000001> ok;

int main() {
	cin >> n;
	ok[0] = 1;
	F0R(i,n) {
	    int x; cin >> x;
	    sum += x;
	    ok = ok|(ok<<x);
	}
    int SUM = sum/2;
    while (!ok[SUM]) SUM --;
    cout << sum-SUM;
}

// read!read!read!read!read!read!read!read!read!read!read!read!read!read!read!read!
// ll vs. int!

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 524288;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
namespace FFT {
	const int MAXN = 524288;
	const long double pi = acosl(-1);
	struct point {long double x, y; };
	point operator + (point a, point b) {return (point) {a.x + b.x, a.y + b.y}; }
	point operator - (point a, point b) {return (point) {a.x - b.x, a.y - b.y}; }
	point operator * (point a, point b) {return (point) {a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x}; }
	point operator / (point a, long double x) {return (point) {a.x / x, a.y / x}; }
	int N, Log, home[MAXN];
	point tmp[MAXN];
	void FFTinit() {
		for (int i = 0; i < N; i++) {
			int tmp = i, ans = 0;
			for (int j = 1; j <= Log; j++) {
				ans <<= 1;
				ans += tmp & 1;
				tmp >>= 1;
			}
			home[i] = ans;
		}
	}
	void FFT(point *a, int mode) {
		for (int i = 0; i < N; i++)
			if (home[i] < i) swap(a[i], a[home[i]]);
		for (int len = 2; len <= N; len <<= 1) {
			point delta = (point) {cosl(2 * pi / len * mode), sinl(2 * pi / len * mode)};
			for (int i = 0; i < N; i += len) {
				point now = (point) {1, 0};
				for (int j = i, k = i + len / 2; k < i + len; j++, k++) {
					point tmp = a[j];
					point tnp = a[k] * now;
					a[j] = tmp + tnp;
					a[k] = tmp - tnp;
					now = now * delta;
				}
			}
		}
		if (mode == -1) {
			for (int i = 0; i < N; i++)
				a[i] = a[i] / N;
		}
	}
	void times(long long *a, long long *c, int limit) {
		N = 1, Log = 0;
		while (N < 2 * limit) {
			N <<= 1;
			Log++;
		}
		for (int i = 0; i < limit; i++)
			tmp[i] = (point) {a[i], 0};
		for (int i = limit; i < N; i++)
			tmp[i] = (point) {0, 0};
		FFTinit();
		FFT(tmp, 1);
		for (int i = 0; i < N; i++)
			tmp[i] = tmp[i] * tmp[i];
		FFT(tmp, -1);
		for (int i = 0; i < N; i++)
			c[i] = (long long) (tmp[i].x + 0.5);
	}
}
ll a[MAXN], c[MAXN];
int n, P, g, Log[MAXN], power[MAXN];
bool check(int g) {
	int cur = 1;
	for (int i = 1; i < P - 1; i++) {
		cur = 1ll * cur * g % P;
		if (cur == 1) return false;
	}
	return true;
}
void findroot() {
	g = 3, power[0] = 1, Log[1] = 0;
	while (!check(g)) g++;
	for (int i = 1; i < P - 1; i++) {
		power[i] = 1ll * power[i - 1] * g % P;
		Log[power[i]] = i;
	}
}
int main() {
	read(n), P = 2e5 + 3;
	findroot();
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		int x; read(x);
		if (x != 0) a[Log[x]]++;
		ans -= 1ll * x * x % P;
	}
	FFT :: times(a, c, P - 1);
	int cur = 1;
	for (int i = 0; i <= P * 2; i++) {
		ans += 1ll * cur * c[i];
		cur = 1ll * cur * g % P;
	}
	cout << ans / 2 << endl;
	return 0;
}


Measured memory_bytes: 29596
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq
INF = float("inf")
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###


S = input()

prev = 0
sum = 0
for c in S:
  if c == 'B':
    prev += 1
  else:
    sum += prev
    
print(sum)


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	bool M[101][101] = {};
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int u, k; cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v; cin >> v;
			M[u][v] = true;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (j != 1)cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int count = 0;
  
  for(int i=0; i<3; i++){
    if(s.at(i) == '1'){
      count++;
    }
    else{
      continue;
    }
  }
  
  cout << count <<endl;
}

Measured memory_bytes: 3600
#include<stdio.h>

int main()
{
    int n,m,K;
    scanf("%d%d",&n,&m);
    if(2<=n && n<=100 && 2<=m && m<=100)
    {
        K = (n-1)*(m-1);
        printf("%d",K);
    }
return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,open=0;
	string s;
	cin>>n>>s;
	n=0;
	for(int i=0;i<s.size();++i){
		if(s[i]=='(') ++open;
		else --open;
		n=min(n,open);
	}
	for(int i=0;i<-n;++i) cout<<'(';
	cout<<s;
	for(int i=0;i<open-n;++i) cout<<')';
}

Measured memory_bytes: 256
import math

def main():
  n,a,b = (int(x) for x in input().split())

  num_a = (math.floor(n/(a + b)))
  num_b = int(n % (a + b))

  print(int(num_a * a + min(a, num_b)))
  
if __name__ == '__main__':
  main()  


Measured memory_bytes: 3060
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#define LL long long
using namespace std;
const LL inf=1LL<<60;;
struct node{
    LL y,next,c;
}a[1000010];LL len=1,last[10010];
LL h[10010],st,ed;
queue<int> q;
void ins(LL x,LL y,LL c)
{
	//printf("%lld %lld %lld\n",x,y,c);
    a[++len].y=y;a[len].c=c;
    a[len].next=last[x];last[x]=len;
    a[++len].y=x;a[len].c=0;
    a[len].next=last[y];last[y]=len;
}
bool bt_h()
{
    memset(h,0,sizeof(h));
    h[st]=1;q.push(st);
    while(!q.empty())
    {
        LL x=q.front();q.pop();
        for(LL i=last[x];i;i=a[i].next)
        {
            LL y=a[i].y;
            if(a[i].c&&h[y]==0) h[y]=h[x]+1,q.push(y);
        }
    }
    return h[ed]!=0;
}
LL findflow(LL x,LL f)
{
    if(x==ed) return f;
    LL ans=0,t;
    for(LL i=last[x];i;i=a[i].next)
    {
        LL y=a[i].y;
        if(ans<f&&h[y]==h[x]+1&&a[i].c)
        {
            ans+=(t=findflow(y,min(f-ans,a[i].c)));
            a[i].c-=t;a[i^1].c+=t;
        }
    }
    if(ans==0) h[x]=0;
    return ans;
}
LL n,b[110];
int main()
{
    scanf("%lld",&n);
    for(LL i=1;i<=n;i++) scanf("%lld",&b[i]);
    LL tot=0;st=0;ed=n+1;
    for(LL i=1;i<=n;i++)
    {
    	if(b[i]>0) tot+=b[i],ins(i,ed,b[i]);
    	else
    	{
    		ins(st,i,-b[i]);
    		for(LL j=i;j<=n;j+=i) if(b[j]>0) ins(i,j,inf);
		}
	}
	while(bt_h()) tot-=findflow(st,inf);
	printf("%lld",tot);
}

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

int main() {
  int N, n, sum;
  cin >> N;
  n = N;
  sum = 0;
  for (int i = 0; i < 9; i++) {
    sum += n%10;
    n /= 10;
  }
  if (N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        var m = Enumerable.Repeat(int.MaxValue, 26).ToArray();
        for (int i = ReadInt(); i > 0; i--)
        {
            var a = new int[26];
            foreach (var c in Read())
            {
                a[c - 'a']++;
            }
            for (int j = 0; j < 26; j++)
            {
                m[j] = Math.Min(m[j], a[j]);
            }
        }
        var s = new StringBuilder();
        for (int i = 0; i < 26; i++)
        {
            s.Append((char)('a' + i), m[i]);
        }
        Console.WriteLine(s);
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();

    public static string Read()
    {
        if (!que.Any())
        {
            foreach (var s in Console.ReadLine().Split()) que.Enqueue(s);
        }
        return que.Dequeue();
    }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());
    public static decimal ReadDecimal() => decimal.Parse(Read());

    public static IEnumerable<string> Read(long n)
    {
        for (long i = 0; i < n; i++) yield return Read();
    }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
    public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse);
    public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}

Measured memory_bytes: 28312
def main():
    q = int(input())
    mod = 1000003
    fact = [1, 1]
    for i in range(2, mod+1):
        fact.append(fact[-1]*i % mod)

    for i in range(q):
        x, d, n = map(int, input().split())
        if d == 0:
            print(pow(x, n, mod))
            continue
        elif n >= mod:
            print(0)
            continue
        b = -x*pow(d, mod-2, mod) % mod
        if b >= n:
            print(pow(fact[b-n], mod-2, mod)*fact[b]*pow(-d, n, mod) % mod)
        else:
            print(0)


main()


Measured memory_bytes: 118128
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

vector<int> enum_div(int n) {
   vector<int> ret;
      for (int i=1 ; i*i<=n ; ++i) {
         if (n%i == 0) {
            ret.push_back(i);
            if (i!=1 && i*i!=n) {
               ret.push_back(n/i);
            }
         }
      }
   return ret;
}

int main() {
   int N, M;
   cin >> N >> M;
   
   int tmp;
   vector<int> res = enum_div(M);
   res.push_back(M);
   sort(res.begin(), res.end());
   for (int i = 0; i < (int)res.size(); i++) {
      if (res[i] >= N) {
         tmp = res[i];
         break;
      }
   }
   cout << M / tmp << endl;
   return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;

namespace AGC023A
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var A = ss.Next(long.Parse, N);

            var dic = new Dictionary<long, long>{[0] = 0};
            var sum = 0L;
            for (var i = 0; i < N; i++)
            {
                sum += A[i];
                if (dic.ContainsKey(sum)) dic[sum]++;
                else dic.Add(sum, 0);
            }

            var ans = 0L;
            foreach (var x in dic.Values) ans += x * (x + 1) / 2;
            sw.WriteLine(ans);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 42552
import math
from statistics import mean

n = int(input())
a = list(map(int, input().split()))

m = mean(a)
if m - math.floor(m) < 0.5:
    m = math.floor(m)
else:
    m = math.floor(m) + 1

diff = 0
for v in a:
    diff += (m - v) ** 2

print(diff)


Measured memory_bytes: 10740
import math

A, B, H, M = map(int, input().split())

th_h = 360 // 12 * H + 360 / 12 / 60 * M
th_m = 360 // 60 * M

ans = A ** 2 + B ** 2 - 2*A*B*math.cos(math.radians(abs(th_h - th_m)))
print(math.sqrt(ans))

Measured memory_bytes: 9372
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	int x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //setprecision()
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
using ll = long long;
using namespace std;

int monmo(char ms){
    if(ms=='R')return 3;
    else if(ms=='G')return 2;
    else if(ms=='B')return 1;
    else cout<<ms;
    return 0;
}

int main() {
    int n;
    map<string,int> m,m2;
    string s,s2,s3,s4,s5;
    string rgb="BGR";
    ll count=0;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        s2=s[i];
        m[s2]++;
    }
    for(int i=0;i<n-2;i++){
        s3=s[i];
        m[s3]--;
        m2=m;
        for(int j=i+1;j<n-1;j++){
            int a=5;
            s4=s[j];
            m2[s4]--;
            if(s[i]==s[j]){continue;}
            a-=monmo(s[i]);
            a-=monmo(s[j]);
            s5=rgb[a];
            count+=m2[s5];
            if(j*2-i<=n)if(s[j*2-i]==rgb[a])count--;
        }
    }
    cout<<count;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define in(a) cin>>a
#define out(a) cout<<a<<endl

int main()
{
	string str;
	cin >> str;
	int ans = 0;
	bool ok = false;
	loop(bit, (1 << 3))
	{
		if (ok)break;
		int ans_tmp = str[0] - '0';
		vector<string> ops;
		loop(j, 3)
		{
			if (bit&(1 << j))
			{
				ans_tmp += (str[j + 1] - '0');
				ops.push_back("+");
			}
			else
			{
				ans_tmp -= (str[j + 1] - '0');
				ops.push_back("-");
			}
		}
		if (ans_tmp == 7)
		{
			string answer = "";
			answer += (char)str[0] + ops[0] + char(str[1]) + ops[1] + char(str[2]) + ops[2] + char(str[3]) + "=7";
			cout << answer << endl;
			ok = true;
		}
	}
}

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

int main(){
  long N, D, X, Y, DA, DB, count = 0;
  cin >> N >> D;
  DB = D * D;
  for(int i = 0; i < N; i++){
    X = 0; Y = 0, DA = 0;
    cin >> X >> Y;
    DA = X * X + Y * Y;
    if(DA <= DB) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 3604
N, K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())

RSP = [[] for _ in range(K)]

for i,t in enumerate(T):
    RSP[i%K].append(t)

ans = 0
road = []
for row in RSP:
    memo = 'baka'
    for a in row:
        if memo != a:
            if a == 'r':
                ans += P
                road.append('p')
            elif a == 's':
                ans+= R
                road.append('r')
            else:
                ans+= S
                road.append('s')
            memo = a
        else:
            memo = 'baka'

print(ans)

Measured memory_bytes: 15056
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define Ans(s) cout << s << endl

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

typedef long long ll;
typedef vector<int> inv;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main()
{
	string s;
	int k;

	cin >> s >> k;

	vector<string> hoge;

	rep(i, s.size())
	{
		Rep(j, 6)
		{
			hoge.push_back(s.substr(i, j));
		}
	}

	sort(ASC(hoge));
	hoge.erase(std::unique(hoge.begin(), hoge.end()), hoge.end());

	cout << hoge[k - 1] << endl;
}

Measured memory_bytes: 1660
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
#include<cctype>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}
//UnionFind木のテンプレ.parentには根のindexが入っている.
//根には連結成分のサイズが入っている.nはノード数.
class UnionFind{
public:
	vector<int> parent;
	UnionFind(){}
	UnionFind(int n){
		this->parent = vector<int>(n,-1);
	}
	int root(int x){
		if (this->parent[x] < 0) return x;
		this->parent[x] = root(this->parent[x]);
		return this->parent[x];
	}
	int unite(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		if (rx == ry) return false;
		if (this->parent[rx] > this->parent[ry]) swap(rx, ry);
		this->parent[rx] += this->parent[ry];
		this->parent[ry] = rx;
		return true;
	}
	int same(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		return rx == ry;
	}
	int size(int x){
		return -this->parent[this->root(x)];
	}
};


//クラスカル法.UnionFindが必要.最小全域木の重みの総和を返す.
//nはノード数.queは(weight,from,to)の順に格納された順序付き待ち行列.
// int v, e; cin >> v >> e;
// 	priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> que;
// 	for (int i = 0; i < e; i++){
// 		int s, t, w; cin >> s >> t >> w;
// 		que.push({w,s,t});
// 	}
int kruskal(int n, priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> que){
	UnionFind uf(n);
	int weight = 0;
	while(!que.empty()){
		vector<int> now = que.top();
		que.pop();
		if (!uf.same(now[1],now[2])){
			uf.unite(now[1],now[2]);
			weight += now[0];
		}
	}
	return weight;
}
//重みがdoubleバーション
double kruskal(int n, priority_queue<tuple<double,int,int>,vector<tuple<double,int,int>>,greater<tuple<double,int,int>>> que){
	UnionFind uf(n);
	double weight = 0;
	while(!que.empty()){
		tuple<double, int, int> now = que.top();
		que.pop();
		if (!uf.same(get<1>(now),get<2>(now))){
			uf.unite(get<1>(now), get<2>(now));
			weight += get<0>(now);
		}
	}
	return weight;
}
double dist(vector<double> a,vector<double> b){
	return sqrt(pow((a[0] - b[0]), 2) + pow((a[1] - b[1]), 2) + pow((a[2] - b[2]), 2));
}

int main(){
	int n;
	cin >> n;
	vector<pair<int, int>> x, y;
	rep(i,n){
		int a, b;
		cin >> a >> b;
		x.push_back(pair<int, int>(a, i));
		y.push_back(pair<int, int>(b, i));
	}
	sort(all(x));
	sort(all(y));
	priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> que;
	rep(i,n-1){
		que.push({x[i+1].first - x[i].first, x[i].second, x[i + 1].second});
		que.push({y[i+1].first - y[i].first, y[i].second, y[i + 1].second});
	}
	cout << kruskal(n, que) << endl;


	return 0;
}

Measured memory_bytes: 25440
import sys

s = list(input())
cm = []
fM = []
for i, j in enumerate(s):
    if j == "C":
        cm.append(i)
    if j == "F":
        fM.append(i)
if "C" not in s or "F" not in s:
    print("No")
    sys.exit()
if max(fM) - min(cm) > 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

string tmp[2] = {"##..", "#.#."};
string rets, rett;
bool r, l;

bool query(string s, string t) {
  cout << s << endl << t << endl;
  string ans;
  cin >> ans;
  if(ans == "end") return true;
  if(ans == "T") return true;
  return false;
}

void rdfs(string s, string t) {
  if(r) return;
  REP(i, 4) {
    if(query(s+tmp[0][i], t+tmp[1][i])) {
      rdfs(s+tmp[0][i], t+tmp[1][i]);
    }
    if(r) return;
  }
  rets = s, rett = t;
  r = true;
}

void ldfs(string s, string t) {
  if(l) return;
  REP(i, 4) {
    if(query(tmp[0][i]+s, tmp[1][i]+t)) {
      ldfs(tmp[0][i]+s, tmp[1][i]+t);
    }
    if(l) return;
  }
  rets = s, rett = t;
  l = true;
}

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

  rdfs("","");
  ldfs(rets, rett);

  query(rets, rett);

  return 0;
}


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

int main(void){
    int n; ll ans = 0;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int t = n-1;
    for(int i = 0; i < n; i++){
        int lim = 2;
        if(i == 0) lim = 1;
        for(int j = 0; j < lim; j++){
            if(t > 0){
                ans += a[i];
                t--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4800
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
double x;
vector<double> v;
while(cin>>x){
v.push_back(x);
}
sort(v.begin(),v.end());
printf("%.5f\n",v[v.size()-1]-v[0]);
return 0;
}

Measured memory_bytes: 1260
#include<stdio.h>
int main(){
	char a[100][100];
	int X,Y,i,i2;
	scanf("%d%d",&Y,&X);
	for(i=0;i<Y;i++){
			scanf("%s",&a[i]);
	}
	for(i=0;i<X+2;i++)printf("#");
	printf("\n");
	for(i=0;i<Y;i++){
		printf("#");
		for(i2=0;i2<X;i2++){
			printf("%c",a[i][i2]);
		}
		printf("#\n");
	}
	for(i=0;i<X+2;i++)printf("#");
	printf("\n");
}

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




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

	ll H,W;
	cin>>H>>W;
    vector<vector<int>> map(H, vector<int>(W));
    string s;
    for(int i=0;i<H;i++){
        cin>>s;
        for(int j=0;j<W;j++){
            if(s[j]=='#'){
                map[i][j] =1;
            }
        }
    }
    typedef pair<ll,ll> pair;
    deque<pair> q;
    deque<ll> move_num;
    ll tmp_l=0;
    vector<vector<int>> map_flag(H, vector<int>(W)); 
    ll ans = 1;
    ll h,w;
    pair tmp_q;
    ll max_l=0;
    ll move[2] = {-1,1};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(map[i][j]==1){
                continue;
            }
            map_flag = map;
            tmp_l=0;
            // スタート地点
            q.push_back(pair(i,j));
            move_num.push_back(tmp_l);
            map_flag[i][j]=1;
            while(!q.empty()){
                tmp_q = q.front();
                h = tmp_q.first;
                w = tmp_q.second;
                tmp_l = move_num.front();
                q.pop_front();
                move_num.pop_front();
                ++tmp_l;
                for(ll k:move){
                    if(0<=h+k&&h+k<H){
                        // 移動出来る時
                        if(map_flag[h+k][w]==0){
                            map_flag[h+k][w]=1;
                            q.push_back(pair(h+k,w));
                            move_num.push_back(tmp_l);
                            max_l = max(max_l,tmp_l);
                        }
                    }
                }
                for(ll k:move){
                    if(0<=w+k&&w+k<W){
                        if(map_flag[h][w+k]==0){
                            map_flag[h][w+k]=1;
                            q.push_back(pair(h,w+k));
                            move_num.push_back(tmp_l);
                            max_l = max(max_l,tmp_l);
                        }
                    }
                }
            }
            // cout<<max_l<<"\n";
        }
    }
    cout<<max_l<<"\n";
	return 0;
}

Measured memory_bytes: 256