akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ABC139B
{
    static class Program
    {
        static void Main()
        {
            Console.ReadLine();
            int[] nbrs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            double res = 0;
            double coordinate = 0;

            for(int i = 0; i < nbrs.Length; i++)
            {
                coordinate += nbrs[i];
            }

            coordinate = Math.Round(coordinate / nbrs.Length, 0);

            for (int i = 0; i < nbrs.Length; i++) {
                res += Stamina(nbrs[i], coordinate);
            }

            
            Console.WriteLine(res);
        }

        private static double Stamina(int X, double P)
        {
            return Math.Pow(X - P, 2);
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int n,m;
int k[15];
int s[15][15];
int p[15];
bool use[15];
int cnt=0;
void dfs(int x,int y,int z){
	if(x==z){
		bool ok=true;
		for(int i=0;i<m;i++){
			int ans=0;
			for(int j=0;j<k[i];j++){
				if(use[s[i][j]-1]){
					ans++;
				}
			}
			int ans2=ans%2;
			if(ans2!=p[i])ok=false;
		}
		if(ok){
			cnt++;
		}
		return ;
	}
	if(y==n)return ;
	dfs(x,y+1,z);
	use[y]=true;
	dfs(x+1,y+1,z);
	use[y]=false;
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>k[i];
		for(int j=0;j<k[i];j++){
			cin>>s[i][j];
		}
	}
	for(int i=0;i<m;i++)cin>>p[i];
	for(int i=0;i<=n;i++){
		memset(use,false,sizeof(use));
		dfs(0,0,i);
	}
	cout<<cnt<<endl;
	return 0;
}

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

class SA{
public:
  string S;
  int n;
  vector<int> sa;
  
  SA():n(-1){}
  SA(string S):S(S),n(S.size()),sa(n){  
    vector<int> rnk(n);
    vector<int> tmp(n);
    for(int i=0;i<n;i++) sa[i]=i;
    for(int i=0;i<n;i++) rnk[i] = S[i];
    
    //k文字についてソートされているところから、2k文字でソート
    for(int Len=1;Len<=n;Len*=2){
      
      //(rnk[i],rnk[i+k])と(rnk[j],rnk[j+k])を比較
      auto compare_sa=[&](const int &i,const int &j){
        if(rnk[i]!=rnk[j])return rnk[i]<rnk[j];
        int ri=i+Len<=n?rnk[i+Len]:-1;
        int rj=j+Len<=n?rnk[j+Len]:-1;
        return ri<rj;
      };
      
      sort(sa.begin(),sa.end(),compare_sa);

      //いったんtmpに次のランクを計算して、rnkに代入
      for(int i=1;i<n;i++)
        tmp[sa[i]] = tmp[sa[i-1]] + compare_sa(sa[i-1],sa[i]);
      rnk = tmp;
    }
  }

  int lower_bound(string T){
    assert(n >= 0);
    int L=-1,R=S.length();
    while(L+1<R){
      int M = (L+R)/2;
      S.compare(sa[M],T.size(),T)<0? L = M:R = M;
    }
    return R;
  } 

  int upper_bound(string T){return lower_bound(T+char('z'+ 1));} 
  int count(string T){return upper_bound(T) - lower_bound(T);};
};

int main(){
  string s;
  cin>>s;
  SA sa(s);
  
  int q;
  cin>>q;
  while(q--){
    string t;
    cin>>t;
    int ans = sa.count(t) != 0;
    printf("%d\n",ans);
  }
  
}



Measured memory_bytes: 16648
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
double check(double xa,double ya,double xb,double yb,double xc,double yc);
int main(void){
    double qxa,qya,qxb,qyb,qxc,qyc,qxp,qyp;
	while(cin>>qxa){

	    cin>>qya>>qxb>>qyb>>qxc>>qyc>>qxp>>qyp;
	    double abc,abp,bcp,cap;
	    abc=check(qxa,qya,qxb,qyb,qxc,qyc);
	    abp=check(qxa,qya,qxb,qyb,qxp,qyp);
        bcp=check(qxb,qyb,qxc,qyc,qxp,qyp);
        cap=check(qxc,qyc,qxa,qya,qxp,qyp);

        double var=abc-(abp+bcp+cap);
        if(var<=0.01&&var>=-0.01)var=0.0;
        if(var==0.0)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;


	}
	return 0;
}


double check(double xa,double ya,double xb,double yb,double xc,double yc){

    double ab,bc,ca;
    double S,s;
    ab=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
    bc=sqrt((xb-xc)*(xb-xc)+(yb-yc)*(yb-yc));
    ca=sqrt((xc-xa)*(xc-xa)+(yc-ya)*(yc-ya));
    s=0.5*(ab+bc+ca);
    S=sqrt(s*(s-ab)*(s-bc)*(s-ca));
    //cout<<S<<endl;
    return S;


}

Measured memory_bytes: 1216
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	string S; cin >> S;
	ll n = S.size()-1;
	if (S[n] == '2' || S[n] == '4' || S[n] == '5' || S[n] == '7' || S[n] == '9') {
		cout << "hon" << endl;
	}
	else if (S[n] == '0' || S[n] == '1' || S[n] == '6' || S[n] == '8') {
		cout << "pon" << endl;
	}
	else {
		cout << "bon" << endl;
	}
}

Measured memory_bytes: 11012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    if(B - A == C - B) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

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

using namespace std;


int main()
{
   
   long long int n,k,ans;
   scanf("%lld%lld",&n,&k);
   if(n%k==0)
      printf("0");
      
    else if(n<=k)
       printf("%lld",min(n,abs(n-k)));
       
    else
      {
          ans=n/k;
          n=n-ans*k;
          
          printf("%lld",min(n,abs(n-k)));
      }
      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

template<typename T>
struct Sum_2D{
  vector<vector<T>>cul;
  bool flag;
  Sum_2D(int h,int w):cul(h+1,vector<T>(w+1)){
    flag=false;
  }

  void add(int x,int y,T val){//0インデックス
    ++x;++y;
    if(x>=cul.size()||y>=cul[0].size())return;
    cul[x][y]+=val;
  }

  void build(){
    flag=true;
    for(int i=1;i<cul.size();++i){
      for(int j=1;j<cul[i].size();++j){
        cul[i][j]+=cul[i][j-1]+cul[i-1][j]-cul[i-1][j-1];
      }
    }
  }

  T query(int lb_x,int lb_y,int ub_x,int ub_y){
    //lb_x,lb_y:左下(含む),ub_x,ub_y:右上(含まない)
    //0インデックスに直す
    assert(flag==true);
    return cul[ub_x][ub_y]-cul[ub_x][lb_y]-cul[lb_x][ub_y]+cul[lb_x][lb_y];
  }
};


void solve()
{
	ll h,w,k;
	cin>>h>>w>>k;
	vector<string>c(h);
	rep(i,h){
		cin>>c[i];
	}
	ll ans=0;
	rep(bit,1<<h){
		rep(bit2,1<<w){
			vector<bool>ng(h),ng2(w);
			rep(i,h){
				if(bit&(1<<i))ng[i]=true;
			}
			rep(i,w){
				if(bit2&(1<<i))ng2[i]=true;
			}
			int cnt=0;
			rep(i,h){
				rep(j,w){
					if(ng[i]||ng2[j])continue;
					if(c[i][j]=='#')++cnt;
				}
			}
			if(cnt==k)++ans;
		}
	}
	cout<<ans;
}

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


Measured memory_bytes: 3656
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let t: usize = sc.cin();

    let mut xs = vec![0; n];
    for i in 0..n {
        let x: i64 = sc.cin();
        xs[i] = x;
    }

    let mut mn = xs[0];
    let mut mx = xs[1] - xs[0];
    for i in 1..n {
        if xs[i] - mn > mx {
            mx = xs[i] - mn;
        }
        mn = min(mn, xs[i]);
    }
    trace!(mx);

    let mut ans = 0;
    let mut mn = xs[0];
    for i in 1..n {
        mn = min(mn, xs[i]);
        if xs[i] - mn == mx {
            ans += 1;
        }
    }


    println!("{}", ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}


Measured memory_bytes: 7676
from bisect import bisect_left

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

# print(A)
# print(B)
# print(C)

A_B = []

for i in range(n):
    A_B.append(bisect_left(A, B[i]))

ruisekiwa = [A_B[0]]
for i in range(1, n):
    ruisekiwa.append(ruisekiwa[-1] + A_B[i])

# print(A_B)
# print(ruisekiwa)

ans = 0

for i in range(n):
    idx = bisect_left(B, C[i])
    if idx:
        ans += ruisekiwa[idx-1]

print(ans)

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

int main(){
    int h,w,ans;
    cin >> h >> w;
    vector<vector<char>> MAP(h,vector<char>(w));
    ans = 0;
    int L[h][w];
    int R[h][w];
    int U[h][w];
    int D[h][w];
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            cin >> MAP[i][j];
            L[i][j] = 0;
            R[i][j] = 0;
            U[i][j] = 0;
            D[i][j] = 0;
        }
    }
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(j == 0 && MAP[i][j] == '.')L[i][j] = 1;
            else if(MAP[i][j] == '.')L[i][j] = L[i][j-1] + 1;
        }
    }
    for(int i = 0;i < h;i++){
        for(int j = w-1;j >= 0;j--){
            if(j == w-1 && MAP[i][j] == '.')R[i][j] = 1;
            else if(MAP[i][j] == '.')R[i][j] = R[i][j+1] + 1;
        }
    }
    for(int i = 0;i < w;i++){
        for(int j = 0;j < h;j++){
            if(j == 0 && MAP[j][i] == '.')U[j][i] = 1;
            else if(MAP[j][i] == '.')U[j][i] = U[j-1][i] + 1;
        }
    }
    for(int i = 0;i < w;i++){
        for(int j = h-1;j >= 0;j--){
            if(j == h-1 && MAP[j][i] == '.')D[j][i] = 1;
            else if(MAP[j][i] == '.')D[j][i] = D[j+1][i] + 1;
        }
    }
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(MAP[i][j] == '.'){
                ans = max(L[i][j] + R[i][j] + U[i][j] + D[i][j] -3,ans);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 66688
midScore =[0]*50
finScore = [0]*50
reScore = [0]*50
personNum = 0
while True:
    m,f,r = map(int,input().split())
    midScore[personNum] = m
    finScore[personNum] = f
    reScore[personNum] = r
    personNum += 1
    if m is f is r is -1:
        break
    
    
for person in range(personNum):
    totalScore = midScore[person] + finScore[person]
    if midScore[person] is finScore[person] is reScore[person] is -1:
        pass
    elif midScore[person] == -1 or finScore[person] == -1:
        print("F")
    elif 80<=totalScore:
        print("A")
    elif 65<=totalScore<80:
        print("B")
    elif 50<=totalScore<65:
        print("C")
    elif 30<=totalScore<50:
        if 50<=reScore[person]:
            print("C")
        else:
            print("D")
    elif totalScore<30:
        print("F")


Measured memory_bytes: 5608
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,num;
    scanf("%d",&n);
    num=n%10;
    if(num==2||num==5||num==4||num==7||num==9)
        printf("hon\n");
    else if(num==0||num==1||num==6||num==8)
        printf("pon\n");
    else
        printf("bon\n");

    return 0;
}


Measured memory_bytes: 1648
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N; cin >> N;
    set<ll> s; s.insert(-1); s.insert(N);
    vl as(N+1, 0);
    REP(i, N){
        ll a; cin >> a; as[a] = i;
    }
    ll ans = 0;
    FOR(i, 1, N+1){
        ll idx = as[i];
        auto rit = s.upper_bound(idx);
        auto lit = rit; lit--;
        ll r = *rit, l = *lit;
        ll rcnt = r-idx-1;
        ll lcnt = idx-l-1;
        ll tot = rcnt*lcnt+rcnt+lcnt+1;
        ans += i*tot;
        s.insert(idx);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

                    
using ll = long long;
using ull = unsigned long long;
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; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;
    
    if (S == U) A--;
    if (T == U) B--;
    cout << A << " " << B << endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>

using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX], n;

	cin >> n;
	for (int i = 0;i < n;i++)cin >> R[i];
	int maxv = -2000000000;
	int minv = R[0];

	for (int i = 1;i < n;i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;

	return 0;
}


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

const int MAX=10005;
int state[MAX],N,D[MAX];
vector<pair<int,int>> S[MAX];
priority_queue<pair<int,int>> Q;

void dijkstra(){
    int cnt=1;
    for(int i=0;i<N;i++){
        state[i]=0;
        D[i]=10000000;
    }
    state[0]=1;
    D[0]=0;
    for(int i=0;i<S[0].size();i++){
        Q.push(make_pair(-S[0][i].second,S[0][i].first));
        D[S[0][i].first]=min(D[S[0][i].first],D[0]+S[0][i].second);
    }
    while(1){
        int a=Q.top().second;
            if(state[a]==0){
            Q.pop();
            state[a]=1;
            for(int i=0;i<S[a].size();i++){
                if(state[S[a][i].first]==0){
                    Q.push(make_pair(-(D[a]+S[a][i].second),S[a][i].first));
                    D[S[a][i].first]=min(D[S[a][i].first],D[a]+S[a][i].second);
                }
            }
                cnt++;
        }
        else Q.pop();
        if(cnt==N) break;
    }
    return;
}


int main(){
    
    cin>>N;
    for(int i=0;i<N;i++){
        int l,a;cin>>l>>a;
        for(int j=0;j<a;j++){
            int b,c;cin>>b>>c;
            S[i].push_back(make_pair(b,c));
        }
    }
    dijkstra();
    for(int i=0;i<N;i++){
        cout<<i<<" "<<D[i]<<endl;
    }
}



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

int main() {
   long A, B, K;
   cin >> A >> B >> K;
   
   if(K >= A + B) {
      cout << 0 << " " << 0 << endl;
   }
   else if(K >= A) {
      cout << 0 << " " << B - (K - A) << endl;
   }
   else {
      cout << A - K << " " << B << endl;
   }
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>V[2];
    V[0].resize(2*n);V[1].resize(2*n);
    for(int i=0;i<2*n;i++)V[0][i]=i+1;
    for(int i=1;i<=m;i++){
        int k;
        cin>>k;
        if(k==0){
            for(int j=0;j<n;j++){
                V[i&1][j*2]=V[(i+1)&1][j];
                V[i&1][j*2+1]=V[(i+1)&1][n+j];
            }
        }
        else{
            for(int j=0;j<2*n-k;j++){
                V[i&1][j]=V[(i+1)&1][j+k];
            }
            for(int j=2*n-k;j<2*n;j++){
                V[i&1][j]=V[(i+1)&1][j-2*n+k];
            }
        }
    }
    for(int i=0;i<2*n;i++)cout<<V[m&1][i]<<endl;
}

Measured memory_bytes: 1200
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sn = new Scanner(System.in);
        int x = Integer.parseInt(sn.next());
        int y = Integer.parseInt(sn.next());
		for( int i =0; i <= x ; i++ ){
            int t = 2 * i;
            int k = 4 * (x - i);
			if (t + k == y ){
                System.out.println("Yes");
                return;
			}
		}
        System.out.println("No");
	}
}



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

int main(){
	int n, x; cin >> n >> x;
	if(n == 1){
		cout << "Yes\n1\n";
	}else if(n == 2){
		cout << (x == 2 ? "Yes\n1\n2\n3\n": "No\n");
	}else if(x == 1 || x == 2 * n - 1){
		cout << "No\n";
	}else{
		cout << "Yes\n";
		vector<int> v(2 * n);
		for(int i = 1; i <= 2 * n - 1; ++i) v[i] = i;
		int yo[4] = {1, x, 2 * n - 1, 2};
		if(x == 2){
			yo[0] = 2 * n - 1;
			yo[1] = 2;
			yo[2] = 1;
			yo[3] = 2 * n - 2;
		}
		for(int i = 0; i < 4; ++i) v[yo[i]] = 0;
		for(int i = 1; i < v.size(); ++i){
			if(!v[i]) v.erase(v.begin() + i--);
		}
		for(int i = 0; i < 4; ++i) v.insert(v.begin() + n - 1 + i, yo[i]);
		for(int i = 1; i <= 2 * n - 1; ++i) cout << v[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 2304
import java.util.Scanner;


class Main
{ 
	int st[]; 
	int minVal(int x, int y) { 
		return (x < y) ? x : y; 
	} 

	 
	int getMid(int s, int e) { 
		return s + (e - s) / 2; 
	} 

	
	int RMQUtil(int ss, int se, int qs, int qe, int index) 
	{ 
		 
		if (qs <= ss && qe >= se) 
			return st[index]; 

		
		if (se < qs || ss > qe) 
			return Integer.MAX_VALUE; 

		 
		int mid = getMid(ss, se); 
		return minVal(RMQUtil(ss, mid, qs, qe, 2 * index + 1), 
				RMQUtil(mid + 1, se, qs, qe, 2 * index + 2)); 
	} 

	
	int RMQ(int n, int qs, int qe) 
	{ 
		
		if (qs < 0 || qe > n - 1 || qs > qe) { 
			System.out.println("Invalid Input"); 
			return -1; 
		} 

		return RMQUtil(0, n - 1, qs, qe, 0); 
	} 

	
	int constructSTUtil(int arr[], int ss, int se, int si) 
	{ 
		
		if (ss == se) { 
			st[si] = arr[ss]; 
			return arr[ss]; 
		} 

		
		int mid = getMid(ss, se); 
		st[si] = minVal(constructSTUtil(arr, ss, mid, si * 2 + 1), 
				constructSTUtil(arr, mid + 1, se, si * 2 + 2)); 
		return st[si]; 
	} 

	
	void constructST(int arr[], int n) 
	{ 
		 
		int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); 

		
		int max_size = 2 * (int) Math.pow(2, x) - 1; 
		st = new int[max_size]; 

		 
		constructSTUtil(arr, 0, n - 1, 0); 
	} 

	 
	public static void main(String args[]) 
	{ 
		
		
		Scanner sc = new Scanner(System.in);
		String N = sc.next(); 
		String slide = sc.next();
		Main tree = new Main();
		int arr[] = new int[Integer.parseInt(N)];
		for(int i=0; i<Integer.parseInt(N); i++)
		{
			arr[i] = Integer.parseInt(sc.next());
		}
		
		tree.constructST(arr, Integer.parseInt(N));
		
		for(int i=0;i<=Integer.parseInt(N) - Integer.parseInt(slide);i++) {
			int result=tree.RMQ(Integer.parseInt(N), i, i+Integer.parseInt(slide)-1);
			if(i != (Integer.parseInt(N) - Integer.parseInt(slide))){
					System.out.print(result+" ");
				}else{
					System.out.println(result);
				}
		}
	} 
} 
 





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

int main() {
  int w, last = 4280;

  while(cin >> w, w != -1) {
    int ans = 1150;
    while(w != 0) {
      if(w > 30) {
	ans += 160 * (w-30);
	w = 30;
      }
      else if(w > 20) {
	ans += 140 * (w-20);
	w = 20;
      }
      else if(w > 10) {
	ans += 125 * (w-10);
	w = 10;
      }
      else w = 0;   
    }
    cout << last - ans << endl;
  }
}

Measured memory_bytes: 1160
use std::collections::HashMap;

fn main() {
    proconio::input! {
        n: usize,
        mut sc: [(String, u64); n],
    }

//    let mut nsc = Vec::new();
    let mut rev = Vec::new();
    let mut cost = u64::max_value();
//    for (s, c) in sc {
//        let r = s.chars().rev().collect::<String>();
//        if s == r {
//            cost = cost.min(c);
//        } else {
//            nsc.push((s, c));
//            rev.push(r);
//        }
//    }
    let sc: Vec<_> = sc
        .iter()
        .filter(|e| {
            let r = e.0.chars().rev().collect::<String>();
            let f = e.0 != r;
            if f {
                rev.push(r);
            } else {
                cost = cost.min(e.1);
            }
            f
        })
        .collect();
    let n = sc.len();
    for i in 0..n {
        let mut solver = Solver::new(n, &sc, &rev);
        cost = cost.min(solver.calc(sc[i].0.as_str(), sc[i].1, true));
    }

    if cost < u64::max_value() {
        println!("{}", cost);
    } else {
        println!("-1");
    }
}

struct Solver<'a> {
    done: HashMap<(&'a str, bool), u64>,
    n: usize,
    sc: &'a Vec<&'a (String, u64)>,
    rev: &'a Vec<String>,
}

impl<'a> Solver<'a> {
    fn new(n: usize, sc: &'a Vec<&'a (String, u64)>, rev: &'a Vec<String>) -> Solver<'a> {
        Solver {
            done: HashMap::new(),
            n: n,
            sc: sc,
            rev: rev,
        }
    }

    fn calc(&mut self, s: &'a str, cost: u64, is_left: bool) -> u64 {
        let mut v = u64::max_value();
        if if let Some(&c) = self.done.get(&(s, is_left)) { cost >= c } else { false } {
            v
        } else {
            self.done.insert((s, is_left), cost);
            for i in 0..self.n {
                let oppo = if is_left { &self.rev[i] } else { &self.sc[i].0 };
                let next = if s.starts_with(oppo) {
                    Some((&s[oppo.len()..], is_left))
                } else if oppo.starts_with(&s) {
                    Some((&oppo[s.len()..], !is_left))
                } else {
                    None
                };
                if let Some((next, is_left)) = next {
                    let cost = cost + self.sc[i].1;
                    v = v.min(if next == next.chars().rev().collect::<String>() {
                        cost
                    } else {
                        self.calc(next, cost, is_left)
                    });
                }
            }
            v
        }
    }
}


Measured memory_bytes: 2212
#include <iostream>
#include <stdio.h>
#include <vector>
#include <functional>
#include <unordered_set>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

const int N = 3e3 + 10;
int dp[N][N];

void relax(int& a, int b) {
	a = max(a, b);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s, t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= m; ++j) {
			if (s[i] == t[j]) {
				relax(dp[i + 1][j + 1], dp[i][j] + 1);
			}
			relax(dp[i + 1][j], dp[i][j]);
			relax(dp[i][j + 1], dp[i][j]);
		}
	}
	string ans;
	int x = n, y = m;
	while (x && y) {
		if (s[x - 1] == t[y - 1]) {
			ans.push_back(s[x - 1]);
			--x;
			--y;
			continue;
		}
		if (dp[x][y] == dp[x - 1][y]) {
			--x;
		} else {
			--y;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}

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

int main() {
 int N;
 cin >> N;
  
  if (N % 10 == 9 ){
   cout << "Yes" << endl;
  }
  else if (N / 10 >= 9) {
   cout << "Yes" << endl;
  }
  else{
   cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    if s in ['a', 'e', 'i', 'o', 'u']:
        print('vowel')
    else:
        print('consonant')

solve()


Measured memory_bytes: 3064
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

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


int main()
{
  ll n;
  cin >> n;
  ll power = 1;

  for (ll i = 1; i <= n; i++)
  {
    power *= i;
    power %= 1000000007;
  }
  cout << power << endl;

}


Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	boolean isLeap(int y) {

		if (y % 400 == 0)

			return true;

		if (y % 100 == 0)

			return false;

		if (y % 4 == 0)

			return true;

		return false;

	}



	void run() {

		boolean first = true;

		for (;;) {

			int start = sc.nextInt();

			int end = sc.nextInt();

			if ((start | end) == 0)

				break;

			if (!first) {

				System.out.println();

			}

			first = false;

			int count = 0;

			for (int i = start; i <= end; i++) {

				if (isLeap(i)) {

					System.out.println(i);

					count++;

				}

			}

			if (count == 0)

				System.out.println("NA");

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
#include<array>
#include<algorithm>
#include<queue>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
#include<bitset>
#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}
//long nHr(int n,int r) {
//	n = n + r - 1;
//	return nCr(n,r);
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI A, B;
	cin >> A >> B;
	if ((A+B)%2 == 0) {
		cout << (A + B) / 2 << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;

const int INF=1e5+1;

bool cmp(pair<int, int> x, pair<int, int> y) {
    return x.second > y.second;
}

int main() {
    int N;
    cin >> N;
    map<int, int>mpe;
    map<int, int>mpo;
    for(int n=0; n<N; n++) {
        int v;
        cin >> v;
        if(n%2) {
            mpe[v]++;
        } else {
            mpo[v]++;
        }
    }
    
    vector<pair<int, int> > vo;
    vector<pair<int, int> > ve;
    for(auto itr=mpo.begin(); itr!=mpo.end(); itr++) {
        vo.push_back(make_pair(itr->first, itr->second));
    }
    for(auto itr=mpe.begin(); itr!=mpe.end(); itr++) {
        ve.push_back(make_pair(itr->first, itr->second));
    }
    
    sort(vo.begin(), vo.end(), cmp);
    sort(ve.begin(), ve.end(), cmp);

    if(vo[0].first!=ve[0].first) {
        cout << N-vo[0].second-ve[0].second << endl;
    } else {
        if(vo.size()>1 && ve.size()>1) {
            if(vo[1].second>ve[1].second) {
                cout << N-vo[1].second-ve[0].second << endl;
            } else {
                cout << N-vo[0].second-ve[1].second << endl;
            }
        } else if(vo.size()==1 && ve.size()==1) {
            cout << N-vo[0].second << endl;
        } else {
            if(vo.size()>1) {
                cout << N-vo[1].second-ve[0].second << endl;
            } else {
                cout << N-vo[0].second-ve[1].second << endl;
            }
        }
    }


    return 0;
    
}

Measured memory_bytes: 6136
h,w=map(int,input().split())
a=[input()for _ in range(h)]
dp=[[0]*w for _ in range(h)]
dp[0][0]=1
for i in range(h):
    for j in range(w):
        if i>0 and a[i-1][j]!='#':
            dp[i][j]+=dp[i-1][j]
        if j>0 and a[i][j-1]!='#':
            dp[i][j]+=dp[i][j-1]
        dp[i][j]=dp[i][j]%(10**9+7)
print(dp[-1][-1])

Measured memory_bytes: 43668
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,M,a[200000];
bool can(int m){
	int p=2;
	int L,R;
	bool l=0,r=0;
	for(L=N-1;L>=0;L--){
		bool b=(a[L]<=m);
		if(p==b){
			l=p;
			break;
		}
		p=b;
		if(L==0){
			if(b) L=-2;
			else L=-1;
			break;
		}
	}
	p=2;
	for(R=N-1;R<M;R++){
		bool b=(a[R]<=m);
		if(p==b){
			r=p;
			break;
		}
		p=b;
		if(R==M-1){
			if(b) R=M+1;
			else R=M;
			break;
		}
	}
	if(!l && !r){
		if(L==-2 && R==M+1) return 1;
		return 0;
	}
	if(l^r){
		return (((N-1)-L)>(R-(N-1)))^l;
	}
	return 1;
}
int main(){
	cin>>N;
	M=N*2-1;
	rep(i,M) cin>>a[i];
	int ub=M,lb=0;
	while(ub-lb>1){
		int m=(ub+lb)/2;
		if(can(m)) ub=m;
		else lb=m;
	}
	cout<<ub<<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

import javax.sound.midi.Track;

public class Main
{

	public static void main(String[] args)
	{
		boolean[][] card = new boolean[5][14];
		for (int i = 0; i < card.length; i++)
		{
			for (int j = 0; j < card[i].length; j++)
			{
				card[i][j] = false;
			}
		}
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String c;
		int m;

		for (int i = 1; i <= n; i++)
		{
			c = in.next();
			m = in.nextInt();
			switch (c.charAt(0))
			{
			case 'S':
				card[1][m] = true;
				break;
			case 'H':
				card[2][m] = true;
				break;
			case 'C':
				card[3][m] = true;
				break;
			case 'D':
				card[4][m] = true;
				break;
			default:
				System.out.println("?????????");
				break;
			}

		}
		
		//System.out.println("????§? \n");

		for (int i = 1; i < card.length; i++)
		{
			for (int j = 1; j < card[i].length; j++)
			{
				if (card[i][j] == false)
				{
					switch (i)
					{
					case 1:
						System.out.println("S " + (j));
						break;
					case 2:
						System.out.println("H " + (j));
						break;
					case 3:
						System.out.println("C " + (j));
						break;
					case 4:
						System.out.println("D " + (j));
						break;

					default:
						break;
					}
					
				}
			}
		}

	}
}

Measured memory_bytes: 26424
#include <stdio.h>
int main(){

  int i,n;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    if(i%3==0){
      printf(" %d",i);
    }
    else if(i%10==3){
      printf(" %d",i);
    }
    else if((i/10)%10==3){
      printf(" %d",i);
    }
    else if((i/100)%10==3){
      printf(" %d",i);
    }
    else if((i/1000)%10==3){
      printf(" %d",i);
    }
    else continue;
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();

    if(B<=A){
      System.out.println("delicious");
    }else if (B<=(A+X)) {
      System.out.println("safe");
    }else{
      System.out.println("dangerous");
    }

  }
}


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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

bool dfs(int n, int sum) {
	if (sum == n)
		return true;
	if (sum > n)
		return false;
	bool ret;
	int cake[2] = {4, 7};
	rep (i, 2) {
		ret = dfs(n, sum + cake[i]);
		if (ret)
			return ret;
	}
	return false;
}

int main()
{
	int n;
	cin >> n;
	if (dfs(n, 0))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n; cin >> n;
    ll ee=0,odd=0;
    for(int i=0;i<n;i++){
        ll a; cin >> a;
        if(a%2 == 1) odd++;
        if(a%4 == 0) ee++;
    }

    bool ok = false;
    if(n%2 == 1  and  odd <= ee+1) ok = true;
    if(n%2 == 0  and  odd <= ee)   ok = true;

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,k;
ll func(ll a){
	if(a < 0) return 0;
	return (a/k)+1;
}
int main(){
	cin >> n >> k;
	ll cnt = 0;
	repn(i,k){
		if( (2*i)%k != 0 ) continue;
		int j = (i==k?k:k-i);
		cnt += func(n-i)*func(n-i)*func(n-j);
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right; sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, k = wi()


for i in range(1, n + 1):
    p = 0
    while i * 2 ** p < k:
        p += 1
    ans += (1/n) * (1/2)**p

print(ans)

Measured memory_bytes: 67052
#include<cstdio>
#define maxn 55 
char s[maxn][maxn];
char x[maxn][maxn];
int main()
{
	int m,n,i,j,cnt;
	scanf("%d %d",&m,&n);
	getchar();
	for(i=0;i<m;i++)
	   {for(j=0;j<n;j++)
	   {
	   	  s[i][j]=getchar();
	   	  
	   }
	   getchar();
	   }
	for(i=0;i<m;i++)
	   for(j=0;j<n;j++)
	   {
	   	if(s[i][j]!='#')
	   	{
	   		if(i>=1&&j>=1)
	   		  {if(s[i-1][j-1]=='#')
	   		   cnt++;
				 }
	   		if(i>=1)
	   		   {if(s[i-1][j]=='#')
	   		   cnt++;
				 }
	   		if(i>=1&&j<=(n-2))
	   		   {if(s[i-1][j+1]=='#')
	   		   cnt++;
				 }
	   		if(j>=1)
	   		   {if(s[i][j-1]=='#')
	   		   cnt++;
				 }
	   		if(j<=(n-2))
	   		   {if(s[i][j+1]=='#')
	   		   cnt++;
				 }
	   		if(i<=(m-2)&&j>=1)
	   		   {if(s[i+1][j-1]=='#')
	   		   cnt++;
				 }
	   		if(i<=(m-2))
	   		   {if(s[i+1][j]=='#')
	   		   cnt++;
				 }
	   		if(i<=(m-2)&&j<=(n-2))
	   		    {if(s[i+1][j+1]=='#')
	   		   cnt++;
				 }
	   		x[i][j]=cnt+'0';
	   		cnt=0;
		   }
		if(s[i][j]=='#')
		{
			x[i][j]='#';
		}
	   }
	for(i=0;i<m;i++)
	   {for(j=0;j<n;j++)
	   {
	   	 putchar(x[i][j]);
	   }
	   printf("\n");
	   }
	return 0;
 } 

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	brick := make([]int, n)
	for i := range brick {
		brick[i] = nextInt()
	}
	//左から順に1を探し、見つかったら2を探し...を繰り返す
	satisfaction, destroy := 0, 0
	for i := 0; i < n; i++ {
		if brick[i] == satisfaction+1 {
			satisfaction++
		} else {
			destroy++
		}
	}
	if satisfaction == 0 {
		destroy = -1
	}
	fmt.Println(destroy)
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define MAX 100002
using namespace std;

int main()
{
  string s;
  long long O[MAX]={},CO[MAX]={},I[MAX]={},CI[MAX]={};
  int n,numI[MAX]={};

  cin>>n;
  cin>>s;

  long long count=0,count1=1,ans=0,sum=0,sum1=0;
  for(int i=0;i<n;i++){
    if(s[i]=='J'){
      count++;
      count1++;
    }
    O[i]=count;
    CO[i]=count1;
  }
  count = 0;
  count1 = 0;
  for(int i=0;i<n;i++){
    if(s[i]=='O'){
      count+=O[i];
      count1+=CO[i];
    }
    if(s[i]=='I'){
      I[i]=count;
      CI[i]=count1;
      sum1+=I[i];
      sum+=CI[i];
    }
  }
  ans=max(sum1+count,sum);

  count=0;
  for(int i=n-1;i>=0;i--){
    if(s[i]=='I')count++;
    numI[i]=count;
  }

  for(int i=0;i<n;i++){
    ans=max(ans,sum1+O[i]*numI[i]);
  }
  cout<<ans<<endl;

  return 0;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long

typedef pair<int,int> pii;
const int N = 1e3+5;
const int H = 1e4+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int h, n;
int a[N], c[N];
int mem[H][N];

int f(int h, int n) {
	if (h <= 0) return 0;
	if (n <= 0) return INF;
	int &ret = mem[h][n];
	if (ret != -1) return ret;
	return ret = min(c[n] + f(h-a[n], n), f(h, n-1));
}
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> h >> n;
	for(int i=1; i<=n; i++) cin >> a[i] >> c[i];
	memset(mem, -1, sizeof mem);
	cout << f(h, n) << endl;
	return 0;
}


Measured memory_bytes: 40064
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

int n;
vector<int> vec;

int main() {
  cin >> n;
  vec.resize(n);
  rep(i, n) { cin >> vec[i]; }
  sort(vec.rbegin(), vec.rend());
  int count = 0;
  rep(i, n - 2) {
    for (int second = i + 1; second < n - 1; second++) {
      for (int k = n - 1; k > second; k--) {
        if (vec[k] > (vec[i] - vec[second])) {
          count += k - second;
          break;
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 1000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

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



int main() {

  int a;
  string s;

  cin >> a >> s;

  if(a>=3200) cout << s << endl;
  else cout << "red" << endl;

  return 0;
}


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

int main() {
  int N, A;
  cin >> N >> A;
  int diff = N % 500;
  
  if(diff <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;  
  }
  return 0;
}


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

const int N = 1e5;

string s;
int n,m;
int ps[N+5];

vector<int> ans;

int main(){
	cin >> n >> m;
	cin >> s;
	reverse(s.begin(),s.end());
	for(int i=1;i<=n;i++){
		ps[i] = ps[i-1] + s[i] - '0';
	}
	bool bisa = 0;
	int cur = 0;
	for(int op=1;op<=n+2;op++){
		int l = cur+1;
		int r = min(cur+m,n);
		int uj = min(cur+m,n);
		int ret = cur;
		while(l<=r){
			int mid = (l+r)/2;
//			cout << mid << " << " << ps[uj] - ps[mid-1] << " <<<<< \n";
			if(ps[uj] - ps[mid-1] != (uj-mid+1)){
				l = mid+1;
				ret = mid;
			} else {
				r = mid-1;
			}
		}
//		cout << uj << " >> " << ret << endl;
		if(ret == cur) break;
		ans.push_back(ret-cur);
		cur = ret;
		if(cur == n){
			bisa = 1;
			break;
		}
//		cout << cur << endl;
	}
	if(!bisa){
		printf("-1\n");
	} else {
		reverse(ans.begin(),ans.end());
		for(int i=0;i<ans.size();i++){
			if(i>0) printf(" ");
			printf("%d",ans[i]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 1528