akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        sort(a+1,a+n+1);
//        for(int i=1;i<=n;i++)
//            cout<<a[i]<<" ";
//        cout<<endl;
        int num=a[n/2+1]-a[n/2];
        cout<<num<<endl;
    }
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int a[100010];
main()
{
    int n,maxx=-20000000, minn=20000000;
    long long int sum=0;
    cin>>n;

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

    for(int i=0;i<n;i++)
    {
        if (a[i]>maxx)
            maxx=a[i];
    }

    for(int i=0;i<n;i++)
    {
        if (a[i]<minn)
            minn=a[i];
    }

    for(int i=0;i<n;i++)
    {
        sum=sum+a[i];
    }


    cout<<minn<<" "<<maxx<<" "<<sum<<endl;
}



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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
 double N,M,D;cin >> N >> M >> D;
 double ans = 0;
 if(D == 0){
   ans = (M-1) * (1/N);
 }else{
   ans = (M-1) * (2*(N-D)/(N*N));
 }
 cout << setprecision(25) << fixed;
 cout << ans << endl;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string card[15];

int main(void){
	int n,k;
	while(cin >> n >> k){
		if(n==0&&k==0) break;
		for(int i=0;i<n;++i) cin >> card[i];
		set<int> ans;
		sort(card,card+n);
		do{
			string cur="";
			for(int i=0;i<k;++i) cur+=card[i];
			ans.insert(stoi(cur));
		}while(next_permutation(card,card+n));
		cout << ans.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1348
/*
...........__________                                                                           ___  __
.............|       |                                                                           |   /
.............|       |                                                                           |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
...........__|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
void read_And_write(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void raushan_kumar(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int n,m;cin>>n>>m;
    int a[n+1];
    fo1(i,n) cin>>a[i];
    int A[n+1];
    mset(A,0);
    while(m--){
    	int u,v;cin>>u>>v;
    	A[u]=max(A[u],a[v]);
    	A[v]=max(A[v],a[u]);
    }
    fo1(i,n){
    	if(a[i]>A[i]){
    		ans++;
    	}
    }
    cout<<ans;
}

int32_t main()
{
    read_And_write();fast;int t=1;
    // cin>>t;
    while(t--){raushan_kumar();}
}

Measured memory_bytes: 5208
<?php
fscanf(STDIN, "%d %d %d %d", $h, $w, $a, $b);
$matrix = array();
for($i=0; $i<$b; $i++) {
    $matrix0[$i] = array_fill(0, $w, 0);
    $matrix1[$i] = array_fill($a, $w-$a, 1);
    $matrix[$i]  = array_replace($matrix0[$i],$matrix1[$i]);
}
for($i=$b; $i<$h; $i++) {
    $matrix0[$i] = array_fill(0, $w, 1);
    $matrix1[$i] = array_fill($a, $w-$a, 0);
    $matrix[$i]  = array_replace($matrix0[$i],$matrix1[$i]);
}
for($i=0; $i<$h; $i++) {
    for($j=0; $j<$w; $j++) {
        echo $matrix[$i][$j];
    }
    echo PHP_EOL;
}
?>

Measured memory_bytes: 114168
#!/usr/bin/env python
# coding: utf-8

import copy

def main():
    n, m = list(map(int, input().split()))
    num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    la = list(map(int, input().split()))
    la.sort()
    dp = [-1 for _ in range(n+10)]
    dp[0] = 0
    for i in range(n):
        if dp[i] == -1:
            continue
        for a in la:
            l = num[a]
            dp[i+l] = max(dp[i+l], dp[i]*10+a)
    print(dp[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 15212
import numpy as np
i8 = np.int64
i4 = np.int32


def calc(dp1, dp2, k):
    dp2[k:] |= dp1[:dp1.shape[0]-k]
    dp2[:dp2.shape[0]-k] |= dp1[k:]


def solve(z, dp):
    zero = dp.shape[2] // 2
    dp[0, 0, zero + z[0, 0]] = 1
    dp[0, 0, zero - z[0, 0]] = 1
    for x in range(1, z.shape[1]):
        calc(dp[0, x - 1], dp[0, x], z[0, x])
    for y in range(1, z.shape[0]):
        calc(dp[y - 1, 0], dp[y, 0], z[y, 0])
        for x in range(1, z.shape[1]):
            calc(dp[y, x - 1], dp[y, x], z[y, x])
            calc(dp[y - 1, x], dp[y, x], z[y, x])
    for i in range(zero, dp.shape[2]):
        if dp[dp.shape[0] - 1, dp.shape[1] - 1, i] > 0:
            return i - zero
    return -1


def main():
    stdin = open('/dev/stdin', 'rb')
    pin = np.fromstring(stdin.read(), i8, sep=' ')
    H, W = pin[:2]
    a = pin[2: 2 + H * W].reshape(H, W)
    b = pin[2 + H * W:].reshape(H, W)
    z = np.abs(a - b)
    dp = np.zeros((H, W, 80 * 80 * 2 + 1), i8)
    ans = solve(z, dp)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 652516
from collections import defaultdict, deque

H, W = map(int, input().split())
sss = [[int(c == '#') for c in input().rstrip()] for _ in range(H)]

dhw = [
    [0, 1],
    [1, 0],
    [0, -1],
    [-1, 0],
]

# h,w,dist
dq = deque([(0, 0, 0)])
# h,w
queued = {(0, 0)}

fdist = -1
while dq:
    h, w, dist = dq.popleft()
    
    if h == H - 1 and w == W - 1:
        fdist = dist
        break
        
    for dh, dw in dhw:
        nh = h + dh
        nw = w + dw
        ndist = dist + 1

        if (nh,nw) in queued:
            continue
        if not(0 <= nh < H) or not(0 <= nw < W):
            continue
        if sss[nh][nw]:
            continue

        dq.append((nh, nw, ndist))
        queued.add((nh, nw))

if fdist == -1:
    print(-1)
else:
    print(H * W - sum(sum(sss,[])) - fdist - 1)

Measured memory_bytes: 74292
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;

class Main {
    
    public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] firstRow = br.readLine().split("\\s");
    
    int elementNum = Integer.parseInt(firstRow[0]);
    int quantum = Integer.parseInt(firstRow[1]);
    
    Queue<Process> que = new LinkedList<Process>();
    for(int i = 0; i < elementNum; i++){
        String[] stringArray = br.readLine().split("\\s");
        
        Process process = new Process(stringArray[0], Integer.parseInt(stringArray[1]));
        que.offer(process);
    }
    
    int resultTime = 0;
    while(que.size() > 0){
        Process process = que.poll();
        
        resultTime += quantum;
        if ((process.processTime = process.processTime - quantum) > 0){
            que.offer(process);
            continue;
        }
        
        resultTime += process.processTime;
        
        System.out.println(process.name + " " + resultTime);
    }
    
}

private final static class Process {
    public String name = null;
    public int processTime = 0;
    
    public Process(String name, int processTime){
        this.name = name;
        this.processTime = processTime;
    }
}
}


Measured memory_bytes: 77760
#include<iostream>
#include<iomanip>

using namespace std;

long long int n, m, d;

int main(void) {

	cin >> n >> m >> d;

	long double ans;

	long double tmp;

	if (d == 0) { tmp = 1.0L / n; }
	else { tmp = 2.0L*(n - d) / n / n; }

	ans = tmp*(m - 1);

	cout << fixed <<setprecision(15)<<ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
h,n = map(int,input().split())
now = [10**10 for _ in range(h+1)]
now[0] = 0
for _ in range(n):
  a,b = map(int,input().split())
  for i in range(1,h+1):
    if i - a >= 0:
      now[i] = min(now[i],now[i-a]+b)
    else:
      now[i] = min(now[i],b)
print(now[-1])

Measured memory_bytes: 44520
#include <bits/stdc++.h>
using namespace std;
int n, a[100020];
int c[200020];
void R(int x, int y) {
	for (; x <= 2 * n + 10; x += x & -x) {
		c[x] += y;
	}
}
int G(int x) {
	int re = 0;
	for (; x > 0; x -= x & -x) {
		re += c[x];
	}
	return re;
}
bool ok(int M) {
	memset(c, 0, sizeof c);
	int s = n + 1;
	long long cnt = 0;
	for (int i = 0; i < n; i++) {
		R(s, 1);
		if (a[i] >= M) {
			s++;
		} else {
			s--;
		}
		cnt += G(s);
	}
	return cnt * 2 >= (long long)n * (n + 1) / 2;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int L = 0, R = 1e9 + 1;
	while (L < R - 1) {
		int M = (L + R) / 2;
		if (ok(M)) {
			L = M;
		} else {
			R = M;
		}
	}
	printf("%d\n", L);
	return 0;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll n,ans=0,cnt=0;
    cin >> n;
    vector<ll> a(n),sum(n+1,0);
    rep(i,n) cin >> a[i];
    rep(i,n){
        sum[i+1] = sum[i];
        sum[i+1] += a[i];
    }
    sort(all(sum));
    rep(i,n){
        if(sum[i+1] != sum[i]) cnt = 0;
        else{
            cnt++;
            ans += cnt;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3328
let memoize n f =
  let dp = Hashtbl.create n in
  let rec get x =
    try Hashtbl.find dp x with
    | Not_found ->
        let result = f get x in
        Hashtbl.add dp x result;
        result in
  get

let primes = memoize 55555 (fun primes -> function
  | 0
  | 1 -> []
  | 2 -> [2]
  | n ->
      primes (int_of_float @@ ceil @@ sqrt @@ float_of_int n)
      |> List.exists (fun p -> n mod p = 0)
      |> function
        | true -> primes (n - 1)
        | false -> n :: primes (n - 1))

let rec take n = function
  | [] -> []
  | x :: xs ->
      if n = 0 then []
      else x :: take (n - 1) xs

let () = Scanf.scanf "%d\n" @@ fun n ->
  primes 55555
  (*
   * (5i + 1) + (5j + 1) + (5k + 1) + (5l + 1) + (5m + 1) 
   * = 5 (i + j + k + l + m + 1)
   *)
  |> List.filter (fun p -> p mod 5 = 1)
  |> take n
  |> List.iter (Printf.printf "%d ")

Measured memory_bytes: 8448
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (a >= 13)
            writer.println(b);
        else if (a >= 6)
            writer.println(b / 2);
        else
            writer.println(0);
        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

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

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

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

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int n;
int h, m, s;
int t, u;

int main()
{
  while(cin >> n, n){
    priority_queue<pii> que;
    rep(i, n){
      scanf("%d:%d:%d", &h, &m, &s);  t = 3600 * h + 60 * m + s;
      scanf("%d:%d:%d", &h, &m, &s);  u = 3600 * h + 60 * m + s;
      que.push(mp(-t, -1));
      que.push(mp(-u, 1));
    }

    int res = 0;
    int cnt = 0;
    while(!que.empty()){
      pii p = que.top();  que.pop();
      cnt += p.second;
      minup(res, cnt);
    }

    cout << -res << endl;
  }

  return 0;
}

Measured memory_bytes: 1492
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	long long ans=0,a[n];
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		a[i] -= i;
	} 
	sort(a,a+n);
	for(int i=0;i<n;i++)
		ans += abs(a[n/2]-a[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

long long cub(int x) {
    return 1ll * x * x * x;
}

int main() {
    int N, K;

    cin >> N >> K;

    if (K & 1) {
        cout << cub(N/K) << endl;
    } else {
        cout << cub( (N+K/2)/K ) + cub(N/K) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll oddsum[500005];
ll evensum[500005];
//ll a[500005];
int main(){
    fastread;
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
}

Measured memory_bytes: 256
from math import ceil


def main():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())

    min_ = min([A, B, C, D, E])
    print(5 + ceil(N / min_)-1)


if __name__ == "__main__":
    main()


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;   
typedef pair<P,P> PP;

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

int n;
ll a[50];

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

	cin >> n;
	REP(i, n) cin >> a[i];

	ll ans = 0;
	while (true) {
		ll sum = 0;
		ll cnt[n] = {};
		REP(i, n) {
			if (a[i] > n - 1) {
				cnt[i] = (a[i] - (n - 1)) / n + !!((a[i] - (n - 1)) % n);
				sum += cnt[i];
			}
		}
		if (sum == 0) break;
		ans += sum;
		REP(i, n) {
			a[i] = a[i] - cnt[i] * n + (sum - cnt[i]);
		}
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
module Main where

import Control.Applicative
import Numeric
import Data.List

main :: IO ()
main = do
  { [n] <- getInts
  ; cards <- loop n
  ; putCards (allcards \\ cards)
  }

putCards :: [(Suit, Int)] -> IO ()
putCards = putStr . unlines . map showCard

loop :: Int -> IO [(Suit, Int)]
loop 0 = return []
loop n = do
  {c <-  getCard
  ; cs <- loop (n-1)
  ;return (c:cs)
  }

showCard :: (Suit, Int) -> String
showCard (s, n) = show s ++ " " ++ show n

--

data Suit = S | H | C | D deriving (Eq, Ord, Show, Read)

allcards :: [(Suit, Int)]
allcards = [(s,r) | s <- [S,H, C, D], r <- [1..13] ] 

getCard :: IO (Suit, Int)
getCard = do
  { [s, r] <- words <$> getLine
  ; return (read s, read r)
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn  .  unwords .  map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 4240
{-# LANGUAGE FlexibleContexts #-}

module Main where

import Debug.Trace
import Data.List
import qualified Data.Set as Set
import qualified Data.Sequence as Seq
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Word
import Data.Char
import Data.Bits
import Data.Array
-- import Data.Array.Unboxed
-- import Data.Array.IO
import Data.Maybe
-- import qualified Data.Map as M
import qualified Data.IntMap as M
-- import Control.Monad.ST
-- import Data.STRef
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf

solver :: String -> String -> [Int]
solver s l = iter 0 [] (take ls l) (drop ls l) where
    ls = length s
    iter _ ac _ [] = reverse ac
    iter i ac sc@(y:ys) (x:xs)
        | s == sc   = iter (i+1) (i:ac) (ys++[x]) xs
        | otherwise = iter (i+1) ac (ys++[x]) xs

main :: IO() 
main = do
    l <- getLine
    s <- getLine
    mapM_ print $ solver s (l++".")



Measured memory_bytes: 4092
from sys import stdin
N, T = [int(x) for x in stdin.readline().rstrip().split()]
d = 1001
for i in range(N):
  l = list(map(int, input().split()))
  if l[1] <= T:
    if l[0] < d:
      d = l[0]
if d < 1001:
  print(d)
else:
  print('TLE')

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

int main()
{
  string a,ret;
  cin >> a;
  ret = "";
  rep(x, a.length())
  {
    ret += "x";
  }
  cout << ret << endl;
  return 0;
}

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

ll func(ll b, ll p)
{
    ll i, ans = 1;
    for(i=1;i<=p;i++){
        ans *= b;
        ans %= mod;
    }
    return ans;
}

int main()
{
    ll n,ans;
    scanf("%lld", &n);
    ans = (((func(10,n)-(2*func(9,n))+func(8,n))%mod)+mod)%mod;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  ll h,w;cin>>h>>w;
  ll ans=0;
  ll ans2=0;
  if(h%3!=0 && w%3!=0){
    ans=min(h,w);
    for(ll i=1;i<=w-1;i++){
      ll t=h*(w-i);
      ll u=i*(h/2);
      ll v=i*(h-h/2);
      ans=min(ans, max(v, max(u, t))-min(v, min(u, t)));
    }
    swap(h,w);
    ans2=min(h,w);
    for(ll i=1;i<=w-1;i++){
      ll t=h*(w-i);
      ll u=i*(h/2);
      ll v=i*(h-h/2);
      ans2=min(ans2, max(v, max(u, t))-min(v, min(u, t)));
    }
  }
  P(min(ans, ans2));
  return 0;
}


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

using namespace std;

const int N = (int) 5e5 + 55;

int fen[N];

void upd(int x, int y) {
  while (x < N) {
    fen[x] += y;
    x |= (x + 1);
  }
}

int get(int x) {
  int res = 0;
  while (x >= 0) {
    res += fen[x];
    x = (x & (x + 1)) - 1;
  }
  return res;
}

int res[N];
vector<pair<int, int>> vec[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    --c[i];
  }
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    --l; --r;
    vec[r].emplace_back(l, i);
  }
  vector<int> last(n, -1);
  for (int i = 0; i < n; i++) {
    if (last[c[i]] != -1) {
      upd(last[c[i]], -1);
    }
    last[c[i]] = i;
    upd(i, 1);
    for (auto u : vec[i]) {
      res[u.second] = get(i) - get(u.first - 1);
    }
  }
  for (int i = 0; i < q; i++) {
    cout << res[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 33164
#include<iostream>
#include<set>
#include<cstring>
#include<queue>
using namespace std;
struct edge{int to,color;};
vector<edge> w[100010];
int n,m,d[100010];
set<int> s[100010];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	while(m--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		w[a].push_back({b,c});
		w[b].push_back({a,c});
	}
	memset(d,0x3f,sizeof d);
	d[1]=0;
	priority_queue<pair<int,int>> q;
	q.push({-d[1],1});
	while(q.size())
	{
		int now=q.top().second,cost=-q.top().first;q.pop();
		if(d[now]<cost) continue;
		for(edge j:w[now])
		{
			int dist=d[now];
			if(!s[now].count(j.color)) dist++;
			if(dist<d[j.to])
			{
				d[j.to]=dist;
				s[j.to].clear();
				s[j.to].insert(j.color);
				q.push({-d[j.to],j.to});
			}
			else if(dist==d[j.to])s[j.to].insert(j.color);
		}
	}
	if(d[n]>4e5)cout<<-1<<endl;
	else cout<<d[n]<<endl;
	return 0;
}


Measured memory_bytes: 21108
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = Int32.Parse(Console.ReadLine());
        var l = ((int)Math.Log10(N));
        var ans = 0;
        if(10000 <= N && N < 100000)
        {
            ans += ((N - 10000) + 1);
        }else if (100 <= N && N < 1000)
        {
            ans+= ((N - 100) + 1);
        }else if (1 <=N && N <10 )
        {
            ans += N;
        }
        if (l % 2 == 0) l--;
        while (-1 < l)
        {
            if (l % 2 == 0) ans += (9 * ((int)Math.Pow(10,(l))));
            l--;
        }
        Console.WriteLine(ans);
    }

}


Measured memory_bytes: 13140
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
#define int ll
 
#define START 0
#define GOAL 1
 
signed main(){
    ll t,n;
    cin>>t>>n;
    set<ll> st;
    vector<pll> data;
    rep(i,n){
        ll s,t;
        cin>>s>>t;
        data.pb(pll(s,START));
        data.pb(pll(t,GOAL));
    }
     
    sort(all(data));
     
    static ll rui[1000000];
    rep(i,1000000)rui[i] = 0;
     
    for(int i=0;i<data.size();i+=2){
        assert(data[i].second==START);
        rui[i+1] = data[i+1].first - data[i].first;
    }
     
    ll ans = 0;
     
    rep(i,1000000-1)rui[i+1] += rui[i];
     
    for(int i=0;i<data.size();i+=2){
        assert(data[i].second==START);
         
        ll end_time = data[i].first + t;
         
        int pos = upper_bound( all(data) , pll(end_time,-1) )-1-data.begin();
         
 
        if(data[pos].second==START){
            int r = rui[pos] - rui[i];
            ans = max(ans,r+(end_time - data[pos].first));
        }else if(data[pos].second==GOAL){
            int r = rui[pos]-rui[i];
            ans = max(ans,r);
        }
         
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 13828
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=100010;
const ll mod=1e9+7;


int main(){  
  int n;
  cin >> n;
  cout << n*(n+1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RG register
#define Min(a,b) (a<b?a:b)
#define ll long long

using namespace std;

inline int gi(){
	RG char ch=getchar();RG int x=0,q=0;
	while(ch<'0' || ch>'9') ch=='-'?(q=1):0,ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return q?(-x):x;
}

int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int q=gi(),h=gi(),s=gi(),d=gi(),n=gi();
	h=Min(h,(q<<1));
	s=Min(s,(h<<1));
	d=Min(d,(s<<1));
	ll ans=1ll*n/2*d;
	if (n&1) ans+=s;
	cout<<ans;
	return 0;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 r;
    cin >> r;
    cout << 3 * r * r << endl;
}


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;
ll a[200001];
set<int> s;
ll ans = 0;

int main(){
  cin >>n;
  FOR(i,1,n+1){
    int x;
    cin >> x;
    a[x] = i;
  }
  s.insert(0);s.insert(n+1);
  FOR(i,1,n+1){
    auto itr = s.lower_bound(a[i]);
    ans  += i*(*itr - a[i])*(a[i]-*(--itr));
    s.insert(a[i]);
  }
  cout << ans <<endl;
}


Measured memory_bytes: 11136
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int N;

int main () {
  vector<int> v_plus;
  vector<int> v_minus;

  cin >> N;
  rep(i, N) {
    int tmp;
    cin >> tmp;

    if (tmp < 0) v_minus.push_back(tmp);
    else v_plus.push_back(tmp);
  }

  if (v_minus.size() == N) {
    sort(All(v_minus), greater<int>());

    ll tmp_l = v_minus[0];

    Rep(i, N-1) {
      ll tmp_r = v_minus[i+1];
      tmp_l -= tmp_r;
    }

    cout << tmp_l << "\n";

    tmp_l = v_minus[0];
    Rep(i, N-1) {
      ll tmp_r = v_minus[i+1];
      cout << tmp_l << " " << tmp_r << "\n";
      tmp_l -= tmp_r;
    }
  } else if (v_plus.size() == N) {
    sort(All(v_plus));

    ll tmp_l = v_plus[0];

    Rep(i, N-2) {
      ll tmp_r = v_plus[i+1];
      tmp_l -= tmp_r;
    }

    cout << v_plus[N-1] - tmp_l << "\n";

    tmp_l = v_plus[0];

    Rep(i, N-2) {
      ll tmp_r = v_plus[i+1];
      cout << tmp_l << " " << tmp_r << "\n";
      tmp_l -= tmp_r;
    }

    cout << v_plus[N-1] << " " <<  tmp_l << "\n";
  } else {
    int p = v_plus.size();

    ll tmp = v_minus[0];
    Rep(i, p-1) {
      tmp -= v_plus[i+1];
    }

    tmp = v_plus[0] - tmp;

    for (int i=p;i<N-1;++i) {
      tmp -= v_minus[i-p+1];
    }

    cout << tmp << "\n";

    tmp = v_minus[0];
    Rep(i, p-1) {
      cout << tmp << " " << v_plus[i+1] << "\n";
      tmp -= v_plus[i+1];
    }

    cout << v_plus[0] << " " << tmp << "\n";

    tmp = v_plus[0] - tmp;

    for (int i=p;i<N-1;++i) {
      cout << tmp << " " << v_minus[i-p+1] << "\n";
      tmp -= v_minus[i-p+1];
    }
  }
}

Measured memory_bytes: 2424
#include <cstdio>
using namespace std;
int a[15];
int even[15], odd[15];
int main(){
	int i, j;
	int n;
	
	scanf("%d", &n);
	for(i=1; i<=n; i++)
		scanf("%d", &a[i]);
		
	even[n]=a[n]%2+1;
	odd[n]=3-even[n];

	for(i=n-1; i>=1; i--){
		if(a[i]%2){ //2 3 4
			odd[i]=odd[i+1];
			even[i]=3*even[i+1]+odd[i+1]*2;
		}
		else{ //1 2 3
			odd[i]=odd[i+1]*2;
			even[i]=3*even[i+1]+odd[i+1];
		}
	}
	printf("%d", even[1]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define MOD 1000000007

int main(int argc, const char * argv[]) {
    int S;
    cin>>S;
    
    int a=0,a_1=0,a_2=0,a_3=1;
    for(int i=2;i<S;++i){
        a=a_1+a_3;
        a%=MOD;
        a_3=a_2;
        a_2=a_1;
        a_1=a;
    }
    cout<<a<<endl;
    
    return 0;
}

Measured memory_bytes: 3184
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <iostream>

struct Matrix
{
	int rows;
	int columns;
};

int main()
{
	int n;
	std::cin >> n;
	//There's n matrixes.
	
	if(n == 1)
	{
		std::cout << 0 << std::endl;
		return 0;
	}
	
	Matrix matrix[1 + n];
	
	for(int i = 1;i <= n;i++)
	{
		//cin >> r, rows >> c, columns.
		std::cin >> matrix[i].rows >> matrix[i].columns;
	}
	
	long long int DPMem[1 + n][1 + n] = {0};
	
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			DPMem[i][j] = 9223372036854775807;
	
	//DP
	
	//init DPMem of M(i) * M(i) and M(i) * M(i + 1).
	for(int i = 1;i <= n - 1;i++)
	{
		DPMem[i][i] = 0;
		DPMem[i][i + 1] = matrix[i].rows * matrix[i].columns * matrix[i + 1].columns;
		
		//Debug.
		//printf("DPMem[%i][%i] = %lli \n",i,i + 1,DPMem[i][i + 1]);
	}
	DPMem[n][n] = 0;
	
	//Debug.
	//std::cout << std::endl;
	
	//DP main.
	for(int len = 3;len <= n;len++)		//len refers to length of multiplying matrix chain
	{
		//Debug.
		//printf("Length = %i \n",len);
		for(int head = 1;head + len - 1 <= n;head++)
		{
			int tail = head + len - 1;
			for(int mid = head;mid < tail;mid++)
			{
				//Debug.
				/*
				printf("DPMem[%i][%i] = %lli \n",head,tail,DPMem[head][tail]);
				printf("head = %i, mid = %i,mid + 1 = %i, tail = %i \n",head,mid,mid + 1,tail);
				*/
				
				DPMem[head][tail] = std::min(DPMem[head][tail],DPMem[head][mid] + DPMem[mid + 1][tail] + matrix[head].rows * matrix[mid].columns * matrix[tail].columns);
				
				//Debug.
				/*
				printf("DPMem[%i][%i] = %lli \n",head,mid,DPMem[head][mid]);
				printf("DPMem[%i][%i] = %lli \n",mid + 1,tail,DPMem[mid + 1][tail]);
				printf("matrix[%i].rows * matrix[%i].columns(matrix[%i].rows) * matrix[%i].columns = %i \n",head,mid,mid + 1,tail,matrix[head].rows * matrix[mid].columns * matrix[tail].columns);
				printf("DPMem[%i][%i] = %lli \n",head,tail,DPMem[head][tail]);
				std::cout << std::endl;
				*/
			}
		}
	}

	//Output.
	std::cout << DPMem[1][n] << std::endl;
	
	return 0;
}


Measured memory_bytes: 3144
import qualified Data.IntSet as S

main = do
    li <- getLine
    let [x,n] = map read $ words li
    li <- getLine
    let ps = map read $ words li
    let ans = compute x n ps
    print ans

compute :: Int -> Int -> [Int] -> Int
compute x n ps = head $ filter (flip S.notMember pS) cands
  where
    pS = S.fromList ps
    cands = x : [ y | i <- [1..], y <- [x-i,x+i] ]


Measured memory_bytes: 4224
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

x = readInt()
ans = math.ceil((-1+(x*8)**0.5)/2)
print(ans)

Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
int main(){
  double a,b,h,m,c,d,e;
  cin >> a >> b >> h >> m;
  c=M_PI*2*m/60;
  m=60*h+m;
  d=M_PI*2*m/720;
  e=abs(c-d);
  cout << fixed << setprecision(20) << sqrt(a*a+b*b-2*a*b*cos(e));
}


Measured memory_bytes: 4288
#include <stdio.h>

int main(void){
    int a=0,b=0;
    char op;
    
    while(true){ 
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?'){
            break;
        }
        if(op=='+'){
            printf("%d\n",a+b);
        }
        if(op=='-'){
            printf("%d\n",a-b);
        }
        if(op=='*'){
            printf("%d\n",a*b);
        }
        if(op=='/'){
            printf("%d\n",a/b);
        }
    }
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int Alice = 0;
    int Bob = 0;
    vector<int> vec(N);
    for(int i = 0; i < N; i++){
    	cin >> vec.at(i);
    }

    for(int i = 0; i < N; i++){
      int MAX = 0;
      int TOP = 0;
      for(int j = 0; j < N; j++){
        if(vec.at(j) > MAX){
          MAX = vec.at(j);
          TOP = j;
        }
      }
      if(i % 2 == 0){
        Alice += MAX;
      }else{
        Bob += MAX;
      }
      vec.at(TOP) = -1;
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

main()
{
	string s;
	cin >> s;
	
	if(s.size() == 2)
	{
		cout << s;
	}
	else
	{
		reverse(all(s));
		cout << s;
	}
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
 
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
 
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
 
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
 
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]


uf = UnionFind(N)
for j in range(M):
    x, y, z = list(map(int, input().split()))
    if not uf.is_same(x-1, y-1):
        uf.union(x-1, y-1)

# rootの個数
ans = 0
for i in range(N):
    if i == uf.par[i]:
        ans += 1
print(ans)




Measured memory_bytes: 8628
n = int(input())
def cntdiv(x):
  cnt = 0
  for i in range(1,x+1,1):
    if (x % i == 0) and (x % 2 == 1): cnt += 1
  return cnt
def cntans(x):
  if x <= 1:
    return 0
  if cntdiv(x) == 8:
    return 1 + cntans(x-1)
  else:
    return cntans(x-1)
print(cntans(n))


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%d", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long
#define float long double 
#define ll long long

const int inf = (int) 1e16;
const int upper = (int) 4e5 + 15;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	int n; cin >> n;
	int k; cin >> k;

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

	int dp[n + 1];

	for (int i = 1; i <= n; i += 1) dp[i] = inf;

	dp[1] = 0;

	for (int i = 2; i <= n; i += 1) {
		for (int j = 1; j <= k; j += 1) {
			if (i - j >= 1) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}

	cout << dp[n];
 	end_routine();	
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

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

int main(){
  FAST();

  vector<vector<int> > bingo(3, vector<int>(3));
  int i, j;
  REP(i, 0, 3)
    REP(j, 0, 3)
        cin >> bingo[i][j];
  int n;
  cin >> n;

  while(n--){
    int x;
    cin >> x;
    REP(i, 0, 3){
        REP(j, 0, 3){
            if(bingo[i][j] == x)
                bingo[i][j] = -1;
        }
    }
  }

    int flag = 0;
    REP(i, 0, 3){
        if(bingo[i][0] == -1 && bingo[i][1] == -1 && bingo[i][2] == -1)
            flag = 1;
    }
    REP(j, 0, 3){
        if(bingo[0][j] == -1 && bingo[1][j] == -1 && bingo[2][j] == -1)
            flag = 1;
    }
    if(bingo[0][0] == -1 && bingo[1][1] == -1 && bingo[2][2] == -1)
        flag = 1;
    if(bingo[0][2] == -1 && bingo[1][1] == -1 && bingo[2][0] == -1)
        flag = 1;

    if(flag == 0)
        cout << "No\n";
    else
        cout << "Yes\n";

  return 0;
}


Measured memory_bytes: 256
gets.to_i
S = gets.chomp.chars

r_e = S.count{|s| s == 'E'}
l_w = 0
ans = S.map{|s|
  r_e -= 1 if s == 'E'
  wk = r_e + l_w
  l_w += 1 if s == 'W'
  wk
}

puts ans.min


Measured memory_bytes: 29828
import numpy as np

N,K = map(int, input().split())
S = [int(x) for x in input()]

memo = np.zeros(10**5+1, dtype = np.int64)
W = min(2*K, 10**5)

current = 1 # 最初は1が0個ある
p = 0

for x in S:
  if x == current:
    memo[p] += 1
  else:
    current = 1 - current
    p += 1
    memo[p] += 1

ans = memo[:W+1].sum()
x = ans
for r in range(2,10**5+1,2):
  if r+W > 10**5:
    break
  x = x-memo[r-2]-memo[r-1]+memo[r+W]+memo[r+W-1]
  if x > ans:
    ans = x

print(ans)


Measured memory_bytes: 14140
#include <bits/stdc++.h>
using namespace std;
#define nl cout<<'\n'
#define nll <<'\n'
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL)
int main()
{
    int t;
    cin>>t;
    long long s=0;
    if(t>=500) s+=(t/500)*(long long)1000;
    t-=s/2;
    s+=(t/5)*5;
    cout<<s;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

long double EPS=1e-10;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(12);


    int n;cin>>n;
    long double ans=INF;
    vector<ll> x(n),y(n);

    rep(i,n) cin>>x[i]>>y[i];

    if(n==2){
        cout<<sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]))/2<<endl;
        return 0;
    }

    rep(i,n){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                long double a=x[i],b=y[i],
                            c=x[j],d=y[j],
                            e=x[k],f=y[k];
                long double ac=sqrt((a-c)*(a-c)+(b-d)*(b-d)),
                            ce=sqrt((e-c)*(e-c)+(f-d)*(f-d)),
                            ae=sqrt((e-a)*(e-a)+(f-b)*(f-b));
                long double cx,cy,r;
                if(abs(ac+ce-ae)<EPS){
                    cx=(a+e)/2;cy=(b+f)/2;
                    r=ae/2;
                }
                else if(abs(ac+ae-ce)<EPS){
                    cx=(c+e)/2;cy=(d+f)/2;
                    r=ce/2;
                }
                else if(abs(ae+ce-ac)<EPS){
                    cx=(a+c)/2;cy=(b+d)/2;
                    r=ac/2;
                }
                else{
                    cy=(e-a)*(a*a+b*b-c*c-d*d)-(c-a)*(a*a+b*b-e*e-f*f);
                    cy/=2*(e-a)*(b-d)-2*(c-a)*(b-f);
                    if(x[j]!=x[i]){
                        cx=2*(b-d)*cy-a*a-b*b+c*c+d*d;
                        cx/=2*(c-a);
                    }else{
                        cx=2*(b-f)*cy-a*a-b*b+e*e+f*f;
                        cx/=2*(e-a);
                    }
                    r=sqrt((cx-a)*(cx-a)+(cy-b)*(cy-b));
                }
                bool flag=true;
                rep(l,n){
                    long double dis=sqrt((x[l]-cx)*(x[l]-cx)+(y[l]-cy)*(y[l]-cy));
                    if(r+EPS>=dis) continue;
                    flag=false;
                }
                if(flag) chmin(ans,r);
            }
        }
    }

    rep(i,n){
        for(int j=i+1;j<n;j++){
            long double a=x[i],b=y[i],
                        c=x[j],d=y[j];
            long double cx=(a+c)/2,cy=(b+d)/2;
            long double r=r=sqrt((cx-a)*(cx-a)+(cy-b)*(cy-b));

            bool flag=true;
            rep(l,n){
                long double dis=sqrt((x[l]-cx)*(x[l]-cx)+(y[l]-cy)*(y[l]-cy));
                if(r+EPS>=dis) continue;
                flag=false;
            }
            if(flag) chmin(ans,r);
        }
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256