akhauriyash/Code-Regression huggingface dataset:
n, k, c = map(int, input().split())
s = list(input())
# cnt = s.count('o')
os = [i for i,x in enumerate(s) if x=='o']

from collections import deque

q = deque(os.copy())
_q1 = q.popleft()
m = k-1
l = [_q1]
if m > 0:
    while q:
        _q2 = q.popleft()
        if _q2 - _q1 > c:
            l.append(_q2)
            _q1 = _q2
            m -= 1
            if m == 0:
                q = deque([])
        else:
            pass

q = deque(os.copy())
_q2 = q.pop()
m = k-1
r = [_q2]
if m > 0:
    while q:
        _q1 = q.pop()
        if _q2 - _q1 > c:
            r.append(_q1)
            _q2 = _q1
            m -= 1
            if m == 0:
                q = deque([])
        else:
            pass

r = list(reversed(r))

ans = 0
for _l, _r in zip(l, r):
    if _l == _r:
        print(str(_l+1))
        ans = 1

if ans == 0:
    print()


Measured memory_bytes: 20724
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, N) cin >> p.at(i);

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

    int sum = 0;
    rep(i, N - 1) {
        sum += p.at(i);
    }
    sum += p.at(N - 1) / 2;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3624
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function lineIn(){
		$buf = fgets(STDIN);
		return $this->killNewLine($buf);
	}
	private function arrayIn(){
		$buf = explode(" ", fgets(STDIN));
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->arrayIn();
		
		$type = $s[0];
		$material = $s[1];

		$sizeOf = array();

		for($i = 0; $i < $type; $i++){
			$sizeOf[] = $this->lineIn();
		}

		sort($sizeOf);

		$ans = 0;

		$buf = $material;
		foreach($sizeOf as $value){
			$buf -= $value;
			$ans++;
		}
		unset($value);

		while($sizeOf[0] <= $buf){
			$buf -= $sizeOf[0];
			$ans++;
		}
		echo $ans . "\n";
	}
}
?>


Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N,M;
string str;
int as[1000001];
int cnt1,cnt2;
int res;

void dfs(int depth,int lim,int sum){
  if(depth==lim)res+=(sum%10==0);
  else{
    if(depth<cnt1){
      for(int i=0;i<M;i++)
        dfs(depth+1,lim,sum+as[i]);
    }
    else{
      for(int i=0;i<M;i++){
        int dig=2*as[i];
        if(dig>=10)dig=dig/10+dig%10;
        dfs(depth+1,lim,sum+dig);
      }
    }
  }
}

int main(){
  cin>>N;
  cin>>str;
  cin>>M;
  for(int i=0;i<M;i++)cin>>as[i];
  int sum=0;
  cnt1=cnt2=0;
  reverse(str.begin(),str.end());
  for(int i=0;i<N;i++){
    if(str[i]=='*'){
      if(i%2==0)cnt1++;
      else cnt2++;
    }
    else{
      if(i%2==0)sum+=str[i]-'0';
      else{
        int dig=2*(str[i]-'0');
        if(dig>=10)dig=dig/10+dig%10;
        sum+=dig;
      }
    }
  }
  int cnt=cnt1+cnt2;
  dfs(0,cnt,sum);
  cout<<res<<endl;
  
  return 0;
}

Measured memory_bytes: 1340
#include<stdio.h>

void sort (int n,int array[],int left,int right) {
  int i, j, k, mid;
  int work[n];
  if (left < right) {
    mid = (left + right)/2;
    sort(n,array, left, mid);
    sort(n,array, mid+1, right);
    for (i = mid; i >= left; i--) { work[i] = array[i]; }
    for (j = mid+1; j <= right; j++) {
      work[right-(j-(mid+1))] = array[j];
    }
    i = left; j = right;
    for (k = left; k <= right; k++) {
      if (work[i] < work[j]) { array[k] = work[i++]; }
      else                   { array[k] = work[j--]; }
    }
  }
}

int main(void){
	unsigned int n,b;
	b=0;
	scanf("%u",&n);
	unsigned int a[n];
	for(int i=0;i<n;i++){
		scanf("%u",&b);
		a[i]=b;
	}
	b=0;

	sort(n,a,0,n-1);

	for(int i=1;i<n;i++){
		if(a[i-1]==a[i]){
			printf("NO");
			b=1;
			break;
		}
	}
	if(b==0){
		printf("YES");
	}
	
	return 0;
}

Measured memory_bytes: 14976
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,now=1;
    cin >>x>>y;
    for (int i=x;i<=y;i++)
    {
    	if (i<0)
    		now*=-1;
    	if (i==0)
		{
			cout <<"Zero"<<endl;
			return 0;
		}
	}
	if (now>0)
		cout <<"Positive"<<endl;
	else
		cout <<"Negative"<<endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

//https://qiita.com/keymoon/items/11fac5627672a6d6a9f6から

class Rollinghash{
    ll MASK30 = (1UL << 30) - 1;
    ll MASK31 = (1UL << 31) - 1;
    ll MD = (1UL << 61) - 1;
    ll MASK61 = MD;

    //a*b mod 2^61-1を返す関数(最後にModを取る)
    ll Mul(ll a, ll b){
        ll au = a >> 31;
        ll ad = a & MASK31;
        ll bu = b >> 31;
        ll bd = b & MASK31;
        ll mid = ad * bu + au * bd;
        ll midu = mid >> 30;
        ll midd = mid & MASK30;
        return CalcMod(au * bu * 2 + midu + (midd << 31) + ad * bd);
    }

    //mod 2^61-1を計算する関数
    ll CalcMod(ll x)
    {
        ll xu = x >> 61;
        ll xd = x & MASK61;
        ll res = xu + xd;
        if (res >= MD) res -= MD;
        return res;
    }
    ll base_(){
        mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
        uniform_int_distribution<ll> rand(2,MD-2);
        return rand(mt);
    }

    ll base/*=base_()*/=MOD;

    vl hash,power;

public:
    Rollinghash(vl &s){
        ll n=s.size();
        hash.assign(n+1,0);
        power.assign(n+1,1);
        rep(i,n){
            power[i+1]=Mul(power[i],base);
            hash[i+1]=(Mul(hash[i],base)+s[i])%MD;
        }
    }
    ll get(int l,int r){
        return (hash[r]+MD-Mul(hash[l],power[r-l]))%MD;
    }
    int LCP(int l0,int r0,int l1,int r1){
        int ok=0,ng=min(r0-l0,r1-l1);
        while(abs(ok-ng)>1){
            int rh_mid=(ok+ng)/2;
            if(get(l0,l0+rh_mid)==get(l1,l1+rh_mid)) ok=rh_mid;
            else ng=rh_mid;
        }
        return ok;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;
    vl A(N),B(N);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        cin >> B[i];
    }
    vl C(2*N),D(N);
    rep(i,N){
        C[i]=C[N+i]=A[i]^A[(i+1)%N];
        D[i]=B[i]^B[(i+1)%N];
    }
    Rollinghash rh0(C);
    Rollinghash rh1(D);
    rep(K,N){
        if(rh0.get(K,K+N)==rh1.get(0,N)){
            cout << K << ' ' << (A[K]^B[0]) << endl;
        }
    }
}


Measured memory_bytes: 20884
A = int(input())
B = int(input())
C = int(input())
X = int(input())
counter = 0

list_500 = list(range(A+1))
list_100 = list(range(B+1))
list_50 = list(range(C+1))

for fh in range(len(list_500)):
    for oh in range(len(list_100)):
      for f in range(len(list_50)):
        if list_500[fh] * 500 + list_100[oh] * 100 + list_50[f] * 50 == X:
          counter += 1

print(counter)


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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n - 2) {
        vector<int> a = {p[i], p[i + 1], p[i + 2]};
        sort(a.begin(), a.end());
        if (a[1] == p[i + 1]) ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
while 1:
    h = input()
    if h == 0:
        break
    M = [map(int, raw_input().split()) for i in xrange(h)]
    ans = 0
    update = 1
    while update:
        update = 0
        for i in xrange(h):
            cnt = 0; prev = None
            for j in xrange(5):
                if prev != M[i][j]:
                    if cnt >= 3:
                        if prev is not None:
                            for k in xrange(cnt):
                                M[i][j - k - 1] = None
                            ans += cnt * prev
                            update = 1
                    cnt = 1
                else:
                    cnt += 1
                prev = M[i][j]
            if cnt >= 3:
                if prev is not None:
                    for k in xrange(cnt):
                        M[i][5 - k - 1] = None
                    ans += cnt * prev
                    update = 1
        for j in xrange(5):
            cur = h-1
            for i in xrange(h-1, -1, -1):
                if M[i][j] is not None:
                    if i < cur:
                        M[cur][j] = M[i][j]
                        M[i][j] = None
                    cur -= 1
    print ans

Measured memory_bytes: 6312
import collections
import numpy as np

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
N = int(input())
#print(N)
A = prime_factorize(N)
c = collections.Counter(A)

#print(A)

d = np.floor((-1. + np.sqrt(1 + 8 * np.array(list(c.values()))))/2)
#print(d)
print(int(np.sum(d)))

Measured memory_bytes: 27240
mod = 10 ** 9 + 7
n = int(input())

# 0がない　または　9がない
one = 1
two = 1
al = 1

for i in range(n):
    one *= 9
    one %= mod
    two *= 8
    two %= mod
    al *= 10
    al %= mod

print((al - (2 * one - two))%mod)


Measured memory_bytes: 9104
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a == 1 {
		a += 13
	}
	if b == 1 {
		b += 13
	}
	if a > b {
		fmt.Println("Alice")
		return
	}
	if a < b {
		fmt.Println("Bob")
		return
	}
	fmt.Println("Draw")
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int s[100000];
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    int q;
    cin >> q;
    int count=0;
    for(int i=0;i<q;i++){
        int x;
        cin >> x;
//        cout <<x <<endl;
        int pmin=0;
        int pmax=n-1;
        int pos=pmin+(pmin+pmax)/2;
        while(true){
            pos=(pmin+pmax)/2;
            if (pmin>pmax)break;
            if (s[pos]<x){
//                cout <<"bb" <<s[pos] <<endl;
                pmin=pos+1;
            }else if (s[pos]>x){
                pmax=pos-1;
            }else{
//                cout << "aa"<<x <<endl;
                count++;
                break;
            }
//            cout << pos <<endl;
        }

    }
    cout << count << endl;
    return 0;
}


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

int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <algorithm> 
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
int vis[105];
int a[105][105];
int main(int argc, char** argv) {
	

	rep(i,1,3)
	{
		rep(j,1,3)
		{
			scanf("%d",&a[i][j]); 
		}
	}
		int n;
	cin>>n;		int x;
	rep(i,1,n)
	{scanf("%d",&x);vis[x]=1;}

	int fg=1;
	rep(i,1,3)
	{
		if(!vis[a[i][i]])
		{
			fg=0;
		}
	}
	if(fg)
	{
		cout<<"Yes";
		return 0;
	}
	fg=1;
	rep(i,1,3)
	{
		if(!vis[a[i][4-i]])
		{
			fg=0;
		}
	}
	if(fg)
	{
		cout<<"Yes";
		return 0;
	}
	rep(j,1,3){
	fg=1;
	rep(i,1,3)
	{
		if(!vis[a[i][j]])
		{
			fg=0;
		}
	}
	if(fg)
	{
		cout<<"Yes";
		return 0;
	}
}
	rep(i,1,3)
	{
		fg=1;
		rep(j,1,3)
		{
		if(!vis[a[i][j]])	
		{
			fg=0;
		}
		}
		if(fg)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
//TO CHANGE THE WORLD
#include <bits/stdc++.h>

using namespace std;

#define L first
#define R seoncd
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn=1e5+10;
int a[maxn], n, l, ind=-1;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>n>>l;
    for(int i=0; i<n; i++) cin>>a[i];
    for(int i=0; i<n-1; i++) if(a[i]+a[i+1]>=l) ind=i;
    if(ind==-1) return cout<<"Impossible"<<endl, 0;
    cout<<"Possible"<<endl;
    for(int i=0; i<ind; i++) cout<<i+1<<"\n";
    for(int i=n-2; i>ind; i--) cout<<i+1<<"\n";
    cout<<ind+1<<endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  VI ans;
  rep(i,6000){
    int X=(i+1)*10+1;
    int F=1;
    rep(j,sqrt(X)){
      if(X%(j+2)==0){
        F=0;
        break;
      }
    }
    if(F) ans.push_back(X);
  }
  rep(i,N){
    if(i) cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
}

Measured memory_bytes: 256
n = int(input())
B = list(map(int,(input().split())))

list_A = [0]*n

list_A[0] = B[0]
list_A[n-1] = B[n-2]
for i in range(1,n-1):
    list_A[i] = min(B[i-1],B[i])

print(sum(list_A))




Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int N,A, B, i, x, y;
	
	scanf("%d", &N);
	scanf("%d", &A);
	scanf("%d", &B);
	
	char s[N];
	
	scanf("%s", s);
	
	x = 0;
	y = 0;
	
	
	for (i = 0; i < N; i++)
	{
		switch (s[i]) 
		{
			case 'a':
                if(x < A + B)
				{
                    printf("Yes\n");
                    x++;
                }
				else
				{
                    printf("No\n");
                }
                break;
            case 'b':
                if(x < A + B && y < B)
				{
                    printf("Yes\n");
                    x++;
                    y++;
                }
				else
				{
                    printf("No\n");
                }
                break;
            case 'c':
                printf("No\n");
                break;
		}
	
	}
	return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
a = str(input())

b = ["A","C","G","T"]
count = 0
max = 0
for i in range(0,len(a)):
    if a[i] in b:
        count = count + 1
        if max < count:
            max = count
    else:
        count = 0

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

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int N,H,W;
	int A;
	int B;
	int i;
	int count = 0;
	scanf("%d %d %d",&N,&H,&W);
	
	for(i=0;i<N;i++){
	scanf("%d %d",&A,&B);
	if(A>=H&&B>=W){count+=1;}

	}
	printf("%d\n",count);
	return 0;
	
}
	

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  if (N >= M)
    return puts("0"), 0;

  std::vector<int> X(M);
  for (auto& xi: X) scanf("%d", &xi);
  std::sort(X.begin(), X.end());

  std::vector<int> Y(M-1);
  for (size_t i = 1; i < M; ++i)
    Y[i-1] = X[i] - X[i-1];

  std::sort(Y.begin(), Y.end());
  for (size_t i = 0; i+1 < M; ++i)
    fprintf(stderr, "%d%c", Y[i], i+2<M? ' ':'\n');
  printf("%d\n", std::accumulate(Y.begin(), Y.begin()+(M-N), 0));
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int dp[8010][16010];
int a[8010];
int main()
{
	string s;
	int x,y;
	cin>>s>>x>>y;
	int k=0;
	int w=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='T')
		{
			k++;
			a[k]=w;
			w=0;
		}
		else
		{
			w++;
		}
	}
	k++;
	a[k]=w;
	dp[1][a[1]+8000]=1;
	for(int i=3;i<=k;i+=2)
	{
		for(int j=0;j<=16000;j++)
		{
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	dp[0][8000]=1;
	for(int i=2;i<=k;i+=2)
	{
		for(int j=0;j<=16000;j++)
		{
			if(j+a[i]<=16000)
			dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
			dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	int ans;
	if(k%2==0)
	{ 
		ans=dp[k][y+8000]&&dp[k-1][x+8000];
	}
	else{
		ans=dp[k][x+8000]&&dp[k-1][y+8000];
	}
	
	cout<<(ans==0?"No":"Yes");
	return 0;
}

Measured memory_bytes: 497792
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def ref(N, M, XY):
    ans = INF
    for i in combinations(range(N), r=M):
        minx = INF
        miny = INF
        maxx = -INF
        maxy = -INF
        for j in i:
            x, y = XY[j]
            minx = min(minx, x)
            maxx = max(maxx, x)
            miny = min(miny, y)
            maxy = max(maxy, y)
        ans = min(ans, (maxx-minx)*(maxy-miny))
    return ans

@mt
def slv(N, M, XY):
    XY.sort(key=itemgetter(1))
    XY.sort()
    # print(XY)

    ans = INF
    for i, (x, y) in enumerate(XY):
        yl = [y]
        for j in range(i+1, N):
            x2, y2 = XY[j]
            lx = x2-x
            yl.append(y2)

            if len(yl) >= M:
                yl.sort()
                for k in range(len(yl)-M+1):
                    ly = yl[k+M-1] -  yl[k]
                    ans = min(ans, lx*ly)
    return ans

def main():
    N, M = read_int_n()
    XY = [read_int_n() for _ in range(N)]
    print(slv(N, M, XY))



if __name__ == '__main__':
    main()


Measured memory_bytes: 78608
#include<iostream>
using namespace std;
int main(void){
    int a,b;
    string s;
    cin >> a >> b >> s;
  b--;
  if(s.at(b) < 68){
    s.at(b) = (char)(s.at(b) + 32);
    cout << s;
  }else{
    s.at(b) = (char)(s.at(b) - 32);
    cout << s;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
#define MAX 100000

static const int N =100;
static const int INFTY =(1<<21);
int n,M[N][N];
int d[N];

void bfs(int s){
  queue<int> q;
  q.push(s);
  for(int i=0;i<n;i++) d[i]=INFTY;
  d[s]=0;
  int u;
  while(!q.empty()){
    u=q.front();
    q.pop();
    for(int v=0;v<n;v++){
      if(M[u][v]==0)continue;
      if(d[v]!=INFTY)continue;
        d[v]=d[u]+1;
        q.push(v);
    }
  }
  for(int i=0;i<n;i++){
    cout << i+1 << " " << ((d[i]==INFTY)? (-1):d[i])<< endl;
  }
}

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

  for(int i=0;i<n;i++){
    cin >>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin >> v;
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);
  return 0;
}


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

# nを割れる整数を1からルートnまで列挙
def divisors(num):
   arr = []
   for i in range(1, int(num**0.5) + 1):
       if num % i == 0:
           arr.append(i)
           if i != num // i:
               arr.append(num//i)
   return arr

n_div = divisors(n)
arr_ = [int(i + n / i) for i in n_div]
print(min(arr_) - 2)

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

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

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

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

    int n;
    cin >> n;
    int p[n];
    int q[n];
    rep(i, n) {
        cin >> p[i];
        q[i] = p[i];
    }

    sort(p, p + n);
    int cnt = 0;
    rep(i, n) {
        if (p[i] != q[i]) {
            cnt++;
        }
    }
    cout << (cnt <= 2 ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, mxw;
	cin >> n >> mxw;
	vector<long long> dp(1e5 + 1, 1e17);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		int w, v;
		cin >> w >> v;
		
		for (int j = 1e5 - v; j >= 0; j--) {
			dp[j + v] = min(dp[j + v], dp[j] + w);
		}
	}
	int ans;
	for (int i = 0; i <= 1e5; i++) {
		if (dp[i] <= mxw) ans = i;
	}
	cout << ans;
}

Measured memory_bytes: 3976
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,s=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){scanf("%d",&a);if(a==s) s++; }
    s--;
    if(s) printf("%d",n-s);
    else printf("%d",-1);
    return 0;
}


Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.readline().strip()

H, W, K = list(map(int, input().split()))
S = []
for i in range(H):
	S.append(input())

ans_matrix = [[0]*W for _ in range(H)]

for i in range(H):
	num_i = 0
	for j in range(W):
		if S[i][j] == "#":
			num_i += 1
	if num_i > 0:
		start = i
		break

num = 0
for i in range(start, H):
	num_i = []
	for j in range(W):
		if S[i][j] == "#":
			num_i.append(j)
	if len(num_i) == 0:
		for j in range(W):
			ans_matrix[i][j] = ans_matrix[i - 1][j]
	else:
		num_i.append(W)
		num_i.sort(reverse=True)
		j_next = num_i.pop()
		j_next = num_i.pop()
		for j in range(W):
			if j == 0:
				num += 1
			if j == j_next:
				num += 1
				j_next = num_i.pop()
			ans_matrix[i][j] = num

for i in range(start):
	for j in range(W):
		ans_matrix[i][j] = ans_matrix[start][j]

def list_print(A):
	length = len(A)
	for i in range(length - 1):
		print(A[i], end="")
		print(" ", end="")
	print(A[- 1])

for i in range(H):
	list_print(ans_matrix[i])

Measured memory_bytes: 62680
//2019.12.29
//Refering to exp.
#include<iostream>
#include<string>
#include<map>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
	int n,k;
	int r,s,p;
	string t;
	cin>>n>>k>>r>>s>>p>>t;
	
	map<char,int> mp;
	mp['r']=p;
	mp['s']=r;
	mp['p']=s;
	
	int ans=0;
	REP(i,k){
		char pre='a';
		for(int j=i;j<n;j+=k){
			if(t[j]==pre){
				pre='a';
			}else{
				ans+=mp[t[j]];
				pre=t[j];
			}
		}
	}
	
	cout<<ans<<endl;
}


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

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
using llint = long long int ;
using namespace std;


int main(){
    int A,B;
    bool check=false;
    cin>>A>>B;
    for(int i=0; i<10000;++i){
        int Ac=i*0.08;
        int Bc=i*0.10;
        if(Ac==A&&Bc==B){
            cout<<i<<endl;
            check=true;
            break;
        }
    }
    if(!check) cout<<-1<<endl;
    
    return 0;
}

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

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

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

    int d[n+1];
    d[0] = 0;
    for(int i = 0; i < n; i++){
        d[i+1] = d[i] + l[i];
    }

    int ans = 0;
    for(int i = 0; i < n+1; i++){
        if(d[i] <= x) ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <set>
#include <vector>

using namespace std;

int check(char c)
{
    if (c == 'o') return 100;
    else return 0;
}

int main(){
    string s;
    cin >> s;
    int ans = 700;
    ans += check(s[0]);
    ans += check(s[1]);
    ans += check(s[2]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, a[maxn], ind;
double mn = 1000000007.0;
int main() {
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int x = a[n - 1];
	double d = x / 2.0;
//	cout << d << endl;
	for(int i = 0; i < n - 1; i++) {
		if(abs(a[i] - d) < mn) {
			mn = abs(a[i] - d);
			ind = i;
		}
	}
	cout << x << " " << a[ind];
	return 0;
}

Measured memory_bytes: 640
s = input()
sr = s[::-1]
n = len(s)
s1 = s[:((n-1)//2)]
s1r = s1[::-1]
s2 = s[((n+3)//2-1):]
s2r = s2[::-1]
if s == sr and s1 == s1r and s2 == s2r:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
int n;
cin >> n;
if(n%2==0){
    cout << n/2-1<<endl;
}
else{
    cout << n/2<<endl;
}
}


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

int main() {
  int n, m, x;
  cin >> n >> m >> x;

  vector<int> a(m);
  set<int> s;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    s.insert(a[i]);
  }

  int tmp = 0;
  for (int i = 0; i < x; i++) {
    if (s.count(i)) {
      tmp++;
    }
  }

  int ans;
  if (tmp <= m / 2) {
    ans = tmp;
  }
  else {
    ans = m - tmp;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>

const int N=100010;

int n,fa[N],dep[N],sz[N],a[N],sa,b[N],sb;
std::vector<int> G[N];

void dfs(int u)
{
	sz[u]=1;
	for(auto v:G[u])if(v^fa[u])
		fa[v]=u,dep[v]=dep[u]+1,dfs(v),sz[u]+=sz[v];
}

int main()
{
	scanf("%d",&n);
	if(n==1)
		return puts("Fennec"),0;
	for(int i=1,x,y; i<n; i++)
	{
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(1);
	int lca=0;
	for(int u=1,v=n;;){
		if(dep[u]>dep[v])u=fa[u];
		else v=fa[v];
		if(u==v){
			lca=u;
			break;
		}
	}
	for(int x=1; x!=fa[lca]; x=fa[x])
		a[++sa]=x;
	for(int y=n; y!=lca; y=fa[y])
		b[++sb]=y;
	for(;sb;--sb)a[++sa]=b[sb];
	int p=a[(sa+1)/2];
	int q=a[(sa+1)/2+1];
	int s1=1,s2=0;
	if(p==fa[q])
	{
		s2=sz[q];
		s1=n-s2;
	}
	if(q==fa[p])
	{
		s1=sz[p];
		s2=n-s1;
	}
	if(s1>s2)
		puts("Fennec");
	else
		puts("Snuke");
	return 0;
}


Measured memory_bytes: 12288
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        c: [Usize1;n],
        ab:[(Usize1,Usize1);n-1],
    }

    let mut v = vec![Vec::new(); n];
    for &p in &ab {
        v[p.0].push(p.1);
        v[p.1].push(p.0);
    }

    struct Ctx {
        c: Vec<usize>,
        color_ct: Vec<Vec<i64>>,
        color_sizes: Vec<Vec<i64>>,
        clock: i64,
    }
    let mut ctx = Ctx {
        c,
        color_ct: vec![vec![0; 1]; n], // 他の部分木内で過ごした時間
        color_sizes: vec![Vec::new(); n],
        clock: 0,
    };

    /*
       ノード数Nの木の、全てのパスの数 = N*(N+1)/2
       色kを通るパスの数 = 全てのパスの数 - 色kを通らないパスの数

       木を、色kを含まない複数の部分木(ノード数 s1, s2, ... sm)に分ける。
       色kを通らないパスの数 = Σ si*(si+1)/2

       部分木のサイズをどうやって求めるか？
       dfsで
       部分木のサイズ = 子ノードに入ってから出るまでの時間 - Σ 子ノードの先の他の部分木に入ってから出るまでの時間
    */
    impl Ctx {
        fn dfs(&mut self, node: usize, parent: usize, v: &Vec<Vec<usize>>) {
            self.clock += 1;
            let color = self.c[node];
            let start_clock = self.clock;

            for &next_node in &v[node] {
                if next_node != parent {
                    let start_clock = self.clock;
                    self.color_ct[color].push(0);
                    self.dfs(next_node, node, v);
                    let ct = self.color_ct[color].pop().unwrap();
                    self.color_sizes[color].push(self.clock - start_clock - ct);
                }
            }

            *self.color_ct[color].last_mut().unwrap() += 1 + self.clock - start_clock;
        }
    }

    ctx.dfs(0, n, &v);
    for i in 0..n {
        ctx.color_sizes[i].push(n as i64 - ctx.color_ct[i][0]);
    }

    for i in 0..n {
        let mut ans = n as i64 * (n + 1) as i64 / 2;
        //print!(" i={} ", i);
        for &size in &ctx.color_sizes[i] {
            let size = size as i64;
            ans -= size * (size + 1) / 2;
            //print!(" s={} ", size);
        }
        println!("{} ", ans);
    }
}


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

struct Card{char suit, value;};

void bubble(struct Card A[], int N){
    for (int i = 0; i < N; i++){
        for(int j = N-1; j>=i; j--){
            if(A[j].value < A[j-1].value){
                Card t = A[j];
                A[j] = A[j-1];
                A[j-1] = t;
            }
        }
    }
}

void selection(struct Card A[], int N){
    for(int i = 0; i< N; i++){
        int minj = i;
        for(int j = i; j< N; j++){
            if(A[j].value < A[minj].value) minj = j;
        }
        Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}

void print(struct Card A[], int N){
    for(int i=0; i< N; i++){
        if(i > 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N){
    for(int i = 0; i< N; i++){
        if(C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

int main(){
    Card C1[100], C2[100];
    int N;
    char ch;

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >>C1[i].suit >> C1[i].value;
    }
    for (int i = 0; i < N; i++) C2[i] = C1[i];

    bubble(C1, N);
    selection(C2, N);

    print(C1, N);
    cout <<"Stable" << endl;

    print(C2, N);
    if(isStable(C1, C2, N)){
        cout << "Stable" <<endl;
    } else {
        cout << "Not stable" << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll Digits(ll n)
{
    ll largest = 0;
    ll smallest = 9;

    while (n)
    {
        ll r = n % 10;
        largest = max(r, largest);
        smallest = min(r, smallest);
        n = n / 10;
    }
    ll ans = largest * smallest;
    return ans;
}
int main()
{
    fastio();
    int n;
    cin >> n;
    n %= 10;
    if (n == 0 or n == 1 or n == 6 or n == 8)
    {
        cout << "pon\n";
    }
    else if (n == 3)
    {
        cout << "bon\n";
    }
    else
    {
        cout << "hon\n";
    }
}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 *
 * @author saku
 */
public class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader sd = new BufferedReader(new InputStreamReader(System.in));
        String str = sd.readLine();
        
        int x = Integer.parseInt(str),  h=x/3600,m,s;
        x %= 3600;
        m=x/60;
        x%=60;
        s = x;
        
        System.out.println(h + ":" + m + ":" +s);
        
    }     
}

Measured memory_bytes: 24428
# -*- coding: utf-8 -*-

import bisect

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])

Aacc, Bacc = [0], [0]
for i in range(N):
    Aacc.append(Aacc[-1] + AB[i][0] * AB[i][1])
    Bacc.append(Bacc[-1] + AB[i][1])

idx = bisect.bisect(Bacc, M)
print(Aacc[idx - 1] if Bacc[idx - 1] == M else Aacc[idx - 1] + AB[idx - 1][0] * (M - Bacc[idx - 1]))


Measured memory_bytes: 26140
from collections import defaultdict
def gen_bound(x,B):
	if x < 3: lb = 2
	else: lb = x - 1
	if x > B-2: ub = B-1
	else: ub = x + 1
	return lb,ub
def solve():
	count = defaultdict(int)
	ans = [0]*10
	H,W,N = map(int,raw_input().split())
	ans[0] = (H-2)*(W-2)
	for i in xrange(N):
		a,b = map(int,raw_input().split())
		xlb,xub = gen_bound(a,H)
		ylb,yub = gen_bound(b,W)
		for x in xrange(xlb,xub+1):
			for y in xrange(ylb,yub+1):
				k = (x,y)
				bef_c = count[k]
				count[k] += 1
				ans[bef_c] -= 1
				ans[bef_c+1] += 1
	for c in ans:
		print c
solve()

Measured memory_bytes: 158400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
int gcd(int a, int b) 
{ 
	if (a == 0) 
		return b; 
	return gcd(b % a, a); 
} 
int invertBits(int num) 
{  
    int x = log2(num) + 1; 
    for (int i = 0; i < x; i++)  
       num = (num ^ (1 << i));  
   
    return num; 
} 
///////////////////////////////////////////////////////////////////////////////////////////////////////////
ll int w;
ll int m[101][100001];
ll int solve(ll int a[][2],ll int n,ll int curr,ll int pw)
{
	//cout<<curr<<" ";
	ll int wt=a[curr][0];
	if(m[curr][pw]!=0)
	{
		return m[curr][pw];
	}
	if(curr==n-1)
	{
		if(pw+wt>w)
		{
			return 0;
		}
		else
		{
			return a[curr][1];
		}
	}
	ll int a1=0,a2=0;
	if(pw+wt>w)
	{
		a1=solve(a,n,curr+1,pw);	
	}
	else
	{
		a2=solve(a,n,curr+1,pw+wt)+a[curr][1];
		a1=solve(a,n,curr+1,pw);
	}
	return m[curr][pw]=max(a1,a2);
}
int main()
{
	ll int n,i,j;
	cin>>n>>w;
   	ll int a[n][2];
   	for(i=0;i<n;i++)
   	{
   		cin>>a[i][0]>>a[i][1];
	}
	cout<<solve(a,n,0,0);
	return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int A, B, M; cin >> A >> B >> M;
    ll price_A[A], price_B[B];
    rep(i, A) cin >> price_A[i];
    rep(i, B) cin >> price_B[i];
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    rep(i, M){
        int x, y; ll c;
        cin >> x >> y >> c;
        pq.push(price_A[x-1] + price_B[y-1] - c);
    }
    sort(price_A, price_A+A);
    sort(price_B, price_B+B);
    pq.push(price_A[0]+price_B[0]);
    cout << pq.top() << endl;
    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if (a+c==2*b)
{
    cout<<"YES"<<endl;  
}
else
{
    cout<<"NO"<<endl;
}

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i,num;
  int p[24];
  double t[24];
  int n[24];
  int scn[3];
  int sortflag;
  int swp;

  for(i=0;i<24;i++){
    scanf("%d%lf",&p[i],&t[i]);
  }
  for(i=0;i<24;i++){
    n[i]=i;
  }
  
  for(;;){
    sortflag=0;
    for(i=0;i<7;i++){
      if(t[n[i]]>t[n[i+1]]){
        sortflag=1;
        swp=n[i];
        n[i]=n[i+1];
        n[i+1]=swp;
      }
    }
    if(sortflag==0)
      break;
  }
  printf("%d %0.2f\n",p[n[0]],t[n[0]]);
  printf("%d %0.2f\n",p[n[1]],t[n[1]]);

  for(;;){
    sortflag=0;
    for(i=8;i<15;i++){
      if(t[n[i]]>t[n[i+1]]){
        sortflag=1;
        swp=n[i];
        n[i]=n[i+1];
        n[i+1]=swp;
      }
    }
    if(sortflag==0)
      break;
  }
  printf("%d %0.2f\n",p[n[8]],t[n[8]]);
  printf("%d %0.2f\n",p[n[9]],t[n[9]]);
  
  for(;;){
    sortflag=0;
    for(i=16;i<23;i++){
      if(t[n[i]]>t[n[i+1]]){
        sortflag=1;
        swp=n[i];
        n[i]=n[i+1];
        n[i+1]=swp;
      }
    }
    if(sortflag==0)
      break;
  }
  printf("%d %0.2f\n",p[n[16]],t[n[16]]);
  printf("%d %0.2f\n",p[n[17]],t[n[17]]);

  scn[0]=n[2];
  scn[1]=n[10];
  scn[2]=n[18];

  for(;;){
    sortflag=0;
    for(i=0;i<2;i++){
      if(t[scn[i]]>t[scn[i+1]]){
        sortflag=1;
        swp=scn[i];
        scn[i]=scn[i+1];
        scn[i+1]=swp;
      }
    }
    if(sortflag==0)
      break;
  }
  printf("%d %0.2f\n",p[scn[0]],t[scn[0]]);
  printf("%d %0.2f\n",p[scn[1]],t[scn[1]]);
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[i]--;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(a[a[i]]==i) ans++;
  }
  cout << ans/2 << endl;
}


Measured memory_bytes: 640
echo H,W,A,B=`tr \  ,`\;M,C,Z,X=10**9+7,1,0,W+H-B-2 '
for I in range(H-'{'1):C=C*(X-I)*pow(','A):Z+=C;C=C*(B+I)*(H+~I)*pow((X-I)*'}-~I,M-2,M\)%M '
print Z%M'|pypy

Measured memory_bytes: 91124
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

struct LCA {
    private:
        ll N;
        vector<int> tree[200010];
        ll logN;
        int parent[200010] = {};
        int depth[200010] = {};
        int next_val[25][200010] = {};
        ll p;
    public:
        void build(ll n, vector<int> t[], ll pa = 0){
            N = n;
            p = pa;
            rep(i,0,N) tree[i] = t[i];
            logN = floor(log2(N)) + 1;
            dfs(p, -1, 0);
            rep(i,0,N){
                next_val[0][i] = parent[i];
            }
            rep(k,0,logN){
                rep(i,0,N){
                    if(next_val[k][i] == -1){
                        next_val[k+1][i] = -1;
                    }else{
                        next_val[k+1][i] = next_val[k][next_val[k][i]];
                    }
                }
            }
        }

        void dfs(ll cur, ll par, ll d){
            depth[cur] = d;
            parent[cur] = par;
            for(auto &e: tree[cur]){
                if(e == par) continue;
                dfs(e, cur, d+1);
            }
        }

        ll getParent(ll cur, ll num) {
            ll p = cur;
            rrep(k,logN-1, 0){
                if(p == -1){
                    break;
                }
                if((num >> k) & 1){
                    p = next_val[k][p];
                }
            }
            return p;
        }

        ll getLCA(ll va, ll vb){
            if(depth[va] > depth[vb]){
                va = getParent(va, depth[va] - depth[vb]);
            }else if(depth[va] < depth[vb]){
                vb = getParent(vb, depth[vb] - depth[va]);
            }
            ll lv = -1, rv = N+1;
            while(rv - lv > 1){
                ll mid = (rv + lv) / 2;
                ll ta = getParent(va, mid);
                ll tb = getParent(vb, mid);
                if(ta == -1 || tb == -1){
                    rv = mid;
                }else if(ta != tb){
                    lv = mid;
                }else{
                    rv = mid;
                }
            }
            return getParent(va, rv);
        }
} lca;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<int> tree[150010];
    rep(i,0,N){
        ll k;
        cin >> k;
        rep(j,0,k){
            ll c;
            cin >> c;
            tree[i].push_back(c);
            tree[c].push_back(i);
        }
    }
    lca.build(N, tree);
    ll Q;
    cin >> Q;

    while(Q--){
        ll a,b;
        cin >> a >> b;
        print(lca.getLCA(a,b));
    }

}


Measured memory_bytes: 42832
// D - Grid Coloring
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int H,W,N; cin>>H>>W>>N;
	vvi C(H, vi(W));
	for(int j=0, c=1; c<=N; ++c){
		int a; cin>>a;
		while(a--){
			int h = j/W, w = j%W;
			if(h%2) w = W - 1 - w;
			C[h][w] = c;
			j++;
		}
	}
	rp(h, 0, H) rp(w, 0, W) printf("%d%c", C[h][w], w+1==W? '\n':' ');
}

Measured memory_bytes: 384
using DataStructures
MOD = 2019

function main()
  a = readline() |> s -> split(s,"") |> xs -> parse.(Int,xs) |> reverse
  n = length(a)
  dp = zeros(Int, n+1)

  for i in 1:n
    dp[i+1] = (powermod(10, i-1, MOD) * a[i] + dp[i]) % MOD
  end

  cnt = counter(Int)
  for x in dp
    inc!(cnt, x)
  end
  ans = [x * (x-1) ÷ 2 for (k,x) in cnt] |> sum

  println(ans)
end

main()



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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  
  double kakua = h * 30.0 + m * 0.5;
  double kakub = m * 6.0;
  double theta = abs(kakua - kakub);
  double csq = a * a + b * b - (2 * a * b * cos(theta * M_PI / 180.0));
  cout << setprecision(18) << sqrt(csq);

}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;
    //cin>>testcase;
    for(int p=0;p<testcase;p++){
     ll n=0,a=0,b=0;
     cin>>n>>a>>b;
     string s;
     cin>>s;
     ll pass=0;
     ll overseas=0;
     for(int i=0;i<n;i++){
         if(s[i]=='a')
         {
            if(pass<a+b)
            {
                cout<<"Yes"<<"\n";
                pass++;
                
            }
            else
            cout<<"No"<<"\n";
         }
         else if(s[i]=='b'){
             if(pass<a+b && overseas<b){
                 cout<<"Yes"<<"\n";
                 pass++;
                 overseas++;
             }
             else
             {cout<<"No"<<"\n";
                 overseas++;}
         }
         else
         cout<<"No"<<"\n";
     }
        
    }

    return 0;
}


Measured memory_bytes: 848
# abc113 B
n = gets.to_i
t, a = gets.split.map(&:to_i)
h = gets.split.map.with_index(1){|x,i|[x.to_i,i]}

p h.sort_by{|hh|
  (a - (t - hh[0] * 0.006)).abs
}[0][1]




Measured memory_bytes: 1788