akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

string s;
map<char, int> mp;

int main() {
	cin >> s;
	inc(i, 4) { mp[s[i]]++; }
	
	cout << (SI(mp) == 2 && mp[s[0]] == 2 ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 768
/*
Hokudai Practice Contest 2014
B - Matsuzaki Number

ティツァツ」テヲツウツ陛ッツシツ堙ァツエツ?ヲツ閉ーテ・ツ按療ヲツ個凖ッツシツ凝・ツ?ィテヲツ篠「テァツエツ「
テ・ツ可催・ツ?ヲテァツ青?」ツ?ィテ」ツ?療」ツ?ヲテ」ツ??・ツ債?・ツ按?」ツ?ェテ・ツ、ツァテ」ツ?催」ツ?陛」ツ?セテ」ツ?ァテァツエツ?ヲツ閉ーテ」ツつ津ゥツ?催・ツ按療」ツ?ォテ・ツ按療ヲツ個凖」ツ?療」ツ?ヲテ」ツ?甘」ツ?催」ツ??
テ・ツ?・テ・ツ環嬾テ」ツ?ォテ・ツッツセテ」ツ?療」ツ?ヲテ・ツ、ツァテ」ツ?催」ツ?貧テ」ツつ暗」ツつ甘・ツ、ツァテ」ツ?催」ツ??ァツエツ?ヲツ閉ーテ」ツつ津ゥツ?催・ツ按療」ツ?凝」ツつ嘉ヲツ篠「テ」ツ?凖」ツ??
ティツヲツ凝」ツ?、テ」ツ?妥」ツ?淌ァツエツ?ヲツ閉ーテ」ツ?凝」ツつ英テ・ツ?凝」ツつ津・ツ渉姪」ツつ甘・ツ?コテ」ツ?療」ツ??」ツ?凖」ツ?ケテ」ツ?ヲテ」ツ?ョテ・ツ渉ッティツδステ」ツ?ェテ」ツδ堙」ツつ「テ」ツ?ョテ・ツ陳古」ツつ津・ツ按療ヲツ個凖」ツ?凖」ツつ凝」ツ??
テ」ツ?敕」ツ?ョテ、ツクツュテ」ツ?ァpテァツ閉ェテァツ崢ョテ」ツ?ォテ・ツーツ湘」ツ?陛」ツ??」ツつづ」ツ?ョテ」ツ?古ァツュツ氾」ツ?暗」ツ?ィテ」ツ?ェテ」ツつ凝」ツ??

テ・ツ按カテァツエツ?」ツ??0^6テ」ツ?ィテ・ツ、ツァテ」ツ?催」ツつ?」ツ?ェテ」ツ?ョテ」ツ?ァテ」ツ??」ツつィテ」ツδゥテ」ツδ暗」ツつケテ」ツδ?」ツδ催」ツつケテ」ツ?ョテァツッツゥテ」ツつ津ァツ板ィテ」ツ??」ツ?ヲテァツエツ?ヲツ閉ーテ・ツ按療ヲツ個凖」ツつ津ィツ。ツ古」ツ??

テヲツウツィテヲツ?湘ァツつケテ」ツ?ィテ」ツ?療」ツ?ヲテ」ツ?｝^(1/2)テ」ツ?セテ」ツ?ァテ・ツ渉姪」ツつ甘・ツ?コテ」ツ?療」ツ?ヲテ」ツδ堙」ツつ「テ」ツ?ョテ・ツ陳古」ツつ津ィツィツ暗ァツョツ療」ツ?凖」ツつ凝」ツ??」ツ?妥」ツ?ァテ」ツ?ッテ」ツ??
テ・ツ陳古」ツ?継テァツ閉ェテァツ崢ョテ」ツ?ォテ・ツーツ湘」ツ?陛」ツ??ヲツ閉ーテ」ツ?古ァツ渉セテ」ツつ古」ツつ凝」ツ?ィテ」ツ?ッテゥツ卍静」ツつ嘉」ツ?ェテ」ツ??」ツ?ョテ」ツ?ァテ、ツクツ催・ツ債?・ツ按?」ツ?ァテ」ツ?づ」ツつ?

[テ・ツ可催・ツ?ヲテァツ青?
テヲツ卍づゥツ鳴禿ィツィツ暗ァツョツ療ゥツ?湘ッツシツ唹(MAX_N loglog MAX_N)
テァツゥツコテゥツ鳴禿ィツィツ暗ァツョツ療ゥツ?湘ッツシツ唹(MAX_N)
[1テ」ツδ?」ツつケテ」ツδ暗」ツつアテ」ツδシテ」ツつケテ」ツ?ョテ・ツ?ヲテァツ青?
テヲツ卍づゥツ鳴禿ィツィツ暗ァツョツ療ゥツ?湘ッツシツ唹(logMAX_N + p^2 log p)
テァツゥツコテゥツ鳴禿ィツィツ暗ァツョツ療ゥツ?湘ッツシツ唹(p^2)
*/

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

//10^6テ」ツつ暗」ツつ甘・ツ、ツァテ」ツ?催」ツ??ァツエツ?ヲツ閉ーテ」ツつ?00テ・ツ?凝ィツヲツ凝」ツ?、テ」ツ?妥」ツつ凝・ツソツ?ィツヲツ?」ツ?古」ツ?づ」ツつ凝」ツ?ョテ」ツ?ァテ」ツ??0^6テ」ツつ暗」ツつ甘・ツ、ツァテ」ツ?催」ツつ?」ツ?ォテゥツ?催・ツ按療」ツつ津ァツ「ツコテ、ツソツ敕」ツ?凖」ツつ?
//10^6テ」ツつ暗」ツつ甘・ツ、ツァテ」ツ?催」ツ??00テァツ閉ェテァツ崢ョテ」ツ?ョテァツエツ?ヲツ閉ーテ」ツ?ッ101197テ」ツ?ェテ」ツ?ョテ」ツ?ァテ」ツ??・ツョツ淌ゥツ堋崚」ツ?ッMAX_N=101198テ」ツ?ァテ・ツ債?・ツ按?
const int MAX_N = 200000;

int main(){
  //テァツエツ?ヲツ閉ーティツ。ツィ
  vector<bool> isPrime(MAX_N+1,1);
  //テァツエツ?ヲツ閉ーテ」ツδェテ」ツつケテ」ツδ?
  vector<int> primes;
  isPrime[0] = isPrime[1] = 0;

  //テ」ツつィテ」ツδゥテ」ツδ暗」ツつケテ」ツδ?」ツδ催」ツつケテ」ツ?ョテァツッツゥ
  for(int i=2;i<=MAX_N;i++){
    if(!isPrime[i])continue;
    primes.push_back(i);
    for(int j=2*i;j<=MAX_N;j+=i)isPrime[j] = 0;
  }
 
  int n,p;
  while(cin >> n >> p, n>=0){ 
    //nテ」ツつ暗」ツつ甘・ツ、ツァテ」ツ?催」ツ??ヲツ慊?・ツーツ湘」ツ?ョテァツエツ?ヲツ閉ーテ」ツ?ョテ、ツスツ催ァツスツョテ」ツつ津ヲツアツづ」ツつ?」ツつ?テ」ツ?禿」ツ?禿」ツ?ァテ」ツ?ッテ、ツコツ古・ツ按?ヲツ篠「テァツエツ「)
    int pos = upper_bound(primes.begin(),primes.end(),n) - primes.begin();

    //nテ」ツつ暗」ツつ甘・ツ、ツァテ」ツ?催」ツ??ァツエツ?ヲツ閉ーテ」ツつ津・ツーツ湘」ツ?陛」ツ??ヲツ鳴ケテ」ツ?凝」ツつ英テ・ツ?凝」ツδェテ」ツつケテ」ツδ暗」ツ?ォティツゥツーテ」ツつ?」ツつ?
    vector<int> pList;
    for(int i=0;i<p;i++)pList.push_back(primes[pos+i]);

    //テ」ツ?凖」ツ?ケテ」ツ?ヲテ」ツ?ョテ」ツδ堙」ツつ「テ」ツ?ョテ・ツ陳古」ツつ津ヲツアツづ」ツつ?」ツつ?
    vector<int> sum;
    for(int i=0;i<p;i++){
      for(int j=0;j<=i;j++){
	sum.push_back(pList[i] + pList[j]);
      }
    }
 
    //pテァツ閉ェテァツ崢ョテ」ツ?ォテ・ツーツ湘」ツ?陛」ツ??ヲツ閉ーテ」ツ?ッテ」ツ??」ツつステ」ツδシテ」ツδ暗」ツ?療」ツ?ヲsum[p-1]テ」ツ?ォテ」ツつ「テ」ツつッテ」ツつサテ」ツつケテ」ツ?凖」ツつ古」ツ?ーテ」ツつ湘」ツ?凝」ツつ?
    sort(sum.begin(),sum.end());
    cout << sum[p-1] << endl;
  }
}

Measured memory_bytes: 1372
// inputに入力データ全体が入る
function Main(input) {
  
   input = input.split(" ");
  var r= parseInt(input[0], 10);
  var D= parseInt(input[1], 10);
  var X= parseInt(input[2], 10);
    
   
for (var i = 0; i <10 ; i++){
            var X = r * X - D;
            console.log(X);}
           
 
}
 
  
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  

Measured memory_bytes: 21320
main(){float d,e,f,g,h,i,m,n;for(;~scanf("%f%f%f%f%f%f%f%f",&d,&e,&f,&g,&h,&i,&m,&n);puts((f-d)*(n-e)*(f=(h-f)*(n-g)-(m-f)*(i-g))>f*(m-d)*(g-e)&f*(d-h)*(n-i)>f*(m-h)*(e-i)?"YES":"NO"));}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    long long a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a>=k){
        cout << k << endl;
    }else if(k<=a+b){
      cout << a << endl;
  }else{
      cout << (a-(k-a-b)) << endl;
  }
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define reps(i,s,n) for(int (i) = (s); (i) < (n); ++(i))
#define rep(i,n) reps(i,0,n)
//using ll = long long;
     
int main(){
     	int a,b;
	cin >> a >>  b;
	if(a+b <= 9)
		cout << a+b << endl;
     	else 
		cout << "error" << endl;
	return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
counter = 0
if x == 1 and y == 1:
  counter += 400000
if x == 3:
  counter += 100000
if x == 2:
  counter += 200000
if x == 1:
  counter += 300000
if y == 3:
  counter += 100000
if y== 2:
  counter += 200000
if y== 1:
  counter += 300000
print(counter)

Measured memory_bytes: 38256
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
    int N,K,max=0,min=200001,cnt=0,decline=0;
    cin >> N >> K;
    long int A[200001]={0};
    for(int i=0;i<N;i++){
        int x;
        cin >>x;
        if(A[x] == 0) cnt++;
        A[x]++;
        if(max<x) max = x;
        if(min>x) min = x;
    }
    int k = cnt-K;
    if(k<=0) cout<<0;
    else {
        sort(A,A+200001,greater<int>());
        for(int i=0;i<k;i++){
            decline += A[cnt-1];
            cnt--;
        }
        cout<< decline;
    }
}


Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P, P>PP;
typedef pair<PP, PP>PPPP;
struct edge { int to; int cost; };
vector<int>G[300006];
int d[300006];

void dijk(int s,int V) {
	fill(d, d + V, inf);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>> Q;
	Q.push(P(0, s));
	while (Q.size()) {
		P p = Q.top();
		Q.pop();
		int v = p.second;
		if (d[v] > p.first)continue;
		rep(i, G[v].size()) {
			int e = G[v][i];
			if (d[e] > d[v] + 1) {
				d[e] = d[v] + 1;
				Q.push(P(d[e], e));
			}
		}
	}
}

signed main() {
	int n, m; cin >> n >> m;
	rep(i, m) {
		int u, v; cin >> u >> v;
		u--; v--;
		G[u].push_back(v + n);
		G[u + n].push_back(v + 2 * n);
		G[u + 2 * n].push_back(v);
	}
	int s, t; cin >> s >> t; s--; t--;
	dijk(s, n * 3);
	cout << (d[t]==inf?-1:d[t]/3) << endl;
}

Measured memory_bytes: 18944
X,K,D = map(int, input().split())
x=abs(X)
a=x//D
if a>=K:
    print(x-D*K)
else:
    if (K-a)%2==0:
        print(int(x-D*a))
    elif (K-a)%2==1:
        print(int(abs(x-D*(a+1))))


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

int i, n, k, v[55], t, ans;
multiset<int> ms;

int main(){
	cin >> n >> k;
	for (i = 0; i < n; ++i)cin >> v[i];

	ans = 0;
	for (int m = 1; m <= k; ++m){ // operate m times
		for (int j = 0; j <= min(m, n); ++j){ // get rid of j jewelry
			if (m-j > n || m-j <= j) continue;
			for (int l = 0; l <= m-j; ++l){ // pick up l jewelry from left
				ms.clear();
				t = 0;
				for (i = 0; i < l; ++i){
					t += v[i];
					ms.insert(v[i]);
				}
				for (i = 0; i < m-j-l; ++i){
					t += v[n-i-1];
					ms.insert(v[n-i-1]);
				}

				i = 0;
				for (auto it=ms.begin(); it != ms.end(); ++it, ++i){
					if (i >= j) break;
					t -= *it;
				}
				if (t > ans) ans = t;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin>>a>>b;
    if(a>=b)
        cout<<1<<endl;
    else
	{
		int rez = b/a;
		if(b%a!=0)
			rez++;
		
		cout<<rez<<endl;
	}
        
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define pb push_back
#define ll long long 
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; 
    for(int T = 0; T < t ; T++){
        ll n, m, k;
        cin >> n >> m >> k;
        std::vector<ll> a(n), b(m);
        cin >> a[0];
        for(int i = 1; i < n; i++){
            cin >> a[i];
            a[i] += a[i - 1];
        }
        cin >> b[0];
        for(int i = 1; i < m; i++){      
            cin >> b[i];
            b[i] += b[i - 1];
        }
        ll csum = 0, ans = 0;
        for(int i = 0; i <= n; i++){
            if(i > 0)
                csum = a[i - 1];
            if(csum > k)
                break;
            ll er = upper_bound(b.begin(), b.end(), k - csum) - b.begin() - 1;
            ans = max(er + i + 1,ans);
        } 
        cout << ans << endl;
    }
    return 0;
}

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ll n,a,now=0; cin >>n; cin >>a; now=a; n--;
	long long sum=0;
	while (n--) {
		scanf("%d",&a);
		if (a>now) {
			now=a;
			continue;
		}
		sum+=now-a;
	}
	cout <<sum;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

vector<ll> num;

struct Nbase {
    int n;
    int sz = 1;
    long long max = 1e18;

    Nbase(int k = 2){
        n = k;
        while(max != 0){
            max /= n;
            sz++;
        }
        num.resize(sz);
    };

    //繰り返し二乗法
    ll EX(ll x,ll n){
        if(n == 0) return 1;
        else if(n%2 == 1) return EX(x,n-1)*x;
        else return EX(x*x,n/2);
    }

    vector<int> to_n(ll num){
        vector<int> ret(sz);
        for(int i = sz-1; i >= 0; i--){
            long long subtraction = EX(n,i);
            if(subtraction <= num){
                for(int j = 1; j <= n; j++){
                    if(num < j*subtraction){
                        ret[i] = j-1;
                        num -= ret[i]*subtraction;
                    } 
                }
            } else ret[i] = 0;
        }
        return ret;
    }

    long long re_n(vector<int>& vec){
        long long ret = 0;
        vec.resize(sz);
        for(int i = 0; i < sz; i++){
            ret += vec[i]*EX(n,i);
        }
        return ret;
    }

    void supress(const vector<int>& lim,vector<int>& at){
        bool upper = true;
        for(int i = sz; i >= 0; i--){
            if(upper && lim[i] > 0) upper = false;
            if(lim[i] > at[i]) break;
            else if(upper || lim[i] < at[i]) at[i] = lim[i];
        }
    }
};

int main(){
    Nbase base = 2;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        vector<int> sam = base.to_n(a[i]);
        for(int j = 0; j < base.sz; j++){
            if(sam[j] == 1) num[j]++;
        }
    }
    vector<int> x(base.sz);
    for(int i = 0; i < base.sz; i++){
        if(num[i] <= n/2) x[i] = 1;
        else x[i] = 0;
    }
    base.supress(base.to_n(k),x);
    ll X = base.re_n(x);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += X^a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4024
/*配列*/
#include <iostream>
using namespace std;

int main(){
  string S,T;
  
  cin >> S >> T;
  
  if(S.length()<=10 && S.length()+1==T.length()){
    T.pop_back();
    int result = S.compare(T);
    if(result == 0){
    	cout << "Yes\n";
    }else{
    	cout << "No\n";
    }
  }
  else
    cout << "No\n";

  return 0;
}


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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;

int main(){
  int a;string s; cin >> a >> s;
  if(a<3200){
          cout << "red" << endl;
  }else{
          cout << s << endl;
  }
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc052/tasks/abc052_b
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

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


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    double n, k;
    cin >> n >> k;
    double ans;
    if (n >= k) ans = (n - k + 1) / n;
    else ans = 0;
    rep(i, min(n, k-1)) {
        double tmp = ceil(log2(k / (i+1)));
        ans += 1/n * pow(0.5, tmp);
    }

    printf("%.10f", ans);
    return 0;
}

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

int main(){
	string s;
	getline(cin,s);

	for(int i=0; i < s.length();i++){
		if(islower(s[i]))
			s[i]=toupper(s[i]);
		else
			s[i]=tolower(s[i]);
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3148
import sys
N,M = map(int,input().split())
data = [[i,list(map(int,sys.stdin.readline().rstrip().split()))] for i in range(M)]

# print(data)
sortdata = sorted(data, key=lambda data:data[1])
# print(sortdata)

cnt = 1
sortdata[0].append(1)
for i in range(1,M):
    if sortdata[i][1][0] == sortdata[i-1][1][0]:
        cnt += 1
    else:
        cnt = 1
    sortdata[i].append(cnt)

sortdata = sorted(sortdata, key=lambda data:data[0])
for i in range(M):
    print(str(sortdata[i][1][0]).rjust(6,'0'),end = "")
    print(str(sortdata[i][2]).rjust(6,'0'))


Measured memory_bytes: 44040
/*    *** Bismillahir Rahmanir Rahim***
          *A S M Masud Parvez*
             *18ICTCSE035*
           *SHIICT(BSMRSTU)*
*/
#include<bits/stdc++.h>
using namespace std;
#define MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define        nl "\n"
#define        End return 0
#define        ll long long int
#define        mp make_pair
#define        gt greater<int>()
#define        pb push_back
#define        mod 1000000007
#define        ull unsigned long long int
int            Max = INT_MIN;
int            Min = INT_MAX;
#define        pi acos(-1)
int i,j,f=0,x,y,z,n,m,S=0,r,len;

int main()
{

MP;
cin>>n>>m;
if(m>=n){
  cout<<"unsafe";
}else
{
  cout<<"safe";
}


End;
}


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

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

    vector<int> p(n), p_prev(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }

    copy(p.begin(), p.end(), p_prev.begin());
    sort(p.begin(), p.end());

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(p[i] != p_prev[i]) cnt++;
    }

    if (cnt == 2 || cnt == 0) cout << "YES" << endl;
    else cout << "NO" << endl;


    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nr = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(nr[1] + Max(0, 10 - nr[0]) * 100);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define MAXCH(a, b) (a = max(a, b))
using namespace std;
typedef long long ll;

struct data {
  ll fi, se, w;
  bool operator<(const data &d) const {
    return se < d.se;
  }
};

int main(void) {
  ll N;
  while(cin >> N, N) {
    vector<data> P(N);
    REP(i, 0, N) cin >> P[i].fi >> P[i].se >> P[i].w, P[i].fi--;

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

    vector<vector<ll>> dp(366, vector<ll>(366, 0));
    REP(k, 0, N) {
      for(ll i = 365; i >= 0; i--) for(ll j = 365; j >= 0; j--) {
        if(i <= P[k].fi) MAXCH(dp[P[k].se][j], dp[i][j] + P[k].w);
        if(j <= P[k].fi) MAXCH(dp[i][P[k].se], dp[i][j] + P[k].w);
      }
    }

    ll ans = 0;
    REP(i, 0, 366) REP(j, 0, 366) ans = max(ans, dp[i][j]);
    cout << ans << endl;
  }
}


Measured memory_bytes: 3928
//
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>      // std::ostringstream

std::vector<std::string> split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

using namespace std;

int main(){
	string str;
	cin >> str;
	vector<string> vec = split(str, ',');
	cout << vec[0] <<" " << vec[1] << " " << vec[2] << endl;

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{	const int n=3;
  ll arr[n];
  for(ll i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  sort(arr,arr+n);
 	ll count=0;
  for(ll i=0;i<n-1;i++)
  {
    if(arr[i+1]-arr[i]==0)
    {
      count++;
    }
  }
 if(count==1)
 {
   cout<<"Yes"<<endl;
   return 0;
 }
 cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int min(int a, int b){
  return (a > b)?b:a;
}

int main(){
  int n, i = 0, j = 0, k = 0;
  scanf("%d", &n);
  int dp[n + 1][n + 1], p[n + 1];
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= n; j++) {
      if(i == j)dp[i][j] = 0;
      else dp[i][j] = 1e9;
    }
  }
  int tmp;
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d", &p[i], &tmp);
  }
  scanf("%d %d", &p[n - 1], &p[n]);
  
  for (k = 1; k <= n; k++) {
    for (i = 0; i + k <= n; i++) {
      int end = i + k - 1;
      for (j = 1; j < k; j++) {
        //printf("i:%d end:%d end - j:%d i + j:%d\n", i, end, end - j, i + j);
        dp[i][end] = min(dp[i][end], dp[i][end - j] + dp[end - j + 1][end] + p[i]*p[end - j + 1]*p[end + 1]);
      }
    }
  /* for (i = 0; i < n; i++) { */
  /*   for (j = 0; j < n; j++) { */
  /*     if(j != n - 1)printf("%6d ", dp[i][j]); */
  /*     else printf("%6d\n", dp[i][j]); */
  /*   } */
  /* } */

    
  }
  printf("%d\n", dp[0][n - 1]);
  return 0;
}

Measured memory_bytes: 632
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //
 
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 300005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}
 
 
 
signed main() {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    fast
    ll n;
    cin >> n;
    ll ans = 0;
    vl x(n), y(n);
    loop(i, n)   cin >> x[i] >> y[i];
    ll pmx = -inf, pmn = inf, mmx = -inf, mmn = inf;
    loop(i, n)
    {
        pmx = max(pmx, x[i] + y[i]);
        pmn = min(pmn, x[i] + y[i]);
        mmx = max(mmx, x[i] - y[i]);
        mmn = min(mmn, x[i] - y[i]);
    }
    ans = max({ans, pmx - pmn, mmx - mmn});
    cout << ans << END;
 
 
// #ifndef ONLINE_JUDGE
//     cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
    return 0;
}
 

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

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long []a=new long[3*N];
		long ans=0;
		for(int i=0;i<3*N;i++){
			a[i]=sc.nextLong();
		}
		Arrays.sort(a);
		for(int i=3*N-1;i>3*N-1-2*N;i-=2){
			ans+=a[i-1];
		}
		System.out.println(ans);
	}

}


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

const int maxn = 2e5+10;
int n,a[maxn];
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

int maxv[maxn<<2];
void build(int l,int r,int rt){
	if(l==r){
		scanf("%d",a+l);
		maxv[rt]=a[l];return;
	}
	int mid=l+r>>1;
	build(lson);build(rson);
	maxv[rt]=max(maxv[rt<<1],maxv[rt<<1|1]);
}
int query(int L,int R,int l,int r,int rt){
	if(L<=l&&R>=r)return maxv[rt];
	int mid=l+r>>1,ret=0;
	if(L<=mid)ret=max(ret,query(L,R,lson));
	if(R>mid)ret=max(ret,query(L,R,rson));
	return ret;
}

int main(){
	scanf("%d",&n);
	build(1,n,1);
	ll ans=0;
	int l,r,mid;
	int len1,len2;
	for(int i=1;i<=n;i++){
		l=0,r=i+1;
		while(r-l>1){
			mid=l+r>>1;
			if(query(mid,i,1,n,1)==a[i])r=mid;
			else l=mid;
		}
		len1=i-r+1;
		l=i-1,r=n+1;
		while(r-l>1){
			mid=l+r>>1;
			if(query(i,mid,1,n,1)==a[i])l=mid;
			else r=mid;
		}
		len2=l-i+1;
		ans+=1ll*a[i]*len1*len2;
		cout<<len1<<" "<<len2<<endl;
	}
	cout<<ans;
	return 0;
}*/

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

const int maxn = 2e5+10;
int n,a[maxn];
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

int maxv[maxn<<2];
void build(int l,int r,int rt){
	if(l==r){
		scanf("%d",a+l);
		maxv[rt]=a[l];return;
	}
	int mid=l+r>>1;
	build(lson);build(rson);
	maxv[rt]=min(maxv[rt<<1],maxv[rt<<1|1]);
}
int query(int L,int R,int l,int r,int rt){
	if(L<=l&&R>=r)return maxv[rt];
	int mid=l+r>>1,ret=0x3f3f3f3f;
	if(L<=mid)ret=min(ret,query(L,R,lson));
	if(R>mid)ret=min(ret,query(L,R,rson));
	return ret;
}

int main(){
	scanf("%d",&n);
	build(1,n,1);
	ll ans=0;
	int l,r,mid;
	int len1,len2;
	for(int i=1;i<=n;i++){
		l=0,r=i+1;
		while(r-l>1){
			mid=l+r>>1;
			if(query(mid,i,1,n,1)==a[i])r=mid;
			else l=mid;
		}
		len1=i-r+1;
		l=i-1,r=n+1;
		while(r-l>1){
			mid=l+r>>1;
			if(query(i,mid,1,n,1)==a[i])l=mid;
			else r=mid;
		}
		len2=l-i+1;
		ans+=1ll*a[i]*len1*len2;
		//cout<<len1<<" "<<len2<<endl;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] array = new int[5];
		for(int i=0;i<n;i++) {
			char[] temp = sc.next().toCharArray();
			char top = temp[0];
			if(top=='M') array[0]++;
			if(top=='A') array[1]++;
			if(top=='R') array[2]++;
			if(top=='C') array[3]++;
			if(top=='H') array[4]++;
		}
		sc.close();
		long ans=0;
		for(int i=0;i<3;i++) {
			for(int j=i+1;j<4;j++) {
				for(int k=j+1;k<5;k++) ans += (long)array[i]*array[j]*array[k];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 46768
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w, d = na()
a = []
for i in range(h):
    a.append(na())

wh = [None] * (h*w)
for i in range(h):
    for j in range(w):
        wh[a[i][j]-1] = (i,j)

xs = []
for i in range(d):
    row = [0]
    for j in range(i+d, h*w, d):
        row.append(row[-1] +
                   abs(wh[j][0]-wh[j-d][0]) +
                   abs(wh[j][1]-wh[j-d][1]))
    xs.append(row)

q = ni()
for z in range(q):
    l, r = na()
    l -= 1; r -= 1
    print(xs[l%d][r//d]-xs[l%d][l//d])
    

Measured memory_bytes: 23656
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class UnionFind:
    """ Union-Find木 """

    def __init__(self, n):
        self.n = n
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)
        # あるノードを根とする集合に属するノード数
        self.size = [1] * (n+1)
        # あるノードを根とする集合が木かどうか
        self.tree = [True] * (n+1)

    def find(self, x):
        """ 根の検索(グループ番号と言えなくもない) """
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """ 併合 """
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # 木かどうかの判定用
        if x == y:
            self.tree[x] = False
            return
        if not self.tree[x] or not self.tree[y]:
            self.tree[x] = self.tree[y] = False

        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        """ 同じ集合に属するか判定 """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """ あるノードの属する集合のノード数 """
        return self.size[self.find(x)]
    
    def is_tree(self, x):
        """ 木かどうかの判定 """
        return self.tree[self.find(x)]

    def len(self):
        """ 集合の数 """
        res = set()
        for i in range(self.n+1):
            res.add(self.find(i))
        # グループ0の分を引いて返却
        return len(res) - 1

N, M = MAP()
P = [p-1 for p in LIST()]

uf = UnionFind(N)
for i in range(M):
    a, b = MAP()
    a -= 1
    b -= 1
    uf.union(P[a], P[b])

cnt = 0
for i in range(N):
    p = P[i]
    if uf.same(p, i):
        cnt += 1
print(cnt)


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

int main() {
	ll n;
	cin >> n;
	vector<double> x(n), y(n);
	rep(i,n) {
		cin >> x[i] >> y[i];
	}
	double ans = 0;
	rep(i,n) rep(j,n) ans += sqrt(pow(x[i] - x[j],2) + pow(y[i] - y[j],2));
	ans /= (double)(n);
	printf("%.10f\n", ans);
	return 0;
}


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

#define MAX_SIZE 26

std::map<char, std::string> codes;
std::map<char, int> frequencies;

class HuffmanTreeNode {
public:
    char data;
    int freq;
    HuffmanTreeNode* left;
    HuffmanTreeNode* right;
    HuffmanTreeNode(char character,
                    int frequency)
    {
        data = character;
        freq = frequency;
        left = right = NULL;
    }
};

// Custom comparator class
class Compare {
public:
    bool operator()(HuffmanTreeNode* a,
                    HuffmanTreeNode* b)
    {
        return a->freq > b->freq;
    }
};

std::priority_queue<HuffmanTreeNode*, std::vector<HuffmanTreeNode*>, Compare> pq;

HuffmanTreeNode* generateTree() {

    while (pq.size() != 1) {

        HuffmanTreeNode* left = pq.top();
        pq.pop();

        HuffmanTreeNode* right = pq.top();
        pq.pop();

        HuffmanTreeNode* node = new HuffmanTreeNode('$',
                                                    left->freq + right->freq);
        node->left = left;
        node->right = right;

        pq.push(node);
    }

    return pq.top();
}

void restoreCodes(HuffmanTreeNode* root,
                  int arr[], int top)
{

    if (root->left) {
        arr[top] = 0;
        restoreCodes(root->left,
                     arr, top + 1);
    }

    if (root->right) {
        arr[top] = 1;
        restoreCodes(root->right, arr, top + 1);
    }

    if (!root->left && !root->right) {
        std::string temp;
        for (int i = 0; i < top; i++) {
            temp += std::to_string(arr[i]);
        }
        codes[root -> data] = temp;
    }
}

void calcFreq(std::string str) {
    for (unsigned long i = 0; i < str.size(); i++) {
        frequencies[static_cast<char>(str[i])]++;
    }
}

void HuffmanCodes()
{
    std::string str;
    std::cin >> str;

    calcFreq(str);

    for (auto v = frequencies.begin(); v != frequencies.end(); v++) {
        HuffmanTreeNode* newNode = new HuffmanTreeNode(v -> first, v -> second);
        pq.push(newNode);
    }

    if (pq.size() == 1) {
        std::cout << pq.top()->freq << std::endl;
    }

    else {
        HuffmanTreeNode* root = generateTree();

        int arr[MAX_SIZE], top = 0;
        restoreCodes(root, arr, top);

        long long res = 0;
        for (auto i : str)
            res += codes[i].size();
        std::cout << res << std::endl;
    }
}

int main()
{
    HuffmanCodes();
    return 0;
}



Measured memory_bytes: 3496
#include <bits/stdc++.h>
#define pb push_back
#define CLR(a) memset(a, 0, sizeof a)
#define SETDP(a) memset(a, -1, sizeof a)
#define SETINF(a) memset(a, 127, sizeof a)
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
int n, m, x;
int pref[110], arr[110];
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n>>m>>x;
    for(int i=0; i<m; i++)
    {
        int a;
        cin>>a;
        arr[a]=1;
    }
    for(int i=1; i<n; i++)
        pref[i]=pref[i-1]+arr[i];
    cout<<min(pref[x-1], pref[n-1]-pref[x])<<"\n";
    return 0;
}


Measured memory_bytes: 256
import collections

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

a, b = map(int, input().split())
af = factorize(a)
bf = factorize(b)
ac = collections.Counter(af)
bc = collections.Counter(bf)
pnum = set(ac.keys()) | set(bc.keys())

ans = 1
for i in pnum:
    ans *= i**(max(ac[i], bc[i]))
print(ans)

Measured memory_bytes: 3316
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [0] * D
for i in range(D):
    r=((i+1)%26)+1
    t[i] = r

    
M=2
day=[1,4]
q=[7,11]
    
m=[0]*D

a=[[0 for i in range(26)] for j in range(D)]
for u in range(D):
    i=t[u]
    for y in range(u,D):
        a[y][i-1]=u+1
    if u==0:
        m[u]=s[u][i-1]
    else:
        m[u]=m[u-1]+s[u][i-1]
mm=[0]*D
for d  in range(D):
    for i in range(26):
        mm[d]+=c[i]*(d+1-a[d][i])
    if not d==0:
        mm[d]+=mm[d-1]
for d in range(D):
    m[d]-=mm[d]
mmm=m[D-1]



for p in range(M):
    new_type=q[p]
    old_type=t[day[p]-1]
    #print(new_type,old_type)
    A=0
    B=0
    C=0
    #C=s[day[p]-1][old_type-1]-s[day[p]-1][new_type-1]
    for d in range(D):
        A+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    xday=day[p]
    if xday>1:
        before_new=a[xday-2][new_type-1]
        before_old=a[xday-2][old_type-1]
        now_new=a[day[p]-1][new_type-1]
        now_old=a[day[p]-1][old_type-1]
        for d in range(day[p]-1,D):
            if a[d][new_type-1]==now_new:
                a[d][new_type-1]=xday
            if a[d][old_type-1]==now_old:
                a[d][old_type-1]=before_old
    else:
        for d in range(day[p]-1,D):
            if a[d][old_type-1]==1:
                a[d][old_type-1]=0
            if a[d][new_type-1]==0:
                a[d][new_type-1]=1   
    t[day[p]-1]=new_type
    for d in range(D):
        B+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    s=mmm-(B-A+C)
    if s>mmm:
        mmm=s
    #print(mmm)
for i in range(len(t)):
    print(t[i])

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

long long int n,k,r,s,p,a;
string m,h;
int main(){
    cin>>n>>k>>r>>s>>p;
    cin>>m;
    for (int i=0; i<n; i++){
        if (m[i]=='r'){
            h+='p';
        }
        else if (m[i]=='p'){
            h+='s';
        }
        else{
            h+='r';
        }
    }
    for (int i=k; i<n; i++){
        if (h[i]==h[i-k]){
            if (h[i]=='r'){
                h[i]='q';
            }
            else if (h[i]=='p'){
                h[i]='q';
            }
            else{
                h[i]='q';
            }
        }
    }
    for (int i=0; i<n; i++){
        if (h[i]=='r'){
            a+=r;
        }
        else if (h[i]=='p'){
            a+=p;
        }
        else if (h[i]=='s'){
            a+=s;
        }
    }
    cout<<a<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
static const int MAX = 10000;


int main(){
  int N = in(), l[MAX], x;
  long long count = 0;
  rep(i, N) l[i] = in();
  sort(l, l+N);	
 
  rep(i, N){
    for(int j = i+1; j < N; j++){
      x = l[i]+l[j];
      for(int k = j+1; k < N; k++){
        if(l[k] >= x) break;
        if(l[i]<l[j]+l[k] && l[j]<l[i]+l[k] && l[k]<l[i]+l[j]){
          count++;
        }    
      }
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N, 1), Red(N, 0);
  Red[0] = 1;
  REP(i, M) {
    int x, y;
    cin >> x >> y, x--, y--;
    if (Red[x] == 1) {
      Red[y] = 1;
    }
    A[x]--;
    A[y]++;
    if (A[x] == 0) {
      Red[x] = 0;
    }
  }
  ll ans = 0;
  REP(i, N) {
    if (Red[i] == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3928
import java.util.*;
import java.io.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int aa = a % 2;
    int bb = b % 2;
    if(aa == 1 && bb == 1){
      System.out.println("Odd");
    }else{
      System.out.println("Even");

    }

  }
}


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int x, y;
	cin >> x >> y;
	int cnt = 0;
	while (x) {
		++cnt;
		x /= y;
	}
	cout << cnt << '\n';
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int i, n;
	deque<int> d;
	cin >> n;
	for (i = 0; i < n; i++){
		int a;
		cin >> a;
		if ((n - i) % 2 == 0) d.push_back(a);
		else d.push_front(a);
	}
	for (i = 0; i < n; i++){
		cout << d[i];
		if (i < n - 1) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18
#define MAX_H 20
#define MAX_W 20

char maze[MAX_H][MAX_W + 1];
int sx, sy;
int gx, gy;
int h, w;
int d[MAX_H][MAX_W];

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

int bfs(){
    queue <P> que;
    for(int i=0; i<h; i++)
        for(int j=0; j<w;j++) d[i][j] = INF;

    que.push(P(sx, sy));
    d[sx][sy]=0;

    while (que.size()){
        P p=que.front(); que.pop();
        if(p.first == gx && p.second== gy) break;

        for(int i=0; i<4; i++){
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if(0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' && d[nx][ny]==INF){
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] +1;
            }
        }
    }
    return d[gx][gy];
}

int main(){
    cin >> h >> w;
    rep(i, h){
        rep(j, w){
            cin >> maze[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < h*w; i++) {
        for (int j = i+1; j < h*w; j++) {
            sx = i/w;
            sy = i%w;
            gx = j/w;
            gy = j%w;
            if(maze[sx][sy]=='#' || maze[gx][gy]=='#') continue;
            int tmp = bfs();
            if(tmp!=INF) chmax(ans, tmp);
        }
    }
        
    
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #include <C:\include\boost\multiprecision\cpp_int.hpp>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// using namespace boost::multiprecision;
ll mod = 1000000007;

ll selectionSort(vector<ll> &a,ll n){
    ll ct=0;
    for(int i=0;i<n;i++){
        ll minj=i;
        for(int j=i;j<n;j++){
            if(a[j]<a[minj]){
                minj =j;
            }
        }
        if(a[i]!=a[minj]){
            swap(a[i],a[minj]);
            ct++;
        }
    }
    return ct;
}

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll k =selectionSort(a,n);
    rep(i,n){
        if(i==n-1) cout<<a[i]<<endl;
        else cout<<a[i]<<" ";
    }
    cout<<k<<endl;
}



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

#include <iostream>
#include <fstream>

#include <iostream>

using namespace std;

class A {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s;
        getline(in, s);
        out << s.substr(0, 4) << ' ' << s.substr(4) << "\n";
	}
};


int main() {
	std::ios_base::sync_with_stdio(false);
	A solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(0);
	out << std::fixed;
	out.precision(20);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string a, b, c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
import sys

n,k=map(int,input().split())
x=list(map(int,input().split()))
if(n==1):
    print(x[0])
    sys.exit()
ans=[]
for i in range(n-(k-1)):
    f=abs(x[i+(k-1)])+abs(x[i+(k-1)]-x[i])
    b=abs(x[i])+abs(x[i]-x[i+(k-1)])
    t=min(b,f)
    ans.append(t)
ans.sort()
print(ans[0])

Measured memory_bytes: 14252
import java.util.Scanner;

/**
 * Created by zzt on 17-3-26.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[m];
        int[] d = new int[m];

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }

        for (int i = 0; i < m; i++) {
            c[i] = scanner.nextInt();
            d[i] = scanner.nextInt();
        }

        int curDis, minDis, minIndex;
        for (int i = 0; i < n; i++) {
            minDis = Math.abs(a[i] - c[0]) + Math.abs(b[i] - d[0]);
            minIndex = 0;
            for (int j = 0; j < m; j++) {
                curDis = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
                if (curDis < minDis) {
                    minDis = curDis;
                    minIndex = j;
                }
            }
            System.out.println(minIndex + 1);
        }
    }
}

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

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    vector<int> v;
    if(s[0] == '0') v.push_back(0);
    for(int i = 1; i < n; i++){
        if(s[i] == '0' && s[i-1] == '1')    v.push_back(i);
    }
    vector<int> onea(n, 1<<30), oneb(n, -1), zerob(n, -1);
    for(int i = 0; i < n; i++){
        if(s[i] == '1'){
            if(i)   onea[i] = min(onea[i-1], i);
            else    onea[i] = i;
        }
    }
    for(int i = n-1; i >= 0; i--){
        if(s[i] == '0'){
            if(i != n-1)    zerob[i] = max(zerob[i+1], i);
            else            zerob[i] = i;
        }
        if(s[i] == '1'){
            if(i != n-1)    oneb[i] = max(oneb[i+1], i);
            else            oneb[i] = i;
        }
    }
    if(v.size() <= k){
        cout << n << endl;
        return 0;
    }
    int vlen = v.size(), ans = 0;
    for(int i = 0; i <= vlen-k; i++){
        int j = i + k - 1;
        int l = v[i], r = zerob[v[j]];
        if(r+1 < n) r = oneb[r+1];
        if(l > 0)   l = onea[l-1];
        ans = max(ans, r-l+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1916