akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

//#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define cl(x, v) memset((x), (v), sizeof(x))
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define MOD 1000000007LL
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

int a[100010];
int b[100010];
int c[100010];

int dp[100010][4];
int n, k;

int solveR(int i, int l){
	if(i == n)
		return 0;
		
	if(dp[i][l] != -1)
		return dp[i][l];
	
	int ans = 0;

	if(l != 0)
		ans = max(ans, a[i] + solveR(i+1, 0));
	if(l != 1)
		ans = max(ans, b[i] + solveR(i+1, 1));
	if(l != 2)
		ans = max(ans, c[i] + solveR(i+1, 2));
		
	return dp[i][l] = ans;
}

int solveI(){
	dp[0][0] = a[0];
	dp[0][1] = b[0];	
	dp[0][2] = c[0];
	
	for(int i=1; i<n; i++){		
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);		
	}
	
	return max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}

int main() {
	
	scanf("%d", &n);
	
	for(int i=0; i<n; i++)
		scanf("%d %d %d", &a[i], &b[i], &c[i]);

//	memset(dp, -1, sizeof(dp));
//	printf("%d\n", solveR(0, 3));
	printf("%d\n", solveI());
		
	return 0;	
}


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

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    double a, ans=0.0; 
    for (int i=0; i<N; i++) {
        cin >> a;
        ans += 1.0/a;
    }
    cout << 1.0/ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
int main(void){
    string in;
    vector<set<int>> s1(10000), s2(10000);

    while(getline(cin, in), in.size()){
        int a, b; char c;
        stringstream ss(in);

        ss >> a >> c >> b;

        s1[a].insert(b);
    }

    while(getline(cin, in)){
        int a, b; char c;
        stringstream ss(in);

        ss >> a >> c >> b;

        s2[a].insert(b);
    }

    rep(i, 10000){
        if(s1[i].size() > 0 && s2[i].size() > 0){
            cout << i << " " << s1[i].size() + s2[i].size() << endl;
        }
    }

	return 0;
}

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

int main(){

	int x,y,a,b,c; cin>>x>>y>>a>>b>>c;
	vector<int> R(a),G(b),C(c);
	//vector<pair<int,char> > tot;
	vector<pair<int,char> > v,ot;
	for(int i=0;i<a;i++){
		cin>>R[i];
		v.push_back({R[i],'r'});
	}
	for(int i=0;i<b;i++){
		cin>>G[i];
		v.push_back({G[i],'g'});
	}
	for(int i=0;i<c;i++){
		cin>>C[i];
		v.push_back({C[i],'c'});
	}
	sort(v.begin(),v.end());
	int cnt_r=0,cnt_g=0;
	for(int i=v.size()-1;i>=0;i--){
		char tipo=v[i].second;
		int val=v[i].first;
		if(tipo=='c') ot.push_back({val,tipo});
		if(tipo=='r' and cnt_r<x){
			ot.push_back({val,tipo});
			cnt_r++;
		}
		if(tipo=='g' and cnt_g<y){
			ot.push_back({val,tipo});
			cnt_g++;
		}
	}

	long long int sum=0;
	cnt_g=0,cnt_r=0;

	for(int i=0,j=ot.size()-1;i<ot.size();){

		char tipo_left=ot[i].second,tipo_right=ot[j].second;
		int val_left=ot[i].first,val_right=ot[j].first;

		if(cnt_g==y and cnt_r==x) break;

		if(tipo_left=='c'){
			if(val_left>=val_right and tipo_right!='c'){
				sum+=val_left;
				if(tipo_right=='g') cnt_g++;
				else cnt_r++;
				i++;
			}
			j--;
		}else{
			if((tipo_left=='g' and cnt_g<y) or (tipo_left=='r' and cnt_r<x)){
				sum+=val_left;
				if(tipo_left=='g') cnt_g++;
				else cnt_r++;
			}
			i++;
		}
	}


	cout<<sum<<endl;	

	return 0;
}

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

int main(void){
    int A,B,K;
    cin >> A >> B >> K;
    int count = 0;
    for(int i=min(A,B);i>0;i--){
        if(A%i == 0 && B%i == 0){
            // cout << i << endl;
            count++;
        }
        if(count == K){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long K = lread();
    auto S = sread();
    if (S.length <= K)
    {
        writeln(S);
        return;
    }
    writeln(S[0 .. K], "...");
}


Measured memory_bytes: 3652
#include <iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,W; cin >> n >> W;
    int v[n]; int w[n];
    for(int i=0;i<n;i++){
        cin >> v[i] >> w[i];
    }

    int dp[n+100][W+100]={0};

    for(int i=0; i<n; ++i){
		for(int j=0; j<=W; ++j){
			if(j-w[i]>=0)
				dp[i+1][j] = max( dp[i+1][j-w[i]]+v[i], dp[i][j] );
			else dp[i+1][j] = dp[i][j];
		}
	}

    
	cout << dp[n][W] << endl;
}


Measured memory_bytes: 10936
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = getLine >> readInts >>= printf "%.10f\n" . solve . map ( fromIntegral :: Int -> Double ) . sort

solve [a] = a
solve (a1:a2:as) = solve ( ( a1 + a2 ) / 2 : as )

Measured memory_bytes: 508
{-# LANGUAGE PartialTypeSignatures #-}
-- {-# LANGUAGE Strict #-}
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L
import Data.Maybe

main :: IO ()
main = readInts >>= output . solve

solve :: [Int] -> _
solve [n] = sum [f a b c | a <- [1..n], b <- [1..n], c <- [1..n]]
  where
    f 1 _ _ = 1
    f _ 1 _ = 1
    f _ _ 1 = 1
    f a b c = gcd (gcd a b) c

output :: _ -> IO ()
output = print

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine


Measured memory_bytes: 4816
#include <iostream>
#include <cstring>
#include <algorithm>
//#define Max 2000000
using namespace std;
int dp[1001][1001];
char x[1000],y[1000];
void init(){
    for(int i=0;i<1000;i++)
        for(int j=0;j<1000;j++)
            dp[i][j]=0;
}
void LCS(){
    int m=strlen(x);
    int r=strlen(y);
    for(int i=1;i<=m;i++)
        for(int j=1;j<=r;j++)
        {
            if(x[i-1]==y[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
}
int main()
{
    int q;
    cin>>q;
    while((q--)>0){
        cin>>x;
        cin>>y;
        init();
        LCS();
        cout<<dp[strlen(x)][strlen(y)]<<endl;
    }
}


Measured memory_bytes: 7000
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define pb push_back
#define mod 1000000007
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define inf 1e18
#define pre(x,y) fixed<<setprecision(y)<<x
#define pq priority_queue<int>
#define mpq priority_queue<int,vector<int>,greater<int>>
#define gcd(x,y) __gcd(x,y)
#define mp make_pair


void dfs(vector<vector<int>> &v,int src,vector<int> &dp)
{
	dp[src]=0;
	int ans=0;
	for(auto x:v[src])
	{
		if(dp[x]==-1) dfs(v,x,dp);
		ans=max(ans,1+dp[x]);
	}
	dp[src]=ans;
}


int solve()
{
	int n,m,x,y,i;
	cin>>n>>m;
	vector<vector<int>> v(n+1);
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		v[x].pb(y);
	}

	vector<int> dp(n+1,-1);
	int ans=0;
	for(i=1;i<=n;i++)
	{
		if(dp[i]==-1)
		{
		dfs(v,i,dp);
		ans=max(ans,dp[i]);
	    }
	}
	return ans;
}





int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<solve()<<endl;
   
	return 0;
}


Measured memory_bytes: 12928
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long N,K,a,b,c,i,j,k,MOD,ans,A[100001],B[100001];

long long power(long long X,long long P,long long M)
{
  long long s;
  
  if(P==0)
  {
    return 1;
  }
  else if(P%2==0)
  {
    s=power(X,P/2,M);
    s*=s;
    s%=M;
    return s;
  }
  else
  {
    s=power(X,P-1,M)*X;
    s%=M;
    return s;
  }
}


int main()
{
  cin >>N>>K;
  MOD=1000000007;
  
 
  for(i=1;i<=K;i++)
  {
    a=K/i;
    A[i]=power(a,N,MOD);   
    B[i]=A[i];
  }
  
  for(i=K;i>=1;i--)
  {
    for(j=2;j*i<=K;j++)
    {
      B[i]-=B[j*i];
      if(B[i]<0) B[i]+=MOD;
      B[i]%=MOD;
    }
    
  }
  
  ans=0;
  for(i=1;i<=K;i++)
  {
    
    ans+=(i*B[i])%MOD;
    ans%=MOD;
  }
  
  cout <<ans; 
  
  
  
  
}

Measured memory_bytes: 5140
//
#include<cstdio>
#include<cmath> 
#include<iostream> 
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;
int n,x;
int main()
{
	//freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
	cin>>n>>x;
	cout<<n-x+1;
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main() {
	int N;cin>>N;
	vector<vector<int>>A(N, vector<int>(N));
	for(int i=0;i<N;i++)for(int j=0;j<N-1;j++)
	{
		cin>>A[i][j];
		A[i][j]--;
	}
	vector<int>pos(N);

	vector<vector<int>>Match(N, vector<int>(N));

	queue<int>kouho;
	for (int i = 0; i < N; i++)kouho.push(i);
	vector<int>p;

	int t = 1;
	while (1)
	{
		bool flag = true;
		for(int i=0;i<N;i++)if(pos[i] != N-1)flag = false;
		if(flag)break;

		p.clear();
		while(kouho.size())
		{
			int a,b;
			a = kouho.front();kouho.pop();
			if(pos[a] == N-1)continue;
			b = A[a][pos[a]];

			if(a > b)swap(a, b);
			if (Match[a][b])
			{
				pos[a]++;
				pos[b]++;
				p.push_back(a);
				p.push_back(b);
				cerr<<a<<" "<<b<<endl;
				flag = true;
			}
			else Match[a][b] = t;
		}
		for(int i=0;i<p.size();i++)kouho.push(p[i]);

		if (flag == false)
		{
			cout<<-1<<endl;
			return 0;
		}

		t++;
	}

	cout<<t-1<<endl;

	return 0;
}

Measured memory_bytes: 10240
num_hotels = int(input())
num_oceanview_hotel = 1
mountains = list(map(int,input().split()))
max_mountain = mountains[0]

for i in range(1, num_hotels):
    if mountains[i] >= max_mountain:
        max_mountain = mountains[i]  
        num_oceanview_hotel += 1
        
print(num_oceanview_hotel)

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int GCD(int a,int b){
	int tmp;
	if(a > b){
		tmp=a;
		a=b;
		b=tmp;
	}
	for(int i=a;i>=1;i--){
		if(a%i==0 && b%i==0){
			return i;
		}
	}
	return 1;
}

int LCM(int a,int b,int gcd){
	return a/gcd * b;
}

int main(void){
	int a,b;
	int gcd;
	while(scanf("%d %d",&a,&b)!=EOF){
		gcd=GCD(a,b);
		printf("%d %d\n",gcd,LCM(a,b,gcd));
	}

	

    return 0;
}


Measured memory_bytes: 2056
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int os = 0;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        os += a & 1;
    }
    cout << (os ? "first" : "second") << '\n';
}
/*
lose if
    2
    4
    6
    2 2
        win if
            2 2 1 1...
win if
    1 1 1...
    2 1 1...
    3 1 1...
    n 1 1...
        lose if
            2 2 1 1...
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 2000000000
const int N = 200010;
int frq[26];
int needed[5];
int have[5];
int main(){
	int h , w;
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++) for(int j=0;j<w;j++){
		char x;
		scanf(" %c",&x);
		frq[x - 'a']++;
	}
	if(h % 2 == 0 && w % 2 == 0){
		needed[0] = h * w;
	}
	else if(h % 2 == 1 && w % 2 == 0){
		needed[0] = ((h - 1) * w);
		needed[2] = w ;  
	}
	else if(h % 2 == 0 && w % 2 == 1){
		needed[0] = (h * (w - 1));
		needed[2] = h ;
	}
	else{
		needed[0] = ((h -1) * (w -1));
		needed[2] = h + w - 2;
		needed[1] = 1;
	}
	
	for(int i=0;i<26;i++) {
		have[0] += frq[i] - (frq[i] % 4);
		frq[i] = frq[i] % 4;
		have[2] += frq[i] - (frq[i] % 2);
		frq[i] = frq[i] % 2;
		have[1] += frq[i];
	}
	if(needed[0] > have[0]){
		puts("No");
		return 0;
	}
	have[0] -= needed[0];
	have[2] += have[0];
	if(needed[2] > have[2]){
		puts("No");
		return 0;
	}
	have[2] -= needed[2];
	have[1] += have[2];
	if(needed[1] > have[1]){
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
t[80000],j,c;main(i){for(;++i<256;)for(j=i;t[j+=i]=j<4e4;);for(;scanf("%d",&i)*i;c=!printf("%d\n",c))for(j=1;j++*2<i;)c+=!t[j]&!t[i-j];}

Measured memory_bytes: 0
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int N;
vector<pair<i64, int>> ai;
i64 memo[2005][2005];

i64 dp(int p, int leftNum) {
    if (p >= N) {
        return 0;
    }
    auto &ret = memo[p][leftNum];
    if (~ret) return ret;

    ret = 0;
    const auto [a, i] = ai[p];
    const int l = leftNum;
    const int r = N - (p - leftNum) - 1;
    chmax(ret, dp(p + 1, leftNum + 1) + a * abs(i - l));
    chmax(ret, dp(p + 1, leftNum) + a * abs(i - r));

    return ret;
}

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

    read(N);
    ai.resize(N);
    rep(i, 0, N) {
        var(int, a);
        ai[i] = {a, i};
    }

    sort(all(ai), greater<>());

    memset(memo, -1, sizeof(memo));
    print(dp(0, 0));

    return 0;
}


Measured memory_bytes: 35256
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int main(void) {
  string str;
  cin >> str;
  for (int i = 0; i < str.length(); i++) {
    if (i % 2 == 0) {

      cout << str[i];
    }
  }

  cout << endl;
  return 0;
}


Measured memory_bytes: 512
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

bool is_leapyear(int y) {
    if(y % 400 == 0) return true;
    if(y % 100 == 0) return false;
    return y % 4 == 0;
}

signed main() {
    int A, B;
    int line_cnt = 0;
    while(cin >> A >> B, A || B) {
        if(line_cnt > 0) cout << endl;
        line_cnt++;
        
        int cnt = 0;
        for(int i=A; i<=B; i++) {
            if(is_leapyear(i)) {
                cout << i << endl;
                cnt++;
            }
        }

        if(cnt == 0) cout << "NA" << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll N, K; cin >> N >> K;
    ll ans = 0;

    for(ll k = K; k <= N+1; k++) {
        ans += k * (2 * N - k + 1) / 2;
        ans %= MOD;
        ans -= k * (k - 1) / 2 - 1;
        ans %= MOD;
    }
    if(ans < 0) ans += MOD;
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a<c &&c<b)||(a>c&&c>b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main()
{
    ll a, b, n;
    cin >> a >> b >> n;
    ll x, ans;
    if (n >= b)
    {
        x = b - 1;
    }
    else
    {
        x = n;
    }
    ans = a * (x % b) / b;
    cout << ans << endl;
}

// なぜかwa

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int n, q;
vector<vector<int>> G(200005);
vector<int> ans(200005);
vector<bool> vi(200005, false);

void dfs(int a) {
	vi[a] = true;
	for (auto& c : G[a]) {
		if (vi[c]) continue;
		vi[c] = true;
		ans[c] += ans[a];
		dfs(c);
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> q;
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
	}
	rep(i, q) {
		int p, x; cin >> p >> x;
		p--;
		ans[p] += x;
	}
	dfs(0);
	rep(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " ");
	return 0;
}


Measured memory_bytes: 26624
#include <stdio.h>

#define mod 1000000007

int main(){
    long long int n,ans,u = 1,x = 1,ab = 1;
    scanf("%lld", &n);
    for(int i = 0; i < n; i++){
        u = (u * 10) % mod;
        x = (x * 9) % mod;
        ab = (ab * 8) % mod;
    }
    ans = (u - (x * 2) % mod + ab) % mod;
    ans = (ans + mod) % mod;
    printf("%lld\n", ans);
}

Measured memory_bytes: 1688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = sc.nextInt();
			int e=a*b;
			int f=c*d;
			if(e<=f)System.out.println(f);
			if(e>f)System.out.println(e);
	}
}

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

using ll = long long;
using ld = long double;

ll a, b, c, x, y, ans;

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

  cin >> a >> b >> c >> x >> y;
  if(2 * c >= a + b) {
    ans = a * x + b * y;
  } else {
    if(x >= y) {
      ans = 2 * c * y + (x - y) * a; 
    } else {
      ans = 2 * c * x + (y - x) * b;
    }
    ans = min(ans, 2 * c * max(x, y));
  }
  cout << ans << '\n';
  
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <map>
#include <vector>

using namespace std;


int main() {
    map<int, bool[13]> cards;
    vector<char> suites = {'S', 'H', 'C', 'D'};
    map<char, int> suitesDict;

    cards[0][13] = {};
    cards[1][13] = {};
    cards[2][13] = {};
    cards[3][13] = {};
    suitesDict['S'] = 0;
    suitesDict['H'] = 1;
    suitesDict['C'] = 2;
    suitesDict['D'] = 3;

    int n, num;
    char s;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s >> num;
        cards[suitesDict[s]][num - 1] = true;
    }

    for (auto pc:cards) {
        for (int i = 0; i < 13; ++i) {
            if (!pc.second[i]) {
                cout << suites[pc.first] << ' ' << i + 1 << endl;
            }
        }
    }
    return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> str;
    while(n--){
        string s;
        cin >> s;
        str.push_back(s);
    }
    sort(str.begin(), str.end());
    int count = 0;
    for(int i = 0; i < str.size(); i++){
        if(str[i] != str[i+1]){
            count++;
        }
    }
    cout << count << endl;

    return 0;
}



Measured memory_bytes: 11584
import sys

N, K = map(int, sys.stdin.readline().split())
h = tuple(map(int, sys.stdin.readline().split()))
cost = [None]*N
cost[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if i + j > N-1:
            break
        tmp = cost[i] + abs(h[i] - h[i+j])
        if cost[i+j] == None or cost[i+j] > tmp:
            cost[i+j] = tmp

print(cost[N-1])

Measured memory_bytes: 56156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (n); i += (s))
#define rep(...) _overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
struct Init {Init() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10);}} init;

int main() {
    ll h, n;
    cin >> h >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vvi dp(n + 1, vi(h + 1, INF));
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, h + 1) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][min(j+a[i], h)] = min(dp[i+1][min(j+a[i], h)], dp[i+1][j] + b[i]);
        }
    }
    print(dp[n][h]);
}

Measured memory_bytes: 81588
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    int now = 1;
    int ans = 0;
    while (true) {
        if (now == 2) {
            std::cout << ans << std::endl;
            return 0;
        }
        if (ans >= N)
            break;

        ans++;
        now = a[now - 1];
    }

    std::cout << -1 << std::endl;

    return 0;
}

Measured memory_bytes: 640
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        a: usize,
        b: usize,
    }

    for i in 0..10000 {
        let aa = i * 8 / 100;
        let bb = i * 10 / 100;
        if aa == a && bb == b {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}


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

int main() {
	string S ;
	cin >> S ;
	bool playable = true ;
	for(int i = 0, lim = S.length() ; i < lim ; ++i) {
		if( i % 2 == 0 && S[i] == 'L' ) {
			playable = false ;
			break ;
		}
		if( i % 2 == 1 && S[i] == 'R' ) {
			playable = false ;
			break ;	
		}
	}
	cout << (playable ? "Yes" : "No" ) << endl ;
	return 0 ;
}


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


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

    priority_queue<int> que;
    rep(i,n){
    	ll tmp;
	cin >> tmp;
	que.push(tmp);
    }
    while(m--){
    	ll tp = que.top();
	que.pop();
	tp /= 2;
	que.push(tp);
    }
    ll ans = 0LL;
    while(!que.empty()){
    	ans += que.top();
	que.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 892
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in) ;
		
		int cards[][] = new int[4][4] ;
		
		boolean flags[][] = new boolean[4][4] ;
		
		int num ;
		
		for(int i=0;i<3;i++) 
			for(int j=0;j<3;j++)
				cards[i][j] = in.nextInt() ;
		
		int cnt = in.nextInt() ;
		
		int bingo = 0 ;
		
		while(cnt-->0) {
			
			num = in.nextInt() ;
			
			for(int i=0;i<3;i++) 
				for(int j=0;j<3;j++)
					if(cards[i][j]==num) { flags[i][j] = true ; bingo++ ; }
		}
		
		boolean flag = false ;
		//check
//		if(bingo>=5) {
//			flag = true ;
////			System.out.println("Yes");
//		}else {
			for(int i=0;i<3;i++) if(checkr(flags,i)) { flag=true ; break ;}
			for(int j=0;j<3;j++) if(checkc(flags,j)) { flag=true ; break ;}
			if(checkx(flags)) { flag=true ; }
//		}
		if(flag)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
	public static boolean checkr(boolean[][] cards,int i) {
		boolean ans = false ;
		int cnt = 0 ;
		for(int j=0;j<3;j++) {
			if(cards[i][j]) cnt++ ;
		}
		if(cnt==3)
			ans = true ;
		return ans ;
	}
	public static boolean checkc(boolean[][] cards,int j) {
		boolean ans = false ;
		int cnt = 0 ;
		for(int i=0;i<3;i++) {
			if(cards[i][j]) cnt++ ;
		}
		if(cnt==3)
			ans = true ;
		return ans ;
	}
	public static boolean checkx(boolean[][] cards) {
		boolean ans = false ;
		if(cards[0][0]&&cards[1][1]&&cards[2][2]) { ans=true ; }
		if(cards[0][2]&&cards[1][1]&&cards[2][0]) { ans=true ; }
		return ans ;
	}
}


Measured memory_bytes: 23764
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main(){
    let line: Vec<i32> = read_as_vec();

    let (n, k) = (line[0], line[1]);

    
    println!("{}", n-k+1);
}


Measured memory_bytes: 4352
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

#[derive(Debug)]
struct Dice {
    top: u32,
    south: u32,
    east: u32,
    west: u32,
    north: u32,
    bottom: u32,
}

impl Dice {
    fn go_north(&mut self) {
        let tmp = self.top;
        self.top = self.south;
        self.south = self.bottom;
        self.bottom = self.north;
        self.north = tmp;
    }

    fn go_south(&mut self) {
        let tmp = self.top;
        self.top = self.north;
        self.north = self.bottom;
        self.bottom = self.south;
        self.south = tmp;
    }

    fn go_east(&mut self) {
        let tmp = self.top;
        self.top = self.west;
        self.west = self.bottom;
        self.bottom = self.east;
        self.east = tmp;
    }

    fn go_west(&mut self) {
        let tmp = self.top;
        self.top = self.east;
        self.east = self.bottom;
        self.bottom = self.west;
        self.west = tmp;
    }
}

impl PartialEq for Dice {
    fn eq(&self, other: &Self) -> bool {
        self.top == other.top
            && self.south == other.south
            && self.east == other.east
            && self.west == other.west
            && self.north == other.north
            && self.bottom == other.bottom
    }
}

fn main() {
    let v = read_vec::<u32>();
    let mut dice = Dice {
        top: v[0],
        south: v[1],
        east: v[2],
        west: v[3],
        north: v[4],
        bottom: v[5],
    };

    let v = read_vec::<u32>();
    let mut dice2 = Dice {
        top: v[0],
        south: v[1],
        east: v[2],
        west: v[3],
        north: v[4],
        bottom: v[5],
    };

    let mut f = 0;
    while dice.south != dice2.south {
        match f {
            4 => {
                dice.go_west();
                dice.go_south();
            }
            5 => {
                dice.go_north();
                dice.go_north();
            }
            _ => dice.go_north(),
        }
        f += 1;
    }
    while dice.top != dice2.top {
        dice.go_east();
    }

    yn(dice == dice2);
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
using ll     = long long;
using prefix = __attribute__((constructor))void;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807LL;

#define elif           else if
#define def            inline auto
#define func           inline constexpr ll
#define up(i,a,n)      for(ll i=(a),i##_1=(n);i<i##_1;++i)
#define down(i,a,n)    for(ll i=(a),i##_1=(n);i>=i##_1;--i)
#define rep(i,n)       up(i,0,n)
#define append         push_back

func    gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
func    lcm(ll a,ll b) {return a*b/gcd(a,b);}
def     dig(ll a)      {return to_string(a).length();}
prefix  init()         {cin.tie(0),ios::sync_with_stdio(0);}

ll L,ind=2;
vector<vector<ll>> V,A;

signed main(){
    cin>>L;
    while(L!=2){
        if(L%2==0){
            L/=2;
            A.push_back({1,L});
        }
        else{
            L--;
            A.push_back({2,L});
        }
    }
    V.push_back({1,2,0});
    V.push_back({1,2,1});
    down(i,A.size()-1,0){
        if(A[i][0]==1){
            V.push_back({ind,++ind,0});
            V.push_back({--ind,++ind,A[i][1]});
        }else{
            V.push_back({1,ind,A[i][1]});
        }
    }
    cout<<ind<<" "<<V.size()<<"\n";
    for(auto i: V)cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<"\n";
}
//for compilation: g++ -o _ _.cpp -std=c++14 (or 17)
//
//for fastening: g++ -O2 -o _ _.cpp -std=c++14 (or 17)
//for fastening: g++ -O3 -mtune=native -march=native -o _ _.cpp -std=c++14 (or 17)


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

manzoku = 0
for i in range(N):
    manzoku += B[A[i]-1]
    if i < N - 1 and A[i] + 1 == A[i + 1]:
        manzoku += C[A[i]-1]
print(manzoku)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

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

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    auto check = [&](ll m){
        ll res = 0;
        for(auto a: A){
            res += (a+m-1)/m - 1;
        }
        return (res<=K);
    };

    ll ng = 0;
    ll ok = 1e9+1;

    while(ok-ng>1){
        ll md = (ok+ng)/2;
        if(check(md)) ok = md;
        else ng = md; 
    }

    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 4764
import math

while True:
    N = int(input())
    if N == 0:
        break
    scores = list(map(float, input().split()))
    n = len(scores)
    mean = sum(scores) / n
    
    variance = 0
    for score in scores:
        variance += (score - mean)** 2
    variance /= n
    
    print(math.sqrt(variance))


Measured memory_bytes: 5768
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int colors[100][100];

int main()
{
    int h, w;
    cin  >> h >> w;
    int n;
    cin >> n;
    
    int k = 0;
    int i = 0;
    rep(k, 0, n)
    {
        int a;
        cin >> a;
        rep(j, 0, a)
        {
            if ((i/w) % 2 == 0)
                colors[i/w][i%w] = k + 1;
            else
                colors[i/w][w - 1 - (i%w)] = k + 1;
            ++i;
        }
    }

    rep(i, 0, h)
    {
        rep(j, 0, w)
        {
            printf("%d ", colors[i][j]);
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
n = list(input())
a = len(n)
N = []
for i in range(a):
    N.append(int(n[i]))
if N[0] == 9:
    print(max(sum(N), 9 * a - 1))
else:
    print(max(sum(N), 9 * (a - 1) + N[0] - 1))



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



int main( ) {
	int n , ans = 0 ; 
	cin >> n ; 
	for( int i = 1 ; i <= n ; i += 2 ) {
		for( int j = 2 ; j <= n ; j += 2 ) {
			if( ( i + j ) % 2 ) {
				ans ++ ; 
			}
		}
	}
	cout << ans ;
}

Measured memory_bytes: 256
#! /usr/bin/env python3

K, S = list(map(int, input().split()))
K += 1
cnt = 0
for i in range(min(K, S+1)):
    if i+K*2<=S : continue
    for j in range(min(K, S-i+1)):
        if i+j+K<=S : continue
        cnt += 1
print(cnt)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, L;
	cin >> N >> L;
	vector<string> string_array;

	rep(i, 0, N) {
		string s;
		cin >> s;
		string_array.push_back(s);
	}

	vsort(string_array);

	rep(i, 0, N) cout << string_array[i];
	cout << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    //bath < 5 && pool < 2  >> -20%
    int n;
    cin >> n;
    rep(i, n){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int C = c; int D = d;
        while(D < 2) D++;
        while(C < 5) C++;
        double ans = (a * C + b * D) * 0.8;
        double an = a*c + b*d;
        cout << min(an, ans) << endl;
    }
}

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

using namespace std;

struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef long long LL;

#define rep(i,n) for(auto i=(n)*0;i<n;i++)
#define range(it,v) for(auto &it:v)

ostream& operator<<(ostream& os,vector<int> v){
    int n=v.size();
    for(int i=0;i<n;i++)os<<(!i)+" "<<v[i];
    return os;
}

vector<int> ch(vector<int> A){
    vector<int> B;
    int n=A.size();
    if(n==1)A.push_back(0),n++;
    if(A.front()>1)B.push_back(A.front()-1);
    for(int i=1;i+1<n;i++)B.push_back(A[i]);
    B.push_back(A.back()+1);
    return B;

}

int main(){
    int N,M;
    cin>>N>>M;
    vector<vector<int>> unko(2);
    rep(i,M){
	int cww;
	cin>>cww;
	unko[cww&1].push_back(cww);
    }
    vector<int> A,B;
    if(unko[1].size()>2){
	cout<<"Impossible"<<endl;
    }
    else{	
	if(unko[1].size()){
	    A.push_back(unko[1].back());
	    unko[1].pop_back();
	}
	range(it,unko[0])A.push_back(it);
	if(unko[1].size()){
	    A.push_back(unko[1].back());
	    unko[1].pop_back();
	}
	cout<<A<<endl;
	auto B=ch(A);
	cout<<B.size()<<endl;
	cout<<B<<endl;
	
    }
    
    return 0;
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll MOD = 998244353ll;

ll modpow(const ll n, ll r){
    if(r == 0) return 1;
    ll ret = modpow(n, r / 2);
    ret = (ret * ret) % MOD;
    if(r % 2 != 0) ret = ret * n;
    return ret % MOD;
}


vector<vector<ll>> combination_array(int n){
    vector<vector<ll>> nCk(n + 1, vector<ll>(n + 1));
    nCk[0][0] = 1;
    repeat(i, 1, n + 1) {
        nCk[i][0] = nCk[i-1][0];
        repeat(j, 1, i + 1) {
            nCk[i][j] = (nCk[i-1][j] + nCk[i-1][j-1]) % MOD;
        }
    }
    return nCk;
}


class Solver {
  public:
    bool solve() {
        int K, N; cin >> K >> N;
        auto nCk = combination_array(max(N, K) * 2);
        auto nHr = [&] (int n, int r) { return nCk[n + r - 1][r]; };

        repeat(i, 2, 2 * K + 1) {
            int num_group = 0; repeat(j, 1, i) num_group += j <= K and i - j <= K and j < i - j;

            ll ans = 0;
            if(i % 2 == 1) {
                repeat(j, 0, num_group + 1) {
                    if(N - j >= 0)
                        ans += (((nCk[num_group][j] * nHr(K - 2 * num_group + j, N - j)) % MOD) * modpow(2, j)) % MOD;
                    ans %= MOD;
                }
            } else {
                repeat(j, 0, num_group + 1) {
                    if(N - j >= 0)
                        ans += (((nCk[num_group][j] * nHr(K - 2 * num_group + j - 1, N - j)) % MOD) * modpow(2, j)) % MOD;
                    ans %= MOD;
                    if(N - j - 1 >= 0)
                        ans += (((nCk[num_group][j] * nHr(K - 2 * num_group + j - 1, N - j - 1)) % MOD) * modpow(2, j)) % MOD;
                    ans %= MOD;
                }
            }
            cout << ans % MOD << endl;
        }

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)


void solve(long long N, long long M){
    if (N >= 2 && M >= 2) {
        cout << (N-2)*(M-2) << endl;
    } else if (N == 1 && M == 1) {
        cout << 1 << endl;
    } else if (N == 1 && M >= 2){
        cout << M-2 << endl;
    } else{
        cout << N-2 << endl;
    }
}

// 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)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


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

int main() {
    int n,m;cin>>n>>m;
    int lmx=0,rmn=100000;
    for (int i=0;i<m;i++) {
        int l,r;cin>>l>>r;
        lmx=max(lmx,l);
        rmn=min(rmn,r);
    }
    cout<<max(0,rmn-lmx+1)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char t1[12];

int f(int x){
	char t2[12];
	int i,c=4;
	memcpy(t2,t1,12);
	t2[x]-=2;
	for(i=1;i<=9;){
		if(t2[i]){
			if(t2[i]>2)t2[i]-=3;
			else if(t2[i+1]&&t2[i+2]){
				--t2[i];--t2[i+1];--t2[i+2];
			}
			else return 0;
			if(!--c)return 1;
		}
		if(!t2[i])++i;
	}
	return 0;
}

int main(void){
	char s[16];
	int i,j,z;
	for(;fgets(s,16,stdin);){
		memset(t1,0,12);
		for(z=i=0;i<13;)++t1[s[i++]-'0'];
		for(i=1;i<=9;i++){
			if(t1[i]<4){
				++t1[i];
				for(j=1;j<=9;j++){
					if(t1[j]>1&&f(j)){
						z++&&printf(" ");
						printf("%d",i,j);
						break;
					}
				}
				--t1[i];
			}
		}
		puts(z?"":"0");
	}
	return 0;
}

Measured memory_bytes: 0