akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
char myHeap[200 * 1024 * 1024];
int sz = 0;
void assert_tle(bool q) { while (!q); }
void* operator new  ( std::size_t count ) {
    sz += count;
    assert_tle(sz <= 200 * 1024 * 1024);
    return myHeap + sz - count;
}
 
void operator delete (void *ptr) { }
 
 
void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void solve()
{
    int ar[]={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};
    int32_t k;
    cin>>k;
    k--;
    cout<<ar[k];
}
 
int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()


int main (void) {
  int N, M; std::cin >> N >> M;
  std::vector<int> X(M);
  for(int i=0; i<M; i++) std::cin >> X[i];
  std::sort(X.begin(), X.end());

  int L = X[M-1] - X[0];

  std::vector<int> diff(M-1);
  for(int i=0; i<M-1; i++) {
    diff[i] = X[i+1] - X[i];
  }
  std::sort(diff.begin(), diff.end(), std::greater<int>());

  if ( N >= M ) std::cout << 0 << std::endl;
  else {
    int ans = 0;
    for(int i=0; i<N-1; i++) ans += diff[i];
    std::cout << L - ans << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
ll a[100000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    int n1=n;
    int i=0;
    int j=n-1;
    if(n1==2){
        cout << ll(a[1]-a[0])<< "\n";
        return 0;
    }
    while(n1>2){
        ans=ll(ans+2*a[j]);
        j--;
        n1--;
        if(n1==2) break;
        ans=ll(ans-2*a[i]);
        i++;
        n1--;
    }
    if(n%2==0){
    ans=ll(ans+a[j]);
    }
    else{
        ans=ll(ans-a[j]);
    }
    ans=ll(ans-a[i]);
    if(n%2==1){
    ll ans1=ans;
    ans=0;
    i=0;
    j=n-1;
    int n1=n;
    while(n1>2){
        ans=ll(ans-2*a[i]);
        i++;
        n1--;
        if(n1==2) break;
        ans=ll(ans+2*a[j]);
        j--;
        n1--;
    }
    ans=ll(ans+a[j]);
    ans=ll(ans+a[i]);
    ans=max(ans1,ans);
    }
    cout << ans<< "\n";
}

Measured memory_bytes: 1024
import java.lang.Math.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val B = readLine()!!.split(" ").map(String::toInt)

    var rsl = B[0] + B[N-2]
    for (i in 1 until N-1) {
        rsl += min(B[i-1], B[i])
    }

    println(rsl)
}

Measured memory_bytes: 36028
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import           Data.Vector.Unboxed   (Vector)
import qualified Data.Vector.Unboxed   as V

main :: IO ()
main = do
  n <- readLn
  as1 <- getInts
  as2 <- getInts
  print $ solve n as1 as2

solve :: Int -> Vector Int -> Vector Int -> Int
solve _ as1 as2 = V.maximum $ V.zipWith (+) ls rs  where
  ls = V.scanl1' (+) as1
  rs = V.scanr1' (+) as2

getInts :: IO (Vector Int)
getInts = V.unfoldr (BS.readInt . BS.dropWhile (== ' ')) <$> BS.getLine


Measured memory_bytes: 508
import java.util.*;

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

    int n = sc.nextInt();
    int m = sc.nextInt();
    int[][] a = new int[n][m];
    int[] b = new int[m];
    int[] ans = new int[n];

    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(int i = 0; i < m; i++){
      b[i] = sc.nextInt();
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
        ans[i] += a[i][j] * b[j];
      }
    }

    for(int i = 0; i < n; i++){
      System.out.println(ans[i]);
    }
  }
}



Measured memory_bytes: 40432
#include<bits/stdc++.h>
using namespace std;
const int maxn=405,maxm=100500;
inline int read(int x=0,char c=getchar()){for(;c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-48;return x;}
int fa[maxn];
bool v[maxn];
int in[maxn],out[maxn],A[maxm],B[maxm],C[maxm],D[maxm],pa[maxm];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	int n,h,tot=0;cin>>n>>h;bool flag=1;
	for(int i=1;i<=n;++i) A[i]=read(),B[i]=read(),C[i]=read(),D[i]=read();//h<<=1;
	for(int i=1;i<=n;++i) {
		int a,b;
		if(!C[i]) a=h+A[i];else a=h-C[i];
		if(!D[i]) b=h-B[i];else b=h+D[i];
		++out[a],++in[b];
	}
	for(int i=0;i<h;++i) if(in[i]<out[i]) flag=0;//cout<<flag<<endl;
	for(int i=h+1;i<=h<<1;++i) if(in[i]>out[i]) flag=0;
	for(int i=0;i<=h<<1;++i) fa[i]=i,v[i]=(in[i]!=out[i]);
	for(int i=1;i<=n;++i){
		int a,b;
		if(!C[i]) a=h+A[i];else a=h-C[i];
		if(!D[i]) b=h-B[i];else b=h+D[i];
		if(find(a)==find(b)) pa[++tot]=a;
		else v[find(b)]|=v[find(a)],fa[find(a)]=find(b);
	}
	for(int i=1;i<=tot;++i) if(!v[find(pa[i])]) flag=0;
	puts(flag?"YES":"NO");
	return 0;
}

Measured memory_bytes: 5580
#include<bits/stdc++.h>
using namespace std;
int getSum(string n) 
 {  
    int sum = 0; 
   for(int i=0;i<n.size();i++){
    sum+=(int)n[i]-'0';
   }
 return sum;
} 
int main(){
 string n;
 cin>>n;
 if(getSum(n)%9==0)cout<<"Yes\n";
 else cout<<"No\n";
}


Measured memory_bytes: 3912
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, M;
int a[1005];
vector<int> vec;

int main(void)
{
	while(1){
		cin >> N >> M;
		if(N == 0 && M == 0) break;
		for(int i = 0; i < N; i++) cin >> a[i];
		a[N] = 0;
		
		vec.clear();
		for(int i = 0; i <= N; i++){
			for(int j = 0; j <= N; j++){
				vec.push_back(a[i] + a[j]);
			}
		}
		sort(vec.begin(), vec.end());
		
		int ans = 0;
		for(int i = 0; i < vec.size(); i++){
			auto p = upper_bound(vec.begin(), vec.end(), M-vec[i]);
			if(p == vec.begin()) continue;
			ans = max(ans, vec[i] + *(--p));
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n;
    cin >> n;
    vector<pair<string, ll>> st;
    rep(i, n) {
        string s;
        cin >> s;
        st.push_back({s, 1});
    }

    ll m;
    cin >> m;
    rep(i, m) {
        string s;
        cin >> s;
        st.push_back({s, -1});
    }

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

    // rep(i, n + m) { cout << st[i].fi << endl; }
    ll ans = 0, cnt = 0;

    rep(i, n + m) {
        if (st[i].fi == st[i + 1].fi) {
            cnt += st[i].se;
        } else {
            cnt += st[i].se;
            // cout << cnt << endl;
            chmax(ans, cnt);
            cnt = 0;
        }
        if (i == n + m - 1 && cnt != 0) chmax(ans, cnt);
    }

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

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    for(int i = a; i <= b; i++) {
        if(c % i == 0) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	VP data(n);
	map<P,int>dis;
	rep(i,n){
		cin>>data[i].F>>data[i].S;
	}
	P ter;
	rep(i,n){
		rep(j,n){
			if(i==j)continue;
			ter = mp(data[i].F - data[j].F, data[i].S - data[j].S);
			dis[ter]+=0;
			dis[ter]++;
		}
	}
	P up;
	int count=0;
	repi(itr,dis){
		if((itr->S) > count){
			count=(itr->S);
			up=(itr->F);
		}
	}
	cout<<n-count<<endl;
}

Measured memory_bytes: 3596
#!/usr/bin/env python3
import sys
from collections import defaultdict
from itertools import accumulate
import heapq

def solve(N: int, K: int, t: "List[int]", d: "List[int]"):
    sushi = defaultdict(list)
    for i in range(N):
        sushi[t[i]].append(d[i])

    A = [] # 各ネタでいちばんおいしい寿司のおいしさ
    B = [] # 各ネタで2番目以降においしい寿司のおいしさリスト
    
    for v in sushi.values():
        v.sort(reverse=True)
        A.append(v[0])
        B.extend(v[1:])
    A.sort(reverse=True)
    B.sort(reverse=True)

    X = [0] + [x for x in accumulate(A)] # X[i]: Aからうまい順にi個選んだ時のおいしさ合計
    Y = [0] + [y for y in accumulate(B)] # Y[j]: Bからうまい順にj個選んだ時のおいしさ合計

    res = 0
    for i in range(1, min(len(X), K + 1)):
        if K - i < len(Y):
            res = max(res, X[i] + Y[K - i] + i ** 2) 
            # B[:i]に含まれるネタが、A[i+1:]に含まれていた場合、実際のネタ数はiより多いが、
            # その場合はiを多くとったほうが、より美味しさが大きくなる。
            # そのためres[i]が答えになりえないため、無視して良い。
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    t = [int()] * (N)  # type: "List[int]" 
    d = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        t[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, K, t, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 35096
#include <cstdint>
#include <iostream>
#include <vector>
#include <algorithm>

int main(void)
{
    uint32_t a, b;
    std::string s;

    std::cin >> a >> b >> s;

    if (s.at(a) != '-') goto NO;
    if (s.size() != a+1+b) goto NO;

    for (auto c : s.substr(0, a)) {
        if (!('0' <= c && c <= '9')) goto NO;
    }

    for (auto c : s.substr(a+1, b)) {
        if (!('0' <= c && c <= '9')) goto NO;
    }

    std::cout << "Yes" << std::endl;
    return 0;

NO:
    std::cout << "No" << std::endl;
    return 0;
}

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

struct union_find{
    vector<int> r;
    
    union_find(int n){
        r = vector<int> (n, -1);
    }
    
    int root(int x){
        if(r[x] < 0){
            return x;
        }else{
            return r[x] = root(r[x]);
        }
    }
    
    bool unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            return false;
        }
        if (r[rx] > r[ry]) {
            swap(rx, ry);
        }
        r[rx] += r[ry];
        r[ry] = rx;
        return true;
    }
    
    int size(int x){
        return -r[root(x)];
    }
};

int main() {
    int n, m, a, b;
    cin >> n >> m;
    union_find UF(n);
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        UF.unite(a - 1, b - 1);
    }
    
    int ans = 0;
    
    for(int i = 0; i < n; i ++){
        ans = max(ans, UF.size(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def func(A, B, bit_len):
    if bit_len == 1:
        return [A, B]
    X = A ^ B
    for i in range(bit_len):
        if (X >> i) & 0x01 >= 1:
            break
    del_bit = i
    A_prime = ((A >> (del_bit + 1)) << del_bit) + (A & ((2 ** del_bit) - 1))
    B_prime = ((B >> (del_bit + 1)) << del_bit) + (B & ((2 ** del_bit) - 1))
    C = A_prime ^ 0x01
    retA = func(A_prime, C, bit_len - 1)
    retB = func(C, B_prime, bit_len - 1)
    ret = [0 for i in range(len(retA) + len(retB))]
    for i in range(len(retA)):
        ret[i] = (retA[i] & ((2 ** del_bit) - 1)) + (A & (2 ** del_bit)) + ((retA[i] & (~((2 ** del_bit) - 1))) << 1)
    for i in range(len(retB)):
        ret[len(retA) + i] = (retB[i] & ((2 ** del_bit) - 1)) + (B & (2 ** del_bit)) + ((retB[i] & (~((2 ** del_bit) - 1))) << 1)

    return ret




def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [int(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    countA = 0
    countB = 0
    for i in range(N):
        countA += (A >> i) & 0x01
    for i in range(N):
        countB += (B >> i) & 0x01
    if countA % 2 == countB % 2:
        print "NO"
        return
    ret = func(A, B, N)
    print "YES"
    for i in range(len(ret)):
        print ret[i],
    print

##    data_list = [0 for i in range(2 ** N)]
##    data_list[0] = A
##    pre_i = 0L
##    X = A
##    gray = [v ^ (v >> 1L) for v  in range(2 ** N)]
##    print gray
##
##    B_idx = 0
##    already = set([X])
##    for i in range(1L, 2L**N):
##        X = X ^ ((gray[i] ^ gray[i-1]))
##        if X in already:
##            print "NO"
##            return
##        already.add(X)
##        data_list[i] = X
##        if X== B:
##            B_idx = i
##    Z = data_list[B_idx - 1] ^ data_list[2 ** N - 1]
##
##    count = 0
##    for i in range(N + 1):
##        count += (Z >> i) & 0x01
##    if count != 1:
##        Z = data_list[B_idx - 1] ^ data_list[2 ** N - 3]
##        count2 = 0
##        for i in range(N + 1):
##            count2 += (Z >> i) & 0x01
##        if count2 != 1:
##            print "NO"
##            return
##        else:
##            tmp = data_list[2 ** N - 3]
##            data_list[2 ** N - 3] = data_list[2 ** N - 1]
##            data_list[2 ** N - 1] = tmp
##
##    print "YES"
##    for i in range(B_idx):
##        print data_list[i],
##    for i in range(2 ** N - 1, B_idx - 1, -1):
##        print data_list[i],
##
##    print

if __name__ == '__main__':
    main()


Measured memory_bytes: 16916
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
S = input()

wl = [0]*N
el = [0]*N
wr = [0]*N
er = [0]*N

if S[0] == 'W':
    wl[0] = 1
    el[0] = 0
else:
    wl[0] = 0
    el[0] = 1

if S[-1] == 'W':
    wr[0] = 1
    er[0] = 0
else:
    wr[0] = 0
    er[0] = 1

for i in range(1, N):
    if S[i] == 'W':
        wl[i] = wl[i-1] + 1
        el[i] = el[i-1]
    else:
        wl[i] = wl[i-1]
        el[i] = el[i-1] + 1

    if S[-i-1] == 'W':
        wr[i] = wr[i-1] + 1
        er[i] = er[i-1]
    else:
        wr[i] = wr[i-1]
        er[i] = er[i-1] + 1

# print(wl)
# print(el)
# print(wr)
# print(er)

res = N
for i in range(N):
    if i == 0:
        val = er[N-i-1]
    elif i == N-1:
        val = wl[i-1] 
    else:
        val = wl[i-1] + er[N-i-1]
    # print(i, val)
    if res > val:
        res = val

print(res)


Measured memory_bytes: 32360
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
  int a[8];
  while((scanf("%d%d%d%d%d%d%d%d",
	       &a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7]))!=EOF){
    int b[8][8] = { {1,2,1,2,1,4,1,4},
		   {1,2,1,4,1,4,1,2},
		   {1,4,1,2,1,2,1,4},
		   {1,4,1,4,1,2,1,2},
		   {2,1,2,1,4,1,4,1},
		   {2,1,4,1,4,1,2,1},
		   {4,1,2,1,2,1,4,1},
		   {4,1,4,1,2,1,2,1}};
    int c[8];
    int i,j,d,m=0x1fffffff;
    for(i=0;i<8;i++){
      d=0;
      for(j=0;j<8;j++){
	d += (a[j]-b[i][j] < 0) ? 0 : a[j] - b[i][j];
      }
      if(m>d) {
	memcpy(c,b[i],sizeof(int)*8);
	m = d;
      }
    }
    for(i=0;i<8;i++){
      if(i==7) printf("%d\n",c[i]);
      else printf("%d ",c[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 0
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

grid = [list(input()) for s in range(H)]
search = [[float('inf')] * W for _ in range(H)]

dq = deque([])
dq.append((Ch, Cw, 0))
search[Ch][Cw] = 0

direction = [[-1, 0], [0, -1], [1, 0], [0, 1]]
dq1 = deque([])

while dq:
    r, c, cur_cost = dq.popleft()
    dq1.append((r, c, cur_cost))

    for x, y in direction:
        r_new = r + x
        c_new = c + y

        if r_new < 0 or r_new >= H or c_new < 0 or c_new >= W or \
                search[r_new][c_new] <= cur_cost or grid[r_new][c_new] == '#':
            continue

        dq.append((r_new, c_new, cur_cost))
        search[r_new][c_new] = cur_cost

    if not dq:
        while dq1:
            r, c, cur_cost = dq1.popleft()

            for x in range(-2, 3):
                r_new = r + x
                if r_new < 0 or r_new >= H:
                    continue

                for y in range(-2, 3):
                    c_new = c + y

                    if c_new < 0 or c_new >= W or search[r_new][c_new] <= cur_cost + 1 or grid[r_new][c_new] == '#':
                        continue

                    dq.append((r_new, c_new, cur_cost + 1))
                    search[r_new][c_new] = cur_cost + 1


if search[Dh][Dw] == float('inf'):
    print(-1)
else:
    print(search[Dh][Dw])


Measured memory_bytes: 147856
/*
 *  Lang    : C++
 *  Author  : little_angel
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, sum = 0;
    cin >> n;
    vector<vector<int>> dp(n, vector<int>(n));
    vector<vector<int>> g(n, vector<int>(n, 1));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            dp[i][j] = min(min(i, j), min(n - 1 - i, n - 1 - j));
        }
    }

    vector<tuple<int, int>> del = {
            {-1, 0},
            {0,  -1},
            {1,  0},
            {0,  1}
    };

    auto valid = [&](int r, int c) -> bool {
        return 0 <= r && r < n && 0 <= c && c < n;
    };

    auto bfs = [&](int sr, int sc) {
        queue<tuple<int, int>> q;
        q.push({sr, sc});
        int x, y, mx, my, dx, dy;
        while (!q.empty()) {
            tie(x, y) = q.front();
            q.pop();
            int val = dp[x][y] + g[x][y];
            for (auto &i:del) {
                tie(dx, dy) = i;
                mx = x + dx;
                my = y + dy;
                if (valid(mx, my) && val < dp[mx][my]) {
                    dp[mx][my] = val;
                    q.push({mx, my});
                }
            }
        }
    };

    for (int i = 0; i < n * n; ++i) {
        int a;
        cin >> a;
        --a;
        sum += dp[a / n][a % n];
        g[a / n][a % n] = 0;
        bfs(a / n, a % n);
    }
    cout << sum << endl;
}


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


int main(){
    string S;
    long long K;
    cin >> S;
    cin >> K;
    int last_one = -1;
    for(int i = 0; i < S.length(); i++){
        if(S[i] != '1'){
            break;
        }else{
            last_one = i;
        }
    }
    if(K <= last_one + 1){
        cout << "1" <<endl;
    }else{
        cout << S[last_one+1] << endl;
    }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int[] P = new int[A];
		Arrays.setAll(P, $ -> sc.nextInt());
		int[] Q = new int[B];
		Arrays.setAll(Q, $ -> sc.nextInt());
		int[] R = new int[C];
		Arrays.setAll(R, $ -> sc.nextInt());
		Arrays.sort(P);
		Arrays.sort(Q);
		Arrays.sort(R);
		int pi = A - 1;
		int qi = B - 1;
		int ri = C - 1;
		long saturation = 0;
		for (int i = 0; i < X + Y; i++) {
			int ps = (A - (pi + 1)) >= X ? -1 : P[pi];
			int qs = (B - (qi + 1)) >= Y ? -1 : Q[qi];
			int rs = ri < 0 ? -1 : R[ri];
			if (ps > rs) {
				if (ps > qs) {
					saturation += ps;
					pi--;
				} else {
					saturation += qs;
					qi--;
				}
			} else {
				if (rs > qs) {
					saturation += rs;
					ri--;
				} else {
					saturation += qs;
					qi--;
				}
			}
		}
		System.out.println(saturation);
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 95944
#include<iostream>
#include<list>
#include<vector>
#include<queue>
using namespace std;

class Vertex;

class Adjacent{
  double weight;
  Vertex* vertex;
public:
  Adjacent(double w,Vertex* v):weight(w),vertex(v){};
  bool operator>(const Adjacent &x)const{ return (weight>x.weight);}
  friend class Graph;
  friend class Vertex;
};

class Vertex{
  int value;
  bool flag;
  bool infinity;
  list<Adjacent> adj_list;
  Vertex():value(0),flag(false),infinity(true){}
  friend class Graph;
};

class Graph{
  vector<Vertex*> graph;
public:
  Graph(int size){
    graph.resize(size);
    for(int i=0;i<size;i++){
      graph[i]=new Vertex();
    }
  }

  ~Graph(){
    for(int i=0;i<(int)graph.size();i++){
      delete graph[i];
    }
  }

  void addEdge(int from,int to,int w){
    graph[from]->adj_list.push_back(Adjacent(w,graph[to]));
    graph[to]->adj_list.push_back(Adjacent(w,graph[from]));
  }

  void prim(){
    Vertex *v=graph[0];
    int n=0;
    bool check=false;
    priority_queue<Adjacent,vector<Adjacent>,greater<Adjacent> > pq;
    int min=0;

    while(true){
      v->flag=true;
      n++;
      if(n==(int)graph.size())
	break;
      for(list<Adjacent>::iterator it=v->adj_list.begin();it!=v->adj_list.end();it++){
	Vertex* w=it->vertex;
	if(!w->flag){
	  if(w->infinity || w->value > it->weight){
	    w->infinity=false;
	    w->value = it->weight;
	    pq.push(Adjacent(w->value,w));
	  }
	}
      }

      while(true){
	if(pq.empty()){
	  check=true;
	  break;
	}
	v=pq.top().vertex;
	pq.pop();
	if(!v->flag) break;
      }

      if(check) break;
      min+=v->value;
    }
    cout<<min<<endl;
  }

};

int main(){
  int v=0;
  int e=0;
  cin>>v>>e;
  Graph graph(v);
  for(int i=0;i<e;i++){
    int from,to,w;
    cin>>from>>to>>w;
    graph.addEdge(from,to,w);
  }
  graph.prim();
  return 0;
}

Measured memory_bytes: 11420
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
typedef long long ll;
using namespace std;

int main() {
	int H,W; cin >> H >> W;
	string C[105];
	for (int i = 1; i <= H; ++i) cin >> C[i];
	for (int i = 1; i <= H; ++i) {
		cout << C[i] << endl << C[i] << endl;
	}
	
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m,ans=INF,a,b,c,smax,smin;
	cin >> n>>m;
	if (!(n % 3)|| !(m % 3)) {
		cout << 0 << endl;
		return 0;
	}
	else{
		ans = min(m,n);
	}
	
	for (ll i = 1; i <= n; ++i) {
		a = i * m;
		b = (n-i)*(m / 2);
		c = (n - i)*(m-(m / 2));
		smax = max(a, max(b, c));
		smin = min(a, min(b, c));
		ll temp = smax - smin;
		ans = min(ans, temp);
	}
	for (ll i = 1; i <= m; ++i) {
		a = i * n;
		b = (m - i)*(n / 2);
		c = (m - i)*(n - (n / 2));
		smax = max(a, max(b, c));
		smin = min(a, min(b, c));
		ll temp = smax - smin;
		ans = min(ans, temp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
 
typedef int Weight;
typedef int Edge;
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
typedef pair<Weight, int> Result;
Result visit(int p, int v, const Graph &g) {
  Result r(0, v);
  int f = g[v].size()==2;
  for(auto &e: g[v]) if (e != p) {
    Result t = visit(v, e, g);
    t.first += f; //e->weight;
    if (r.first < t.first) r = t;
  }
  return r;
}
Weight diameter(const Graph &g) {
  Result r = visit(-1, 0, g);
  Result t = visit(-1, r.second, g);
  return t.first; // (r.second, t.second) is farthest pair
}
 
int main(){
	int V,s,t;
	scanf("%d",&V);
	Graph g(V);
	for(;V>1;V--)scanf("%d%d",&s,&t),s--,t--,g[s].emplace_back(t),g[t].emplace_back(s);
	printf("%d\n",diameter(g)+count_if(g.begin(),g.end(),[](auto &e){return e.size()==1;}));
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    
    string s;
    cin >> s;
    int n = s.size();

    int w = 0;
    for (char c : s) w += c == 'o';

    if (w + (15 - n) >= 8) cout << "YES\n";
    else cout << "NO\n";

}   

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class163
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Dictionary<int, long> dic = new Dictionary<int, long>();
            for(int i = 0; i < N; i++)
            {
                if (!dic.ContainsKey(A[i]))
                    dic[A[i]] = 1;
                else
                    dic[A[i]]++;
            }
            Dictionary<int, long> count = new Dictionary<int, long>();
            long sum = 0;
            foreach(int i in dic.Keys)
            {
                count[i] = (dic[i] * (dic[i]-1)) / 2;
                sum += count[i];
            }
            
            for(int i = 0; i < N; i++)
            {
                Console.WriteLine(sum - count[A[i]] + ((dic[A[i]] - 1) * (dic[A[i]] - 2))/2);
            }
        }
    }
}


Measured memory_bytes: 49488
// Frof 2 - Atcoder - DP

#include<bits/stdc++.h>

using namespace std;

int main(){
	long int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	long long int dp[n]={0};
	
	for(int i=1;i<n;i++){
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		for(int j=i-2;j>=i-k && j>=0 ;j--){
			dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
		}
	}
	
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;
using ll = long long;
 
int main(){
    int n;
    cin >> n;
    vector<int> num(60010, 0);
    for(int x = 1; x <= 100; x++){
        for(int y = x; y <= 100; y++){
            for(int z = y; z <= 100; z++){
                int fn = x*x + y*y + z*z + x*y + y*z + z*x;
                if(x == y && y == z) num[fn]++;
                else if(x != y && y != z) num[fn] += 6;
                else num[fn] += 3;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        cout << num[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
const ll mod =   1e9+7;

int main()
{  fast
int x;
cin>>x;
cout<<((x*360)/(__gcd(x,360)))/x;
}

Measured memory_bytes: 3576
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	int i,j;
	int x;
	scanf("%d",&x);
	for(i=-1001;i<1001;i++)
	for(j=-1001;j<1001;j++)
	{
		if((long long)i*i*i*i*i-(long long)j*j*j*j*j==x)
		{
			printf("%d %d\n",i,j);
			return 0;
		}
	}
	
}

Measured memory_bytes: 1736
n = int(input())
m=a=r=c=h=0
for i in range(n):
  s = input()[0]
  if s == 'M':
    m += 1
  elif s == 'A': 
    a += 1
  elif s == 'R': 
    r += 1
  elif s == 'C': 
    c += 1
  elif s == 'H': 
    h += 1
  else:
    continue
march = [m,a,r,c,h]
march.sort()
if march[0] == march[1] == march[2] == 0:
  print(0)
elif march[0] == march[1] == 0:
  print(march[2]*march[3]*march[4])
elif march[0] == 0:
  print(march[1]*march[2]*march[3]
  +march[2]*march[3]*march[4]
  +march[3]*march[4]*march[1]
  +march[4]*march[1]*march[2])
else:
  print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h
  +a*r*c+a*r*h+a*c*h+r*c*h)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <string.h>
using namespace std;

int64_t comb(int n, int k) {
    if (n < k || k < 0) return 0;
    int64_t p[64] = { 1 };
    for (int i = 1; i <= n; i++) {
        int64_t t = 1;
        for (int j = 1; j <= i; j++) {
            int64_t s = p[j];
            p[j] += t;
            t = s;
        }
    }
    return p[k];
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int64_t v[50];
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    sort(v, v + n, greater<>());
    int64_t r = 0;
    int64_t cs = 0, ck = 0;
    for (int k = a; k <= b; k++) {
        int64_t s = 0;
        for (int i = 0; i < k; i++) {
            s += v[i];
        }
        int l0 = 0, l1 = 0;
        for (int i = 0; i < k; i++) {
            if (v[i] == v[k - 1]) l0++;
        }
        for (int i = 0; i < n; i++) {
            if (v[i] == v[k - 1]) l1++;
        }
        int64_t l = comb(l1, l0);
        if (ck == 0 || s * ck > cs * k) {
            cs = s;
            ck = k;
            r = l;
        } else if (s * ck == cs * k) {
            r += l;
        }
    }

    printf("%.9f\n%lld\n", (double)cs / ck, r);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>
#include <bitset>
#include <cstdio>
// #include <complex>
#include <random>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
// const ll INF = 1e9;
const ld INF = 1e20;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
//const double PI = acos(-1);


void solve() {
    int a, b;
    cin >> a >> b;
    cout << max(0, a - b - b);
}

int main() {
    // freopen("moscow.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    int a,b; cin>>a>>b;
  	if(b==1)
    {
      cout<<0;
      return 0;
    }
    if(a>=b)
    {
        cout<<1;
        return 0;
    }
    int ans = a,res=0;
    for(int i=1;i<=50000;i++)
    {
        if(ans < b){
            ans += (a-1);
            res++;
        }
        else{
            //res = i;
            break;
        }
    }
    cout<<res+1;
    return 0;
}


Measured memory_bytes: 256
a, b, c, k = map(int, input().split())

ans = 0
if a < k:
    ans += a
    k -= a
elif k <= a:
    print(k)
    exit()

if b < k:
    k -= b
elif k <= b:
    print(ans)
    exit()

ans += -1*k
print(ans)


Measured memory_bytes: 9180
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=110;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
char a[N],b[N],c[N];
signed main()
{
    cin>>a>>b>>c;
    printf("%c%c%c\n",a[0]-'a'+'A',b[0]-'a'+'A',c[0]-'a'+'A');
    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>S;
    N = S.size();
    set<char> alpha;
    bool yes = true;
    rep(i,N){
        if(alpha.find(S[i]) == alpha.end()){
            alpha.insert(S[i]);
        }else{
            yes = false;
        }
    }
    cout<<(yes ? "yes" : "no")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_V 100001
#define MAX_LOG_V 30
using namespace std;
typedef long long ll;
vector<int> G[MAX_V];
int root;
int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

void dfs(int v,int p,int d){
  parent[0][v]=p;
  depth[v]=d;
  for(int i=0;i<G[v].size();i++)if(G[v][i] != p)dfs(G[v][i],v,d+1);
}

void init(int V){
  dfs(root,-1,0);

  for(int k=0; k+1<MAX_LOG_V ;k++)
    for(int v=0; v<V ;v++)
      if(parent[k][v] < 0)parent[k+1][v] = -1;
      else parent[k+1][v] = parent[k][parent[k][v]];
}

int lca(int u,int v){
  if(depth[u]>depth[v]) swap(u,v);
  
  for(int k=0; k<MAX_LOG_V ;k++)
    if((depth[v]-depth[u])>>k&1)v=parent[k][v];
  
  if(u==v) return u;
  for(int k=MAX_LOG_V-1; k>=0 ;k--)
    if(parent[k][u] != parent[k][v]){
      u=parent[k][u];
      v=parent[k][v];
    }
  return parent[0][u];
}

ll dis(int a,int b){return depth[a]+depth[b]-2*depth[lca(a,b)];}

ll calc(vector<int>&v){
  vector<int> nv;
  for(int i=0;i<v.size();i++)
    for(int j=0;j<G[v[i]].size();j++)nv.push_back(G[v[i]][j]);
  if(nv.empty())return 0;
  ll res = dis(v.back(),nv[0]);
  v = nv;
  for(int i=0;i<v.size()-1;i++)res+=dis(v[i],v[i+1]);
  return res;
}

int main(){
  int n;
  cin>>n;
  for(int i=1,a;i<n;i++)cin>>a,G[a-1].push_back(i);
  init(n);
  vector<int>v(1);
  ll r=0,ans=0;
  while((r=calc(v)))ans+=r;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 25276
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int H = scan.nextInt();
        int W = scan.nextInt();
        int ans = 0;
        for (int i = 0; i < N; i++) {
            int A = scan.nextInt();
            int B = scan.nextInt();
            if (A < H) {
                continue;
            }
            if (B < W) {
                continue;
            }
            ans += 1;
        }
        System.out.println(ans);
    }
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

vector<string> ss;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    string s; int k;
    cin >> s >> k;
    int n = s.length();
    for(int i = 0; i < s.length(); i++)
    {
        for(int j = 1; j <= k; j++)
        {
            //cout << i << " " << j << endl;
            if(i+j-1==n)break;
            else ss.pb(s.substr(i,j));
        }
    }
    sort(ss.begin(),ss.end());
    unique(ss.begin(),ss.end());
    cout << ss[k-1] << endl;
}


Measured memory_bytes: 1660
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    bool solve(string& s) {
        int n = s.length();
        if (n != 6) {
            return false;
        }
        return s[2] == s[3] && s[4] == s[5];
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    Solution sol;
    if (sol.solve(s)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
import math
def c_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,k=map(int,input().split())
for i in range(1,k+1):
    if i <= n-k+1:
        print(((c_count(n-k+1,i)%(10**9+7)) * (c_count(k-1,i-1)%(10**9+7)))%(10**9+7))
    else:
        print(0)

Measured memory_bytes: 3316
#!/usr/bin/env python3
import math

def cal_primes(N):
    candidate = [*range(2, N+1)]
    primes = []

    while candidate[0]**2 <= N:
        primes.append(candidate[0])
        candidate = [*filter(lambda x: x % candidate[0] != 0, candidate)]
    
    primes.extend(candidate)
    return primes

def main():
    N = int(input())
    A = list(map(int, input().split()))
    if N == 2:
        if math.gcd(A[0],A[1]) == 1:
            ans = 0
        else:
            ans = 2
    else:
        A.sort()
        nums = [0] * (10**6+1)
        for a in A:
            nums[a] += 1
        
        plist = cal_primes(10**6//2)

        ans = 0
        for p in plist:
            now = p
            cnt = 0
            while now <= 10**6:
                cnt += nums[now]
                now += p
            if cnt == N:
                ans = 2
                break
            elif cnt > 1:
                ans = 1
    
    if ans == 0:
        print('pairwise coprime')
    elif ans == 1:
        print('setwise coprime')
    else:
        print('not coprime')

if __name__ == "__main__":
    main()

Measured memory_bytes: 204656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AParking solver = new AParking();
        solver.solve(1, in, out);
        out.close();
    }

    static class AParking {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            out.println(Math.min(n * a, b));
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21460
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 100005
using namespace std;
typedef long long ll;
ll dat[maxn<<2],dat2[maxn<<2],ans,C,N,x[maxn],v[maxn],clockw[maxn],countw[maxn];
void build(int id,ll l,ll r){
//	cout<<"OK"<<endl;
	if(l == r) dat[id] = clockw[(int)l];
	else{
		ll mid = (l + r) >> 1;
		build(id<<1,l,mid);
		build(id<<1|1,mid+1,r);
		dat[id] = max(dat[id<<1],dat[id<<1|1]);
	}
}
void build2(int id,ll l,ll r){
	if(l == r){
		dat2[id] = countw[(int)l];
	}else{
		ll mid = (l + r) >> 1;
		build2(id<<1,l,mid);
		build2(id<<1|1,mid+1,r);
		dat2[id] = max(dat2[id<<1],dat2[id<<1|1]);
	}
}
ll query(int id,ll l,ll r,ll x,ll y){
	if(x > y) return -1ll;
	if(x <= l && r <= y) return dat[id];
	ll mid = (l + r) >> 1;
	ll res = 0ll;
	if(x <= mid) res = max(res,query(id<<1,l,mid,x,y));
	if(y >= mid+1) res = max(res,query(id<<1|1,mid+1,r,x,y));
	return res;
}
ll query2(int id,ll l,ll r,ll x,ll y){
	if(x > y) return -1ll;
	if(x <= l && r <= y) return dat2[id];
	ll mid = (l + r) >> 1;
	ll res = 0ll;
	if(x <= mid) res = max(res,query2(id<<1,l,mid,x,y));
	if(y >= mid+1) res = max(res,query2(id<<1|1,mid+1,r,x,y));
	return res;
}
int main(){
	scanf("%lld%lld",&N,&C);
	for(int i=1;i<=N;i++){
		scanf("%lld%lld",&x[i],&v[i]);
		clockw[i] = clockw[i-1] + v[i] - (x[i]-x[i-1]);
	}
	for(ll i=N;i>=1;i--){
		countw[i] = countw[i+1] + v[i] - (C - x[i]);
		if(i != N) countw[i] += C - x[i+1];
	}
	build(1,1,N);//顺时针
	build2(1,1,N);//逆时针
//	cout<<"OK"<<endl;
//	for(int i=1;i<=N;i++){
//		cout<<clockw[i]<<" ";
//	}
//	cout<<endl;
//	for(ll i=N;i>=1;i--){
//		cout << countw[i] <<" ";
//	}
//	cout<<endl;
//	cout<<dat[1]<<endl;
//	system("pause");
	ans = max(ans,query(1,1,N,1,N));
	for(ll i=N;i>=1;i--){
//		cout<<"OK"<<endl;
		ans = max(ans,max(query(1,1,N,1,i-1) - (C - x[i]),0ll) + countw[i]);
	}
//	cout<<"OK"<<endl;
	ans = max(ans,query2(1,1,N,1,N));
	for(ll i=1;i<=N;i++){
		ans = max(ans,max(query2(1,1,N,i+1,N) - x[i],0ll) + clockw[i]);
	}
//	cout<<query2(1,1,N,2,N)<<endl;
//	cout<<dat2[1]<<endl;
	printf("%lld\n",ans);
	return 0;
}


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

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



int main()
{
	int N, K, R, S, P, ans = 0;
	char pre = 'X';
	string T;

	cin >> N >> K >> R >> S >> P >> T;

	rep(k, K) {
		for (int i = k; i < N; i += K) {
			if (T[i] != pre) {
				if (T[i] == 'r') ans += P;
				else if (T[i] == 's') ans += R;
				else if (T[i] == 'p') ans += S;
				pre = T[i];
			}
			else pre = 'X';
		}
		pre = 'X';
	}

	cout << ans << endl;

	return 0;
}


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

#define pb push_back
#define mp make_pair
#define F(i, a, n, b) for(int i=a;i<n;i+=b)
#define REVF(i, a, b, c) for(int i=a;i>=b;i-=c)
#define REP(i, n) F(i, 0, n, 1)
#define REP1(i, n) F(i, 1, n+1, 1)
#define REV(i, n) REVF(i, n, 0, 1)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef long long ll;

const ll MAX = 2e6 + 5;

int n;
double ans = 0.0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	if(n % 2 == 0)
		ans = n/2.0/n;
	else
		ans = (n - (n-1)/2*1.0)/n;
	cout<<fixed<<setprecision(10)<<ans;
	return 0;
}

Measured memory_bytes: 256