akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
bool cmax(sign &a,sign b){return (a<b)?a=b,1:0;}
bool cmin(sign &a,sign b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
  T ans=0,f=1;
  char ch=getchar();
  while(!isdigit(ch)&&ch!='-')ch=getchar();
  if(ch=='-')f=-1,ch=getchar();
  while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
  return ans*f;
}
template<typename T>void write(T x,char y)
{
  if(x==0)
  {
      putchar('0'),putchar(y);
      return;
  }
  if(x<0)
  {
      putchar('-');
      x=-x;
  }
  static char wr[20];
  int top=0;
  for(;x;x/=10)wr[++top]=x%10+'0';
  while(top)putchar(wr[top--]);
  putchar(y);
}
void file()
{
  #ifndef ONLINE_JUDGE
      freopen("test.in","r",stdin);
      freopen("test.out","w",stdout);
  #endif
}
const int N=1e5+5;
int n;
const int mo=1e9+7;
ll power(ll x,int y)
{
	ll res=1;
	for(;y;x=x*x%mo,y>>=1)if(y&1)res=res*x%mo;
	return res;
}
int a[N],b[N];
ll suma[N],sumb[N];
bool cmpa(int x,int y){return a[x]<a[y];}
bool cmpb(int x,int y){return b[x]<b[y];}
void input()
{
	n=read<int>();
	For(i,1,n)
	{
		a[i]=read<int>(),b[i]=read<int>();
	}
}
int vis[N];
int ida[N],idb[N];
ll ans,cnt;
void work()
{
	For(i,1,n)ida[i]=idb[i]=i;
	sort(ida+1,ida+n+1,cmpa);
	sort(idb+1,idb+n+1,cmpb);
	For(i,1,n)
	{
		suma[i]=suma[i-1]+a[ida[i]];
		sumb[i]=sumb[i-1]+b[idb[i]];
		//cout<<suma[i]<<' '<<sumb[i]<<endl;
	}
	ans=suma[n];
	For(i,1,n)vis[i]=1;
	Fordown(i,n,1)
	{
		//cout<<idb[n-i+1]<<' '<<ida[i]<<endl;
		if(++vis[idb[n-i+1]]==2)cnt++;
		if(--vis[ida[i]]==1)--cnt;
		if(i==1||cnt>0)ans=min(suma[i-1]+sumb[n-i+1],ans);	
		else ans=min(ans,min(suma[i-2]+sumb[n-i+1]+a[ida[i]]
				,sumb[n-i]+suma[i-1]+b[idb[n-i+2]]));
	}
	write(ans,'\n');
}
int main()
{
//	file();
	input();
    work();
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,maxn=1000000;
int n,h,d,ans,jc[2222222],pre[2222222],sum[2222222],dp[2222222];
void Init()
{
	jc[0]=1;
	for (int i=1;i<=maxn;i++) jc[i]=1ll*jc[i-1]*i%mod;
	pre[0]=1;
	for (int i=1;i<=maxn;i++) pre[i]=(pre[i-1]+jc[i])%mod;
}
int binpow(int a,int t)
{
	int res=1,p=a;
	for (int i=t;i;i>>=1)
	{
		if (i&1) res=1ll*res*p%mod;
		p=1ll*p*p%mod; 
	}
	return res;
}
int main()
{
	cin>>n>>h>>d;
	Init();
	dp[0]=1;sum[0]=1;
	for (int i=1;i<h;i++)
	{
		int cur=sum[i-1];
		if (i-1-d>=0) cur=(cur-sum[i-1-d])%mod;
		dp[i]=1ll*cur*(pre[n]-1)%mod;
		sum[i]=(sum[i-1]+dp[i])%mod;
	}
	for (int i=0;i<h;i++)
	{
		if (i+d>=h) ans=(ans+dp[i])%mod;
	}
	ans=1ll*ans*jc[n]%mod;
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 22784
#include <iostream>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5)) {
        cout << "YES";
    } else {
        cout << "NO";
    }
}

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

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long

int main(){
  string s;
  cin >> s;
  REP(i,s.size()){
    for(int j=i+1;j<s.size();j++){
      if(s[i]==s[j]){
        cout<<"no"<<endl;

        return 0;
      }
    }
  }
  cout<<"yes"<<endl;

  return 0;
}


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

int main() {
    int a = 0, b = 0;
    scanf("%d %d", &a, &b);
    int max = b - a;
    int ans = 0;
    for (int i=1; i<=max; i++) {
        ans += i;
    }
    ans -= b;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if (A + B +C >= 22) {
        cout << "bust" << endl;
    }
    else{
        cout << "win" << endl;
    }
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int a, b;
    scan(a, b);
    writeln(a * b % 2 ? "Yes" : "No");
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        String a=sc.next();
        int m=a.length();
        for(int i=0;i<m;i++)
            System.out.print("x");


    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
//#include<windows.h>


using namespace std;



#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9 + 7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;




int main() {
	int a[13] = {0,1,2,1,3,1,3,1,1,3,1,3,1};
	int x, y;
	cin >> x >> y;
	if (a[x] == a[y]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a, b, c;
	for(a = 1; a <= 9; a++){
		for(b = 1; b <= 9; b++){
			c = a * b;
			printf("%dx%d=%d\n",a, b, c);
		}
	}
    return 0;
}

Measured memory_bytes: 524
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


#define huge 1000000007
typedef long long ll;

int main(void) {
	
	ll N = 0;
	ll K = 0;
	ll X = 0;
	ll Y = 0;
	string w;
	int count = 0;
	cin >> w;
	string res = "Yes";
	//cin >> N >> K >> X >> Y;

	for (int i = 97; i < 97 + 26; i++) {
		char c = (char)i;
		
		for (int j = 0; j < w.length(); j++) {
			if (w[j] == c)
				count++;
		}

		if (count % 2 == 1) {
			res = "No";
			break;
		}
		else {
			count = 0;
		}

	}

	cout << res << endl;
	
	
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

template< typename T >
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

LL cost[112345];
vector<pair<LL,LL>> adjlist[112345];

void dfs(int v, int p, LL d)
{
    //dump(v)
    cost[v] = d;
    for(auto e : adjlist[v])
    {
        if(e.first == p) continue;
        dfs(e.first, v, d + e.second);
    }

}


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL N; cin >> N;
    REP(i,N-1)
    {
        LL a,b; LL c; cin>>a>>b>>c;
        adjlist[a].emplace_back(b,c);
        adjlist[b].emplace_back(a,c);
    }
    int Q,K; cin>>Q>>K;
    dfs(K,-1,0);
    vector<LL> ans;
    REP(i,Q)
    {
        int x,y; cin>>x>>y;
        ans.emplace_back(cost[x]+cost[y]);
    }
    for(auto p : ans)
    {
        cout << p << endl;
    }


}

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

 int main() {
   int N;
   cin >> N;
   vector<int> a(N);
   vector<int> b(N);
   vector<int> c(N-1);

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

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

   for(int i=0;i<N-1;i++) {
     cin >> c[i];
   }

   int total = 0;

   for(int i=0;i<N;i++) {
     total += b[a[i]-1];
     if(i != 0) {
       if(a[i] == a[i-1] + 1) {
         total += c[a[i]-2];
       }
     }
   }

   cout << total << endl;

   return 0;
 }

Measured memory_bytes: 256
n = gets.to_i
nums = gets.chomp.split.map(&:to_i)
1.upto(nums.size-1).each do |i|
  puts nums * ' '
  num = nums[i]
  while 0 < i && num < nums[i-1]
    nums[i] = nums[i-1]
    i -= 1
  end
  nums[i] = num
end
puts nums * ' '

Measured memory_bytes: 6120
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    char x; cin >> x;
    if ('a' <= x && x <= 'z') cout << 'a' << endl;
    else cout << 'A' << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
//最大公約数
int gcd(int a,int b){
    if(b > a){
        swap(a,b);
    }
    bool flag = true;
    int gcdl;
    while(flag){
        if(a%b == 0){
            flag = false;
            gcdl = b;
        }
        else{
            swap(a,b);
            b = b % a;
        }
    }
    return gcdl;
}
int main(){
    int n;
    cin >> n;
    long long a[n];
    for(int i = 0;i<n;i++){
        cin >> a[i];
    }   
    long long tem = gcd(a[0],a[1]);
    for(int i = 2;i<n;i++){
        tem = gcd(tem,a[i]);
    }
    cout << tem << endl;
}

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

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

constexpr int MAX_N = 100+10;
constexpr int MAX_W = 10000+10;

int v[MAX_N];
int w[MAX_N];
int dp[MAX_N][MAX_W];

int main() {
  int N, W;
  cin >> N >> W;
  for (int i{}; i < N; ++i) {
    cin >> v[i] >> w[i];
  }

  for (int i{}; i < N; ++i) {
    for (int j{}; j <= W; ++j) {
      if (j >= w[i]) {
        chmax(dp[i+1][j], dp[i][j - w[i]] + v[i]);
      }
      chmax(dp[i+1][j], dp[i][j]);
    }
  }

  cout << dp[N][W] << endl;
  return 0;
}



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

using namespace std;

int main() {
	string s;
	cin >> s;
	int m = 10000;
	for (int i = 0; i < s.length() - 2; i++)
		m = min(m, abs(stoi(s.substr(i, 3)) - 753));
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn main() {
    let stdin = std::io::stdin();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut s = String::new();
    reader.read_line(&mut s).unwrap();
    let s = s.trim();
    let abcd: Vec<i32> = s.chars().map(|x| x.to_string().parse().unwrap()).collect();
    let a = abcd[0];
    let b = abcd[1];
    let c = abcd[2];
    let d = abcd[3];

    let abcd = [
        [a, b, c, d],
        [a, -b, c, d],
        [a, b, -c, d],
        [a, b, c, -d],
        [a, -b, -c, d],
        [a, b, -c, -d],
        [a, -b, c, -d],
        [a, -b, -c, -d],
    ];
    let ans = abcd
        .iter()
        .filter(|x| x.iter().sum::<i32>() == 7)
        .nth(0)
        .unwrap();
    println!("{}{:+}{:+}{:+}=7", ans[0], ans[1], ans[2], ans[3]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a,b;
    cin >> a >> b;
    if(a == 'H'){
        print(b);
    }else{
        if(b == 'H'){
            print("D");
        }else{
            print("H");
        }
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    vll sm(n+1, 0);
    rep(i, n) sm[i+1] = sm[i] + a[i];
    int ans = 1;
    for (int i = n-1; i >= 1; --i) {
        if (sm[i]*2 >= a[i]) ans++;
        else break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents

main = do
    argMatrix <- getIntMatrix
    print $ solve argMatrix


solve :: [[Integer]] -> Integer
solve ll =  2 * target - rate
    where 
        rate = head $ head ll
        target = head $ last ll 


Measured memory_bytes: 380
function Main(input){
  var inputArray = input.split(' ');
  var D = Number(inputArray[0]);
  var T = Number(inputArray[1]);
  var S = Number(inputArray[2]);
  
  return console.log(D/S <= T ? 'Yes' : 'No');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 30580
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.fold_left (fun (evens, odds) a ->
    if a mod 2 = 0 then (3 * evens + odds, 2 * odds)
    else (3 * evens + 2 * odds, odds)) (0, 1) as_
  |> fst
  |> Printf.printf "%d\n"

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

int main() {
  char a, b;
  cin >> a >> b;
  if (a == 'H') {
    printf("%c", b);
  } else {
    printf("%c", b == 'H' ? 'D' : 'H');
  }
  return 0;
}

Measured memory_bytes: 256
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

LL bin(LL a, LL b, LL p) {
	LL res = 1;
	for (a%=p; b; b>>=1, a=a*a%p)
		if (b & 1)
			res = res * a % p;
	return res;
}

int n;
const int N = 2e5+50;

int siz[N], sum[N];

vector<int> G[N];

int c[N];
LL ans[N];

void dfs(int u, int fa) {
	siz[u] = 1;
	int sons = 0;
	for (int v : G[u]) {
		if (v == fa)
			continue;
		int now = sum[c[u]];
		dfs(v, u);
		siz[u] += siz[v];
		int add = sum[c[u]] - now;
		ans[c[u]] += 1LL * (siz[v] - add) * (siz[v] - add + 1) / 2;
		sons += siz[v] - add;

		dbg(u, c[u], siz[v]-add, add);
	}
	sum[c[u]] += sons+1;
}

bool used[N];

int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &n);
    for (int i=1; i<=n; ++i) {
    	scanf("%d", &c[i]);
    	used[c[i]] = true;
    }
    for (int i=1; i<n; ++i) {
    	int u, v;
    	scanf("%d%d", &u, &v);
    	G[u].push_back(v);
    	G[v].push_back(u);
    }

    dfs(1, 0);
    for (int i=1; i<=n; ++i) {
    	if (used[i]) {
    		ans[i] += 1LL * (n-sum[i]) * (n-sum[i]+1) / 2;
    		printf("%lld\n", 1LL*n*(n+1)/2 - ans[i]);
    	} else {
    		printf("0\n");
    	}
    }


    return 0;
}

Measured memory_bytes: 37604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N+1);
    vector<ll> check(N, -1);
    ll l, r;
    ll aa, b;
    for (ll i = 0; i < N+1; i++) {
        cin >> a[i]; a[i]--;
        if(check[a[i]] == -1) {
            check[a[i]] = i;
        }
        else{
            l = check[a[i]];
            r = i;
        }
    }

    aa = l;
    b = N-r;

    vector<ll> fact(100005);
    fact[0] = 1; fact[1] = 1;
    for (int i = 2; i < 100005; i++) {
        fact[i] = fact[i-1] * i % MOD;
    }
    vector<ll> inv(100005); inv[1] = 1;
    for (int i = 2; i < 100005; i++) {
        inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
    }
    vector<ll> invfact(100005);
    invfact[0] = 1; invfact[1] = 1;
    for (int i = 2; i < 100005; i++) {
        invfact[i] = invfact[i-1] * inv[i] % MOD;
    }  

    ll ans;
    ll tmp1;
    printf("%lld\n", N);
    for (ll k = 2; k < N+2; k++) {
        ans = fact[N+1] * invfact[k] % MOD;
        ans = ans * invfact[N-k+1] % MOD;
        if(aa + b >= k-1){
            tmp1 = fact[aa + b] * invfact[k-1] % MOD;
            tmp1 = tmp1 * invfact[aa+b-k+1] % MOD;
            ans = (MOD + ans - tmp1) % MOD;
        }
        printf("%lld\n", ans);
    }

}


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

N = int(input())
P = list(map(int, input().split()))
M = [0] * N
M[0] = P[0]
m = P[0]
for i in range(1, N):
    m = min(P[i], m)
    M[i] = m


ans = 0
for i in range(N):
    if P[i] <= M[i]:ans+=1

print(ans)


Measured memory_bytes: 24744
K = int(input())
num = 0

import itertools

Lun = [[] for _ in range(11)]
Lun[1] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(2, 11):
    for j in Lun[i-1]:
        j_mod = j % 10
        if j_mod != 0:
            Lun[i].append(j * 10 + j_mod - 1)
        Lun[i].append(j * 10 + j_mod)
        if j_mod != 9:
            Lun[i].append(j * 10 + j_mod + 1)

Lunlun = list(itertools.chain.from_iterable(Lun))
print(Lunlun[K-1])

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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x >= r && W >= x + r) {
		if (y >= r && H >= y + r) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 3096
import sys
input=sys.stdin.readline
from itertools import accumulate
sys.setrecursionlimit(100000000)

def main():
    a,b,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    ans=min(a)+min(b)
    for i in range(m):
        x,y,c=map(int,input().split())
        x-=1
        y-=1
        tmp=a[x]+b[y]-c
        ans=min(tmp,ans)
    print(ans)

  

if __name__=='__main__':
    main()

Measured memory_bytes: 18616
using System;
using System.Linq;
class c
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse).OrderBy(f => f).ToArray();
        Console.WriteLine(inp.Count(f => f % 2 == 0) > 0 ? 0 : inp[0] * inp[1]);
    }
}

Measured memory_bytes: 13396
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
#define v1out(v) FOR(j,0,v.size()){cout<<v[j]; if(j!=(ll)v.size()-1)cout<<" ";else cout<<endl; }
#define v2out(v) FOR(i,0,v.size())v1out(v[i]);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> lR(n);
    vector<int> lG(n);
    vector<int> lB(n);
    vector<int> rR(n);
    vector<int> rG(n);
    vector<int> rB(n);
    FOR(i,0,n){
        if(s[i] == 'R') lR[i]=1;
        if(s[i] == 'G') lG[i]=1;
        if(s[i] == 'B') lB[i]=1;        
    }
    FOR(i,1,n){
        lR[i] += lR[i-1];
        lG[i] += lG[i-1];
        lB[i] += lB[i-1];        
    }

    FORr(i,0,n-1){
        if(s[i] == 'R') rR[i]=1;
        if(s[i] == 'G') rG[i]=1;
        if(s[i] == 'B') rB[i]=1;        
    }
    FORr(i,0,n-2){
        rR[i] += rR[i+1];
        rG[i] += rG[i+1];
        rB[i] += rB[i+1];        
    }


    ll ans = 0;
    FOR(i,0,n){
        if(s[i] == 'R'){
            ans += lG[i]*rB[i];
            ans += rG[i]*lB[i];            
        }
        if(s[i] == 'G'){
            ans += lR[i]*rB[i];
            ans += rR[i]*lB[i];            
        }
        if(s[i] == 'B'){
            ans += lG[i]*rR[i];
            ans += rG[i]*lR[i];            
        }       
    }   

    FOR(dif,1,n){
        FOR(l,0,n){
            ll m,r;
            m = l + dif;
            r = m + dif;
            if(r >= n)continue;
            if(s[l] != s[m] && s[m] != s[r] && s[r] != s[l]) ans--;
        }
    }
    cout<<ans<<endl;
    

    
    
}

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

int main() {
  int a, b;
  while(1) {
    cin >> a >> b;
    if(a == 0 && b == 0)break;
    if(a < b) {
      cout << a << " " << b << endl;
    }else {
      cout << b << " " << a << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int H,R;
    cin >> H >> R;
    if(H+R > 0){
        cout<<1<<endl;
    }
    if(H+R == 0){
        cout<<0<<endl;
    }
    if(H+R < 0){
        cout<<-1<<endl;
    }
}



Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<queue>
#include<vector>

using namespace std;

struct State{
  int cur,h,w,dir;
  bool operator < (const State& st) const {
    return cur > st.cur;
  }
};

const int NORTH = 0;
const int SIZE = 1001;
const int INF = (1<<25);
int H,W,N;
int dh[] = {-1,0,1,0};
int dw[] = {0,1,0,-1};
string command;
char field[SIZE][SIZE];
int sh,sw,gh,gw;
int T[SIZE][SIZE][4];
vector<int> DIR[4];

bool isInside(int h, int w){return 0<=h&&h<H&&0<=w&&w<W;}

void input(){
  cin >> command;
  for(int i = 0; i < H; i++)
    for(int j = 0; j < W; j++){
      cin >> field[i][j];
      if(field[i][j] == 'S'){sh=i;sw=j;}
      if(field[i][j] == 'G'){gh=i;gw=j;}
    }
  for(int i = 0; i < 4; i++) DIR[i].clear();
  int d = 0;
  for(int i = 0; i < (int)command.length(); i++){
    if(command[i] == 'R') d = (d+1)%4;
    else d = (d+3)%4;
    DIR[d].push_back(i+1);
  }
}

bool solve(){
  fill(T[0][0], T[0][0]+SIZE*SIZE*4, INF);
  priority_queue<State> Q;
  Q.push((State){0,sh,sw,NORTH});
  T[sh][sw][NORTH] = 0;

  while(!Q.empty()){
    const State now = Q.top(); Q.pop();

    if(now.h == gh && now.w == gw) return true;
    if(T[now.h][now.w][now.dir] < now.cur) continue;
    
    // turn around
    State nex = now;    
    for(int i = 0; i < 4; i++){
      if(now.dir == i) continue;
      
      vector<int>::iterator ite = lower_bound(DIR[i].begin(),DIR[i].end(),now.cur);
      if(ite == DIR[i].end()) continue;
      
      nex.cur = *ite;
      nex.dir = i;
      if(T[nex.h][nex.w][nex.dir] > nex.cur){
	T[nex.h][nex.w][nex.dir] = nex.cur;
	Q.push(nex);
      }
    }
    
    // go forward
    nex = now;
    nex.h += dh[nex.dir];
    nex.w += dw[nex.dir];
    if(isInside(nex.h,nex.w) && field[nex.h][nex.w] != '#'){
      if(T[nex.h][nex.w][nex.dir] > nex.cur){
	T[nex.h][nex.w][nex.dir] = nex.cur;
	Q.push(nex);
      }
    }
  }
  return false;
}

int main(){
  while(cin >> H >> W >> N && (H|N|W)){
    input();
    cout << (solve()?"Yes":"No") << endl;
  }
  return 0;
}

Measured memory_bytes: 23692
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
  		Scanner scan = new Scanner(System.in);
  		int cnt1 = 0;
  		int cnt2 = 0;
  		for(int i = 0; i < 3; i++){
    		int num = scan.nextInt();
    		if(num == 5){
      			cnt1++;
    		}
    		else if(num == 7){
      			cnt2++;
    		}
  		}
  
  		if(cnt1 == 2 && cnt2 == 1){
    		System.out.println("YES");
  		}
  		else{
    		System.out.println("NO");
  		}
  		scan.close();
	}
}


Measured memory_bytes: 22868
#include <cstdio>
using namespace std;

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

int main() {
  size_t N, M;
  scanf("%ld%ld", &N, &M);
  int ss[N][M], ps[M];
  rep(i, N) rep(j, M) ss[i][j] = 0;
  rep(j, M) {
    size_t k;
    scanf("%ld", &k);
    rep(i, k) {
      size_t s;
      scanf("%ld", &s);
      ss[s-1][j] = 1;
    }
  }
  rep(j, M) scanf("%d", &ps[j]);
  int r = 0;
  for (int b = 0; b < (1 << N); b++) {
    int xs[M];
    rep(j, M) xs[j] = 0;
    rep(i, N)
      if ((b >> i) & 1)
        rep(j, M)
          if (ss[i][j])
            xs[j]++;
    bool f = true;
    rep(j, M)
      if (xs[j] % 2 != ps[j]) {
        f = false;
        break;
      }
    if (f)
      r++;
  }
  printf("%d\n", r);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    if (a-k<0)
    {
        /* code */
        
        b=b+(a-k);
        a=0;
        if (b<0)
        {
            /* code */
            b=0;
        }
        
    }
    else
    {
        a=a-k;
    }
    cout<<a<<" "<<b;
    
}
  

Measured memory_bytes: 256
from itertools import product

H, W = map(int,input().split())
grid = [input() for i in range(H)]
colored_grid = ['.'*W for i in range(H)] #白色であることを.、黒色であることを#で表す #問題を解くだけならば必要ない

for i,j in product(range(H),range(W)):
    if grid[i][j] == '#':
        colored_grid[i][j].replace('.','#',1) #こちらも思ったようには動作しない "....."->"..#.."にならない
        #colored_grid[i][j] = '#' 思ったように動作しない
        for x,y in product(range(-1,2),repeat=2): #x=0,y=0で自身を含むことに注意
            if abs(x) + abs(y) == 2:
                continue
            if x == 0 and y == 0:
                continue
            if 0 <= i+x <= H-1 and 0 <= j+y <= W-1 and grid[i+x][j+y] == '#': #8近傍の黒色を探す
                colored_grid[i+x][j+y].replace('.','#',1)
                break #黒色に塗れた！
        else: #黒色に塗れなかった 
            colored_grid[i][j].replace('#','.',1)
            print('No')
            break
else:
    print('Yes')


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N)
  cin >> A[i];
  ll ans = 0;
  ll sum = 0;
  REP(i, N)
  {
    if (A[i] == 0)
    {
      ans += sum / 2;
      sum = 0;
    }
    else
    {
      sum += A[i];
    }
  }
  ans += sum / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.IO;

namespace MinPro2019D
{
    public class Program
    {
        public static void Main()
        {
            Stream stream = Console.OpenStandardInput(256);
            byte[] buffer = new byte[1024];
            int index = 0;
            int length = stream.Read(buffer, 0, 1024);
            int L = 0;

            while (48 <= buffer[index] && buffer[index] <= 57)
            {
                L = L * 10 + buffer[index] - 48;
                ++index;
                if (index < length) continue;
                index = 0;
                length = stream.Read(buffer, 0, 1024);
            }

            long[] dp = new long[5];
            long A;
            long x;

            for (int i = 0; i < L; i++)
            {
                A = 0;

                while (buffer[index] < 48 || 57 < buffer[index])
                {
                    ++index;
                    if (index < length) continue;
                    index = 0;
                    length = stream.Read(buffer, 0, 1024);
                }

                while (48 <= buffer[index] && buffer[index] <= 57)
                {
                    A = A * 10 + buffer[index] - 48;
                    ++index;
                    if (index < length) continue;
                    index = 0;
                    length = stream.Read(buffer, 0, 1024);
                }

                x = A == 0 ? 2 : A & 1;

                dp[0] += A;
                dp[1] += x;
                dp[2] += (x & 1) ^ 1;
                dp[3] += x;
                dp[4] += A;
                dp[1] = Math.Min(dp[1], dp[0]);
                dp[2] = Math.Min(dp[2], dp[1]);
                dp[3] = Math.Min(dp[3], dp[2]);
                dp[4] = Math.Min(dp[4], dp[3]);
            }

            Console.WriteLine(dp[4].ToString());
        }
    }
}


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

int main(){
    int N;
    string s;
    cin >> N >> s;
    int ans = 0;
    int x = 0;
    for (int i=0; i<N; i++){
        if (s[i] == 'I'){
            x += 1;
        }
        else{
            x -= 1;
        }
        ans = max(ans, x);
    }
    cout << ans << endl;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 3e2;
int n, m, mod, dp[nsz + 5][nsz + 5], suf[nsz + 5][nsz + 5], C[nsz + 5][nsz + 5];

void inline upd(int &a, const int b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    }
}

int main() {
    scanf("%d%d%d", &n, &m, &mod);
    circ (i, 0, n) {
        C[i][0] = 1;
        cont (j, i) {
            upd(C[i][j], C[i - 1][j] + C[i - 1][j - 1]);
        }
    }
    for (int i = m; i >= 0; --i) {
        dp[1][i] = 1;
        upd(suf[1][i], suf[1][i + 1] + dp[1][i]);
    }
    circ (i, 2, n + 1) {
        for (int k = m; k >= 0; --k) {
            cont (j, i - 1) {
                upd(dp[i][k], (num) dp[i - j][k] * suf[j][k + 1] % mod * C[i - 2][j - 1] % mod);
            }
            upd(suf[i][k], suf[i][k + 1] + dp[i][k]);
        }
    }
    printf("%d\n", dp[n + 1][0]);
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; const int MAX = 1100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();

    LL n,k;
    cin>>n>>k;
    if(k>=n){cout<<COM(2*n-1,n-1)%MOD<<endl;return 0;}
    LL min[n];
    for(int i=0;i<n;i++){min[i]=(COM(n,i)*COM(n-1,i))%MOD;}
    LL ans=0;
    //for(int i=0;i<=k;i++){cout<<min[i]<<endl;}
    for(int i=0;i<=k;i++){ans=(ans+min[i])%MOD;}
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

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

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

int main()
{
	const char* names[] = {"AAA", "AA", "A", "B", "C", "D", "E", "NA"};
	double m500[] = {35.5, 37.5, 40.0, 43.0, 50.0, 55.0, 70.0};
	double m1000[] = {71.0, 77.0, 83.0, 89.0, 105.0, 116.0, 148.0};
	
	double a, b;
	while(scanf("%lf%lf", &a, &b) != EOF){
		puts(names[max(distance(m500, upper_bound(m500, m500+7, a)), distance(m1000, upper_bound(m1000, m1000+7, b)))]);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
int s_round(float *n);

int main(void) {

	int N;
	int X[100];
	int  i,P;
	int  temp;
	float  p;

	scanf("%d",&N);

    for(i=0;i<N-1;i++) scanf("%d ",&X[i]);
    scanf("%d",&X[N-1]);

    temp=0;p=0;
    for(i=0;i<N;i++) p+=X[i];
    p=p/N;
    P=s_round(&p);

    for(i=0;i<N;i++)
    	temp=temp+(X[i]-P)*(X[i]-P);

    printf("%d",temp);
    return(0);
}

// 四捨五入
int s_round(float *n)
{
	float a;

	//printf("%f",*n);
	a=*n-(int)*n;
	//printf("%f",a);
	if(a>=0.5) return((int)(*n+1));
	return((int)*n);

}



Measured memory_bytes: 128
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
vl a;
vl b;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    a = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
    b = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> b[i];
    }
    solve();
}

// 1 <= N <= 50
// 0 <= a_{i}, b_{i} <= 50
// 入力中の値はすべて整数である。

const ll MX=51;

bool f(vl &c){
    ll n=c.size();
    vvl g(MX,vl(MX,INF));
    rep(i,MX)g[i][i]=0;
    rep(i,MX)rep(j,n)g[i][i%c[j]]=0;
    rep(i,MX)rep(j,MX)rep(k,MX){
        chmin(g[j][k],g[j][i]+g[i][k]);
    }
    rep(i,N){
        if(g[a[i]][b[i]])return false;
    }
    return true;
}

// ll N, vl a, vl b
// はじめの数列を b_{1}, b_{2}, ..., b_{N} に変えるのに必要な最小のコストを出力せよ。目的の達成が不可能である場合は、代わりに -1 と出力せよ。
void solve(){
    vl ng(MX+1);
    ll ans=0;
    rrep(i,MX+1){
        if(!i)continue;
        vl c;
        rep(j,1,MX){
            if(!ng[j]&&j!=i)c.push_back(j);
        }
        ng[i]=f(c);
        if(!ng[i])ans+=1LL<<i;
    }
    cout<<(ans>=1LL<<MX?-1:ans)<<endl;
}


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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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; }

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll n,k,q; cin>>n>>k>>q;
    vint a(n); rep(i,n) cin>>a[i];

    ll ans = LLONG_MAX;
    rep(i,n){
        // cout<<"i: "<<i<<endl;
        vvint s;
        s.emplace_back();
        rep(j,n){
            if(a[j] >= a[i]){
                s.back().emplace_back(a[j]);
            }else{
                s.emplace_back();
            }
        }
        vint arr;
        rep(j,s.size()){
            sort(ALL(s[j]));
            ll c = (ll)(s[j].size()) - k + 1;
            rep(l, c) arr.emplace_back(s[j][l]);
        }
        if(arr.size() < q) continue;
        sort(ALL(arr));
        // printv(arr);
        chmin(ans, arr[q-1] - a[i]);
    }
    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 512
import math
pi = math.pi

a,b,h,m = map(int, input().split())
th_m = m*2*pi/60
th_h = (60*h + m)*2*pi/720

mx = math.cos(th_m)*b
my = math.sin(th_m)*b
hx = math.cos(th_h)*a
hy = math.sin(th_h)*a

dis = math.sqrt((mx-hx)**2 + (my-hy)**2)
print(dis)


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

int main() {
  string s;
  cin >> s;

  sort(s.begin(), s.end());
  if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
int arr[maxn];
int M(){
    int n;
    if(!~scanf("%d", &n)) return 0;
    int qtd4 = 0, qtd2 = 0;
    for(int e = 0; e < n; e++){
        scanf("%d", arr + e);
        qtd4 += arr[e] % 4 == 0;
        if(arr[e] % 4 != 0){
            if(arr[e] % 2 == 0)
                qtd2 += 1;
        }
    }
    if(qtd4 >= n/2) printf("Yes\n");
    else if((n - qtd4*2) <= qtd2) printf("Yes\n");
    else printf("No\n");
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int N,K,R,S,P; string T; cin >> N >> K >> R >> S >> P>>T;

    int score = 0;

    int now = 0;
    veb flag(N,true);

    while(now < K) {
        if(T[now] == 'p') score += S;
        if(T[now] == 'r') score += P;
        if(T[now] == 's') score += R;
        now++;
        //cout << score << endl;
    }
    while(now < N) {
        if(T[now-K] == 'p') {
            if(T[now] == 'r') score += P;
            if(T[now] == 's') score += R;
            if(T[now] == 'p') {
                if(flag[now-K]) flag[now] = false;
                else score += S;
            }
            
        }
        if(T[now-K] == 'r') {
            if(T[now] == 'p') score += S;
            if(T[now] == 's') score += R;
            if(T[now] == 'r') {
                if(flag[now-K]) flag[now] = false;
                else score += P;
            }
        }
        if(T[now-K] == 's') {
            if(T[now] == 'r') score += P; 
            if(T[now] == 'p') score += S; 
            if(T[now] == 's') {
                if(flag[now-K]) flag[now] = false;
                else score += R;
            }
        }
        //cout << score << endl;
        now++;
    }
    cout << score << endl;

}

Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CWalkingTakahashi {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll x, k, d; cin >> x >> k >> d;
      __uint128_t x2 = x;
      __uint128_t k2 = k;
      __uint128_t d2 = d;



      if (abs(x) >= k2*d2) {
        if (x > 0) {
          cout << x - k*d << endl;
          return;
        } else {
          cout << abs(x + k*d) << endl;
          return;
        }
      }

      bool isxpositive = true;
      if (x < 0) {
        isxpositive = false;
        x = abs(x);
      }

      ll p = x/d;
      x -= d*p;
      k -= p;

      if (k%2 != 0) {
        x -= d;
      }
      if (!isxpositive) {
        x = -x;
      }
      cout << abs(x) << endl;





    }
};

signed main() {
  CWalkingTakahashi solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<int> a(12);
    for (auto &&i : a) scanf("%d", &i);
    sort(a.begin(),a.end());
    if(a[0] == a[3] && a[4] == a[7] && a[8] == a[11]) puts("yes");
    else puts("no");
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>                          
using namespace std;
long long x,y,ans=1;
int main(){
    cin>>x>>y;
    while(x*2<=y)
    {
    	x*=2;
    	ans++;
	}
	cout<<ans;
	return 0;
}
//68871358
//76140264
//25446011
//200841159
//914174775

Measured memory_bytes: 256