akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll dp[45];
  CLR(dp);
  dp[0]=dp[1]=1;
  FOR(i,2,45) dp[i]=dp[i-1]+dp[i-2];
  int n;
  cin>>n;
  cout<<dp[n]<<endl;
}


Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {
    //Algae
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long r = sc.nextLong();
        long d = sc.nextLong();
        long x = sc.nextLong();
        for (int i = 0; i < 10; i++) {
            x = r * x - d;
            System.out.println(x);
        }
        sc.close();
    }
}


Measured memory_bytes: 21076
def gcd(a, b):
	while (b != 0):
		temp = a % b
		a = b
		b = temp
	return abs(a)

a, b, c, d = map(int, input().split())
x = c*d//gcd(c, d)
print((b-a+1)-(b//c-(a-1)//c+b//d-(a-1)//d-b//x+(a-1)//x))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>

using namespace std;


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

	vector<int> answer(n + 1, 0);

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

	for (int i = 1; i <= n; i++) {
		cout << answer[i] << endl;
	}
}

Measured memory_bytes: 4052
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1);

void test();

int main() {
    fast_io();
    test();
    return 0;
}

void test() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c - max({a, b, c}) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>

int k;
int S[1<<18];
int Z[1<<18];
std::multiset<int, std::greater<int>> MS;

bool solve()
{
    Z[0] = *MS.begin();
    MS.erase(MS.begin());
    for (int i=1;i<k;i*=2)
        for (int j=0;j<i;++j)
        {
            auto it = MS.upper_bound(Z[j]);
            if (it == MS.end()) return false;
            Z[j+i] = *it;
            MS.erase(it);
        }
    return true;
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    int n;
    std::cin >> n;
    k = 1<<n;
    for (int i=0;i<k;++i) std::cin >> S[i];
    MS.insert(S, S+k);
    
    std::cout << (solve() ? "Yes" : "No") << std::endl;
    return 0;
}

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

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int Max = 0;
    int dmax = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] > Max) {
            Max = a[i];
        } else {
            dmax = max(dmax, Max - a[i]);
        }
    }
    int cnt1 = 1;
    int cnt2 = 0;
    int ans = 0;
    Max = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] > Max) {
            Max = a[i];
            ans += min(cnt2, cnt1);
            cnt2 = 0;
            cnt1 = 1;
        } else if (a[i] == Max) {
            cnt1++;
        } else if (Max - a[i] == dmax) {
            cnt2++; 
        }
    }
    ans += min(cnt2, cnt1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

ll* uniformity,*partial;
int N = 1;

void init(int first_N){
	while(N < first_N)N *= 2;
}

void add_and_updateNodes(int left,int right,ll value,int node_id,int node_left,int node_right){

	if(right < node_left || left > node_right)return;
	else if(left <= node_left && right >= node_right){
		uniformity[node_id] += value;
	}else{
		partial[node_id] += (min(right,node_right)-max(left,node_left)+1)*value;
		add_and_updateNodes(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2);
		add_and_updateNodes(left,right,value,2*node_id+2,(node_left+node_right)/2+1,node_right);
	}
}

ll getSum(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return 0;
	else if(left <= node_left && right >= node_right){
		return (node_right-node_left+1)*uniformity[node_id]+partial[node_id];
	}else{
		ll sum = (min(right,node_right)-max(left,node_left)+1)*uniformity[node_id];
		sum += getSum(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		sum += getSum(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return sum;
	}
}

int main(){

	int first_N,Q;
	ll S,T;
	scanf("%d %d %lld %lld",&first_N,&Q,&S,&T);

	init(first_N);

	uniformity = new ll[540000];
	partial = new ll[540000];

	for(int i = 0; i <= 2*N-2; i++){
		uniformity[i] = 0;
		partial[i] = 0;
	}

	ll tmp,up_sum = 0,down_sum = 0,pre = 0;

	scanf("%lld",&tmp);

	for(int i = 0; i < first_N; i++){
		scanf("%lld",&tmp);

		if(tmp > pre){
			up_sum += (tmp-pre);
		}else{
			down_sum += (pre-tmp);
		}
		add_and_updateNodes(i,i,tmp,0,0,N-1);
		pre = tmp;
	}

	int L,R;
	ll X,pre_left_diff,pre_right_diff,next_left_diff,next_right_diff;

	for(int i = 0; i < Q; i++){
		scanf("%d %d %lld",&L,&R,&X);
		L--;
		R--;

		if(L == 0){
			pre_left_diff = getSum(0,0,0,0,N-1);
		}else{
			pre_left_diff = getSum(L,L,0,0,N-1)-getSum(L-1,L-1,0,0,N-1);
		}
		if(R == first_N-1){
			pre_right_diff = 0;
		}else{
			pre_right_diff = getSum(R+1,R+1,0,0,N-1)-getSum(R,R,0,0,N-1);
		}

		add_and_updateNodes(L,R,X,0,0,N-1);

		if(L == 0){
			next_left_diff = getSum(0,0,0,0,N-1);
		}else{
			next_left_diff = getSum(L,L,0,0,N-1)-getSum(L-1,L-1,0,0,N-1);
		}
		if(R == first_N-1){
			next_right_diff = 0;
		}else{
			next_right_diff = getSum(R+1,R+1,0,0,N-1)-getSum(R,R,0,0,N-1);
		}

		if(pre_left_diff <= 0){
			down_sum -= abs(pre_left_diff);
		}else{
			up_sum -= abs(pre_left_diff);
		}

		if(pre_right_diff <= 0){
			down_sum -= abs(pre_right_diff);
		}else{
			up_sum -= abs(pre_right_diff);
		}

		if(next_left_diff <= 0){
			down_sum += abs(next_left_diff);
		}else{
			up_sum += abs(next_left_diff);
		}

		if(next_right_diff <= 0){
			down_sum += abs(next_right_diff);
		}else{
			up_sum += abs(next_right_diff);
		}

		printf("%lld\n",T*down_sum-S*up_sum);

	}

	return 0;
}

Measured memory_bytes: 11424
n, k = map(int, raw_input().split())
H = [int(raw_input()) for i in range(n)]
H.sort()
min_diff = 10**9 + 1
for i in range(n - k + 1):
    diff = H[i+k-1] - H[i]
    if min_diff > diff:
        min_diff = diff
print min_diff

Measured memory_bytes: 8964
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s, t;
  cin >> s >> t;
  s += s;
  auto x = s.find(t);
  if (x == std::string::npos)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


Measured memory_bytes: 3596
#include <iostream>

using namespace std;
/*
#define sq(a) ((a) * (a))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define what_is(x) cerr << fixed << setprecision(2) << #x << " = " << x << endl
#define setbitj(n, j) (n |= (1 << (j)))
#define isbitjOn(n, j) (((n & (1 << (j))) > 0) ? 1 : 0)
#define safeMod(a, m) ((((a)%(m))+(m))%(m))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int MAX = 100005;
const int MOD = 1000000007;

inline bool isEq(double a, double b){return abs(a - b) < EPS;}
inline double toRad(double deg){return deg*PI/180;}
inline double toDeg(double rad){return rad*180/PI;}

inline int geti(int &_int){return scanf("%d", &_int);}
inline int getii(int &_int, int &_int2){return scanf("%d %d", &_int, &_int2);}
inline int getiii(int &_int, int &_int2, int &_int3){return scanf("%d %d %d", &_int, &_int2, &_int3);}

inline int getl(ll &_ll){return scanf("%lld", &_ll);}
inline int getll(ll &_ll, ll &_ll2){return scanf("%lld %lld", &_ll, &_ll2);}
inline int getlll(ll &_ll, ll &_ll2, ll &_ll3){return scanf("%lld %lld %lld", &_ll, &_ll2, &_ll3);}

inline int getd(double &_double){return scanf("%lf", &_double);}
inline int getdd(double &_double, double &_double2){return scanf("%lf %lf", &_double, &_double2);}

inline int getstr(char *str){return scanf("%s", str);}

//#define isValid(a, b) (a >= 0 && a < b)
//int dr[]  =  {0, -1, -1, -1,  0,  1, 1, 1};
//int dc[]  =  {1,  1,  0, -1, -1, -1, 0, 1};
*/
int main(int argc, char* argv[])
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    cout << 24 + (24-n);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
c = input()

w = 0
w_left = [None]*(N+1)
w_left[0] = 0
for i in range(N):
    if c[i] == 'W': w += 1
    w_left[i+1] = w

r = 0
r_right = [None]*(N+1)
r_right[N] = 0
for i in reversed(range(N)):
    if c[i] == 'R': r += 1
    r_right[i] = r

def cost(i):
    return max(w_left[i], r_right[i])

best = min(cost(i) for i in range(N+1))
print(best)


Measured memory_bytes: 77776
n,k =list(map(int,input().split()))

mod = 10**9+7
ans = 1%mod
left_combination = 1
right_combination = 1

for i in range(1,min(k,n-1)+1):
    left_combination = (left_combination*(n+1-i)*pow(i,mod-2,mod))%mod
    right_combination = (right_combination*(n-i)*pow(i,mod-2,mod))%mod
    ans = (ans + (left_combination*right_combination)%mod)%mod

print(ans)

Measured memory_bytes: 3188
//https://atcoder.jp/contests/agc041/tasks/agc041_a
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N,A,B; cin>>N>>A>>B;
    if(A>B) swap(A,B);
    ll ans=0;
    if(abs(B-A)%2==0) {
        ans= abs(B-A)/2;
    }else{
        //l
        auto l=A-1;
        //r
        auto r=N-B;
        ans += min(l,r);
        ans += 1;
        --B;
        ans+=(B-A)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

bitset<5001> bs[5001],now;
int a[5001],n;
int d[5001][5001];
int main() {
	bs[0]=now=1;
	int N,k;
	scanf("%d%d",&N,&k);
	while(N--)
	{
		int x;
		scanf("%d",&x);
		if(x<k)a[++n]=x;
	}
	fup(i,1,n,1)bs[i]=bs[i-1]|(bs[i-1]<<a[i]);
	fup(i,0,n-1,1)
	{
		d[i][0]=1;
		fup(j,1,k-1,1)d[i][j]=d[i][j-1]+bs[i][j];
	}
	int ans=0;
	fdn(i,n,1,1) 
	{
		bool ok=0;
		fup(j,0,k-1,1)
		{
			if(now[j])
			{
				int t=d[i-1][k-j-1];
				if(k-a[i]-j-1>=0)t-=d[i-1][k-a[i]-j-1];
				if(t>0)ok=1;
			}
		}
		if(!ok)ans++;
		now|=(now<<a[i]);
	}
	printf("%d",ans);
}

Measured memory_bytes: 100992
import java.util.*;
import java.io.PrintWriter;
public class Main{
	static long[] a_cum;
	static long[][] dp;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		dp=new long[n+1][n+1];
		a_cum=new long[n+1];
		for(int i=1; i<=n; i++){
			a_cum[i]=sc.nextLong()+a_cum[i-1];
		}
		System.out.println(f(1,n));
	}
	static long f(int l,int r){
		if(l==r) return 0;
		if(dp[l][r]!=0) return dp[l][r];
		long min=Long.MAX_VALUE;
		for(int i=l; i<r; i++){
			min=Math.min(min,f(l,i)+f(i+1,r));
		}
		return dp[l][r]=min+a_cum[r]-a_cum[l-1];
	}
}

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

int main(void)
{
        int A,B,i,num;
        char data[10];
        scanf("%d %d",&A,&B);
        scanf("%s",data);
        if(data[A]=='-')
        {
                num=0;
                for(i=0;data[i]!='\0';i++)
                {
                        if(data[i]>='0' && data[i]<='9')
                        {
                                num++;
                        }                                                                                                                                                                        

                }
                if(num==(A+B))  printf("Yes");
                else            printf("No");
        }else
        {
                printf("No");
        }
        return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N;
VI ps;
class SegT{
private:
  int dat[2][2 * (1 << 18) - 1];
  int NN;
  VI xs;

public:
  int mind(int x, int y){
	if(x == -1) return y;
	if(y == -1) return x;
	return (xs[x] < xs[y]? x: y);
  }

  SegT(int n_, VI& xs_){
	NN = 1;
	while(NN < n_) NN <<= 1;
	xs = xs_;
	for(int i=0;i<2*NN-1;++i) dat[0][i] = dat[1][i] = -1;
	for(int i=0;i<n_;++i)
	  dat[0][NN-1+i] = i;
	for(int i=NN-2;i>=0;--i){
	  int l = i*2+1, r = i*2+2;
	  if(r >= NN-1)
		dat[0][i] = dat[0][l];
	  else
		dat[0][i] = mind(dat[0][l], dat[0][r]);

	  if(r >= NN-1)
		dat[1][i] = dat[0][r];
	  else
		dat[1][i] = mind(dat[1][l], dat[1][r]);
	}
  }

  int query(int a, int b, int p, int k, int l, int r){
	if(r <= a || b <= l) return -1;
	if(a <= l && r <= b) return dat[(p+l-a)%2][k];
	else{
	  int m = (l+r)/2;
	  if(b <= m)
		return query(a, b, p, k*2+1, l, m);
	  if(m <= a)
		return query(a, b, p, k*2+2, m, r);
	  int vl = query(a, b, p, k*2+1, l, m);
	  int vr = query(a, b, p, k*2+2, m, r);
	  return mind(vl, vr);
	}
  }
  int query(int a, int b, int p){
	return query(a, b, p, 0, 0, NN);
  }
};

using PQ = priority_queue<PII,vector<PII>,function<bool(PII,PII)>>;
int main(){
  cin >> N;
  ps.resize(N);
  REP(i,N) cin >> ps[i];

  SegT seg(N, ps);
  /*
  while(true){
	int a, b, p;
	cin >> a >> b >> p;
	cout << seg.query(a,b,p) << endl;
  }
  */
  PQ rans([&](const PII& lhs, const PII& rhs){
	  return ps[seg.query(lhs.FF, lhs.SS, 0)] > ps[seg.query(rhs.FF, rhs.SS, 0)];
	});
  rans.push(MP(0,N));
  vector<PII> ans;

  while(!rans.empty()){
	PII ran = rans.top();
	rans.pop();
	int l = ran.FF, r = ran.SS;
	int li = seg.query(l, r, 0);
	int ri = seg.query(li, r, 1);

	ans.PB(MP(ps[li], ps[ri]));
	if(li-l)
	  rans.push(MP(l,li));
	if(ri-(li+1))
	  rans.push(MP(li+1,ri));
	if(r-(ri+1))
	  rans.push(MP(ri+1,r));
  }
  
  REP(i,N/2){
	cout << (i?" ":"") << ans[i].FF << " " << ans[i].SS;
  }
  cout << endl;
  
  return 0;
}


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

int n,ans;
char s[100010];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	ans=1;
	for (int i=2;i<=n;i++)
		if (s[i]!=s[i-1])	ans++;
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[3][3];
    int m[3][3];
    int flag=0;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
            
        }
    }
    
    int n;
    cin>>n;
    while(n--){
        int x;
        cin>>x;
        for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(a[i][j]==x)
            m[i][j]=1;
        }
    }
    }
    for(int i=0;i<3;i++){
        if(m[0][i]==1 && m[1][i]==1 && m[2][i]==1)
        flag=1;
        if(m[i][0]==1 && m[i][1]==1 && m[i][2]==1)
        flag=1;
        
    }
    if(m[0][0]==1 && m[1][1]==1 && m[2][2]==1)
    flag=1;
    if(m[0][2]==1 && m[1][1]==1 && m[2][0]==1)
    flag=1;
    if(flag==1)
    cout<<"Yes";
    if(flag==0)
    cout<<"No";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll dp[10000007];

int main(){
  string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  ll h, w;
  cin >> h >> w;
  ll curw = 0;
  ll curh = 1;
  rep(i, h * w){
    string s;
    cin >> s;
    if(s=="snuke"){
      cout << a[curw] << curh << endl;
      return 0;
    }
    curw++;
    if(curw==w){
      curw = 0;
      curh++;
    }
  }
}

Measured memory_bytes: 3604
#include <stdio.h>

void drawline(char head, char body, int width)
{
	int i;

	i = 1;
	while(i <= width)
	{
		if(i == 1 || i == width)
			printf("%c", head);
		else
			printf("%c", body);
		i++;
	}
	printf("\n");
}

int main(void)
{
	int height, width;		//Value H, W.
	int i;

	while(1)
	{
		scanf("%d %d", &height, &width);
		if(height == 0 && width == 0)
			return (0);

		i = 1;
		while(i <= height)
		{
			if(i == 1 || i == height)
				drawline('#', '#', width);
			else
				drawline('#', '.', width);
			i++;
		}

		printf("\n");
	}

	return (0);
}



Measured memory_bytes: 2048
#create date: 2020-06-30 09:34

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a, b = ns().split()
    a = int(a)
    b = int(float(b)*100+0.5)
    print(a*b//100)

if __name__ == "__main__":
    main()


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

int main(){
 
  string str;
  cin >> str;
  
  for(int i=0;i<3;i++){
	if(str[i] == '1'){
      str[i] = '9';
    }
    else if(str[i] == '9'){
      str[i] = '1';
    }
  }
  cout << str;
}

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

#define fi first
#define se second

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

const ll D = 100007;

pii a[D];

int main()
{
    ll n, m, ans = 0;
    cin >> n >> m;
    for (ll i = 1; i <= n; i++)
        cin >> a[i].fi >> a[i].se;
    sort(a + 1, a + n + 1);

    for (ll i = 1; i <= n; i++)
        ans += min(a[i].se, m) * a[i].fi, m -= min(a[i].se, m);
    cout << ans << endl;
}


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

Measured memory_bytes: 256
# A0611
# Silk Road
# @kankichi573
s = STDIN.gets.split
$n = s[0].to_i
$m  = s[1].to_i
$d = Array.new($n)
$c = Array.new($m)
$table = Array.new($n+1){Array.new($m+1,-1)}

0.upto($n-1){|i|
  $d[i] = STDIN.gets.split[0].to_i}
0.upto($m-1){|i|
  $c[i] = STDIN.gets.split[0].to_i
}

def solve(pos,dat)
  if $table[pos][dat] != -1
    $table[pos][dat]
  elsif(pos==$n)
    0
  elsif(dat==$m)
    ret = 2**31-1
  else
    # printf("%d %d\n",pos,dat)
    # printf("%d\n",$d[pos])
    # printf("%d\n",$c[dat])
    ret1 = $d[pos]*$c[dat] + solve(pos+1,dat+1) 
    ret2 = solve(pos,dat+1)
    
    ret=$table[pos][dat]=if ret1 > ret2
                          ret2
                        else
                          ret1
                        end
    ret
  end
end
puts solve(0,0)

Measured memory_bytes: 15116
#include <iostream>
#include <vector>

int gcd(int x,int y){
    if(x % y == 0){
        return y;
    }
    return gcd(y, x%y);
}

int main(){
    using namespace std;
    int MAX_A = 1000000;
    vector<int> lp(MAX_A+1,0);//最小の素因数をいれる(2以上をみていけばいい)
    vector<int> pr;//MAX_A以下の素数の集合
    int cnt=0;
    vector<int> count(MAX_A+1,0);
    for(int i = 2; i <= MAX_A; i++){//線形時間で処理してくれる
        if(lp[i] == 0){
            lp[i] = i;
            pr.push_back(i);
        }
        for(int j = 0; j < pr.size()&& pr[j] <= lp[i]&& i * pr[j] <= MAX_A; j++){
            lp[i * pr[j]] = pr[j];//i * pr[j] == C(const)としてありえるi, jの組は高々一通りになるので、これは線形時間で処理される
        }
    }
    int N;
    cin >> N;
    vector<int> A(N);
    int GCD = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        GCD = gcd(GCD, A[i]);
        while(A[i]>1){
            int div = lp[A[i]];
            count[div]++;
            while(A[i] % div == 0){
                A[i] /= div;
            }
        }
    }
    if(GCD != 1){
        cout << "not coprime" << endl;
        return 0;
    }
    for(int i = 2; i < MAX_A; i++){
        if(count[i] >= 2){
            cout << "setwise coprime" << endl;
            return 0;
        }
    }
    cout << "pairwise coprime" << endl;
}

Measured memory_bytes: 15520
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;

int main() {
    long long N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];

    vector<long long> S(N, 0), T(N, 0);
    for(int i=0; i<N; ++i) {
        for(int j=0; j<N; ++j) {
            if(A[i] > A[j]) {
                S[i] += 1;
                if(i < j) T[i] += 1;
            }
        }
    }

    long long res = 0;
    for(int i=0; i<N; ++i) {
        res = (res + K * T[i] % MOD) % MOD;
        res = (res + S[i] * (((K - 1) * K / 2LL) % MOD) % MOD) % MOD;
    }
    cout << res % MOD << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  map<string,int> cnt;
  for(int i;i<N;i++){
    string s;
    cin>>s;
    cnt[s]++;
  }
  for(string s:{"AC","WA","TLE","RE"}){
    cout<<s<<" x "<<cnt[s]<<endl;
  }
  return 0;
}  

Measured memory_bytes: 3632
#include <stdio.h>

void normalization(int *w, int *h)
{
    int t;
    
    if (*w < *h){
        t = *w;
        *w = *h;
        *h = t;
    }
}

int main(void)
{
    int W, H, C;
    int m, n, t;
    
    scanf("%d%d%d", &W, &H, &C);

    normalization(&W, &H);
    
    m = W;
    n = H;
    while (n != 0){
        t = m % n;
        m = n;
        n = t;
    }
    printf("%d\n", W / m * H / m * C);
    
    return (0);
}




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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main(void)
{
	IOS;
	int n,q; cin>>n>>q;
	set<pair<int,int>> hor, ver;
	hor.insert({n,n});
	ver.insert({n,n});
	int black = (n-2)*(n-2);
	int seenup[n+1] = {}, seendown[n]={};
	while(q--) {
		int ty,x; cin>>ty>>x;
		if(ty==1) {
			if(seenup[x])
				continue;
			seenup[x]=1;
			ii p = *hor.lower_bound({x,-1});
			// cout<<p.ss<<endl;
			ver.insert({p.ss,x});
			// cout<<p.ss<<" "<<x<<endl;
			black -= (p.ss-2);
		} else {
			if(seendown[x])
				continue;
			seendown[x]=1;
			ii p = *ver.lower_bound({x,-1});
			black -= (p.ss-2);
			// cout<<p.ss<<endl;
			hor.insert({p.ss,x});
			// cout<<p.ss<<" "<<x<<endl;
		}
		// cout<<"black = "<<black<<endl;
	}
	cout<<black<<endl;
	return 0;
}

Measured memory_bytes: 19192
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val n = sc.nextInt()
    val p = Array(n) { sc.nextInt() }

    var min = 3e5.toInt()
    var ans = 0
    for (i in 0 until n) {
        if (p[i] <= min) {
            ans += 1
            min = p[i]
        }
    }
    println(ans)
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<int> B(N);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  vector<int> X(N + 1);
  for (int i = 1; i < N + 1; i++) {
    X.at(i) = X.at(i - 1) + A.at(i - 1);
  }
  vector<int> Y(N + 1);
  for (int i = 1; i < N + 1; i++) {
    Y.at(i) = Y.at(i - 1) + B.at(i - 1);
  }
  int ans = 0;
  for (int i = 1; i < N + 1; i++) {
    ans = max(ans, X.at(i) + (Y.at(N) - Y.at(i - 1)));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3556
def resolve():
    N = int(input())
    S = [input() for _ in range(N)]
    counter = {
        "AC": 0,
        "WA": 0,
        "TLE": 0,
        "RE": 0,
    }
    for i in range(N):
        counter[S[i]] += 1

    for k, v in counter.items():
        print(f"{k} x {v}")

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 16160
s = input()

ans = True

while len(s) > 0:
    if len(s) == 1:
        print('No')
        exit(0)
    if s[0] == 'h' and s[1] == 'i':
        s = s[2:]
    else:
        ans = False
        break

if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
# coding:utf-8

import math
import re

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def main(params):
    n = params
    a = make_divisors(n)
    total = 0
    for i in a:
        if i - 1 >= 2 and i -1 > n  / i:
            total += i - 1
    print total

if __name__ == "__main__":
    params = int(raw_input())
    #cnt = 1 # TODO: edit here
#    params = []
#    for i in range(n):
#        param = raw_input()
#        params.append(param)
    main(params)



Measured memory_bytes: 34436
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll MOD = 998244353;
const ll inf = 1e18;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll n, m;
    cin >> n >> m;
    vector<P> p(n);
    ll a, b;
    REP(i, n) {
        cin >> a >> b;
        p[i] = {a, b};
    }
    VSORT(p);

    // 期限がカツい日にできる仕事は限定的なので後ろ側からどの仕事をいれたら良いか考える
    // que : その日入れられる仕事の報酬リスト
    // p を a の昇順で並べて b を que に入れていく
    // 期限を巻き戻すほど入れられる仕事が増える
    priority_queue<ll> que;
    ll res = 0, d = m, id = 0;
    REPR(d, m) {
        while (id < n && d + p[id].first <= m) {
            que.push(p[id].second);
            id++;
        }
        if (!que.empty()) {
            res += que.top();
            que.pop();
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2936
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

var H, W, K int
var s []string

func solve(h, w int) int {
	ret := 0
	// fmt.Printf("%b %b\n", h, w)
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if h>>i%2 == 0 && w>>j%2 == 0 {
				if s[i][j] == '#' {
					ret++
				}
			}
		}
	}
	// out(ret)
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	H, W, K = getInt(), getInt(), getInt()
	s = make([]string, H)
	for i := 0; i < H; i++ {
		s[i] = getString()
	}

	h := 1 << H
	w := 1 << W

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			k := solve(i, j)
			if k == K {
				ans++
			}
		}
	}
	out(ans)
}


Measured memory_bytes: 1776
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(a > b){
			int tmp = a;
				a = b;
				b = tmp;
		}
		if(b > c){
			int tmp = b;
				b = c;
				c = tmp;
		}
		if(a > b){
			int tmp = a;
				a = b;
				b = tmp;
		}
		System.out.println(a + " " + b + " " + c);
		
		sc.close();

	}

}

Measured memory_bytes: 26132
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
const int maxn=10050,maxm=20050,inf=0x3f3f3f3f;
struct Edge
{
    int to,next,dis,cos ;
}edge[maxm*2];
struct Pair
{
    int D,V,C;
    Pair(){;}
    Pair(int d,int c,int v)
    {
        D=d,V=v,C=c;
    }
    friend bool operator <(const Pair a,const Pair b)
    {
        if(a.D!=b.D)
        return a.D>b.D;
        else return a.C>b.C;
    }
};
int tot,head[maxn],dist[maxn],cost[maxn];
bool vis[maxn];
void init()
{
    tot=0;
    memset(head,-1,sizeof(head));
}
void add_edge(int u,int v,int d,int c)
{
    edge[tot].to=v;
    edge[tot].dis=d;
    edge[tot].cos=c;
    edge[tot].next=head[u];
    head[u]=tot++;
}
int dijstra(int start)
{
    memset(vis,false,sizeof(vis));
    memset(dist,inf,sizeof(dist));
    int ans=0;
    dist[start]=0;
   // vis[start]=true;
    priority_queue<Pair>que;
    que.push(Pair(0,0,start));
    while(!que.empty())
    {
        Pair now=que.top();
        que.pop();
        if(vis[now.V])
            continue;
        vis[now.V]=true;
        ans+=now.C;
        for(int i=head[now.V];i!=-1;i=edge[i].next)
        {
            int to=edge[i].to;
            que.push(Pair(now.D+edge[i].dis,edge[i].cos,to));
        }
    }
    return ans;
}
int main()
{
    int u,v,d,c;
    int n,m;
    while(scanf("%d%d",&n,&m)!=-1)
    {
        init();
        if(n==0&&m==0)break;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d%d",&u,&v,&d,&c);
            add_edge(u,v,d,c);
            add_edge(v,u,d,c);
        }
        printf("%d\n",dijstra(1));
    }
    return 0;
}

Measured memory_bytes: 2544
N = int(input())
A = list(map(int, input().split()))
B = [i // 400 for i in A if i < 3200]
if B == []:
  print(1, N)
elif len(B) == N:
  C = len(set(B))
  print(C, C)
else:
  C = len(set(B))
  D = C + N - len(B)
  print(C, D)

Measured memory_bytes: 9128
LEN = 0

SNK = [1,2,3,4,5,6,7,8,9]
#SNK.append("SUNUKE!:"+str(1))
LEN +=1

for i in range(1,10): SNK.append(i*10+9)
#SNK.append("SUNUKE!:"+str(2))
LEN +=1

#for i in range(1,10): SNK.append(i*100+99)
#SNK.append("SUNUKE!:"+str(3))
LEN +=1

for loop in range(2):
    SNK_sub = list(range(pow(10,loop),pow(10,loop+1)))
    SNK += list(map(lambda x:(x*pow(10,LEN-1))+(pow(10,LEN-1)-1),SNK_sub))
    LEN += len(str(max(SNK_sub)))-1
    for d in SNK_sub: #loop=0のとき，d=1-9
        SNK += [(i*pow(10,LEN-1))+(pow(10,LEN-1)-1) for i in range(10,10*(d+1))]
        SNK += list(map(lambda x:(x*pow(10,LEN))+(pow(10,LEN)-1),SNK_sub[SNK_sub.index(d)+1:]))
        #SNK.append("SUNUKE!:"+str(LEN+3))
        LEN += 1+loop
        if LEN>20:break

print("\n".join(str(i) for i in SNK[:int(input())]))

Measured memory_bytes: 3064
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    int max = Math.max(a, Math.max(b, c));
    for(int i = 0; i < k; i++){
      max *= 2;
    }
    int sum = a + b + c + max - Math.max(a, Math.max(b, c));
    System.out.println(sum);
  }
}

Measured memory_bytes: 21716
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a[4],u[10],h,b,t; while(cin>>a[0]){
    rep(i,10)u[i]=0; h=0,b=0;
    rep(i,3)cin>>a[i+1]; rep(i,4)u[a[i]]=1;
    rep(i,4){
      cin>>t; if(a[i]==t)h++;
      if(u[t])b++;
    }
    cout<<h<<" "<<b-h<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
a,b=map(int,input().split())
if (2*b-a)%3==0 and (2*a-b)%3==0 and (2*b-a)>=0 and (2*a-b)>=0:
  n=(2*b-a)//3
  m=(2*a-b)//3
  p = 10**9+7
  def nCr(n,r):
    if r*2>n:
        return nCr(n,n-r)
    else:
        a = b = 1
        for i in range(r):
            a = a * (n - i) % p
            b = b * (r - i) % p
        return (a * pow(b,p-2,p)) % p

  print(nCr((m+n),m))
else:
  print(0)

Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math
from collections import deque

N, K = map(int, input().split())
P = list(map(int, input().split()))

def expected(x):
    s = 0
    if x % 2 == 1:
        s = x * math.ceil(x / 2)
    else:
        s = (x + 1) * (x / 2)

    return s / x

b = {}
mx = 0
# 前回分
q = deque()
p = 0

for i in range(N - K + 1):
    s = 0
    # 初回は全部計算
    if i == 0:
        for j in range(K):
            k = i + j
            if not P[k] in b:
                b[P[k]] = expected(P[k])
            s += b[P[k]]
            # 順番に保持
            q.append(b[P[k]])
    else:
        # 追加分
        k = i + (K - 1)
        if not P[k] in b:
            b[P[k]] = expected(P[k])
        # シフト
        f = q.popleft()
        q.append(b[P[k]])

        # 計算
        s = p - f + b[P[k]]

    # 最大更新
    mx = max(mx, s)
    # 前回分として保持
    p = s

print(mx)


Measured memory_bytes: 25564
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        sc.close();

        int end = Math.min(b, d);
        int start = Math.max(a, c);

        if (end - start > 0) {
            System.out.println(end - start);
        } else {
            System.out.println(0);
        }
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;

  int sum = 0;
  for (int i = 1; i <= N; i++) {
	int x;
    cin >> x;
    
    sum += min(x, K - x) * 2;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int X, Y, kame, turu;

    cin >> X >> Y;

    kame = (Y/2) - X;
    turu = X - kame;

    if(kame>=0 && turu>=0 && X==kame+turu && Y==2*turu+4*kame) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
    
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
      int n, k, d, a[105];
      cin >> n >> k;
      memset(a, 0, sizeof(a));
      while(k--)
      {
            cin >> d;
            while(d--)
            {
                  int temp;
                  cin >> temp;
                  a[temp]=1;
            }
      }
      int ans=0;
      for (int i=1; i<=n; i++)
      {
            if (a[i]==0)
                  ans++;
      }cout << ans << endl;
 	return 0;
}


Measured memory_bytes: 3612
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define LL long long
#define int LL
const LL inf=0x3f3f3f3f;
using namespace std;
template<typename tp> inline void read(tp &x)
{
	x=0; char c=getchar(); bool f=0;
	for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());
	if(f) x=-x;
}
int k,zz;
char s[1000];
signed main()
{
	scanf("%s",s+1);
	read(k);
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
		if(s[i]=='1')
			zz++;
		else break;
	if(k<=zz) puts("1");
	else printf("%c\n",s[zz+1]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
//typedef pair<int,int>P;
const int INF=10101;
const int H_MAX=8;
const int W_MAX=8;
vector< vector<char> > G(H_MAX,vector<char>(W_MAX));
vector< vector<bool> > P(H_MAX,vector<bool>(W_MAX,false));
bool flag=false;
int h,w;

void dfs(int i,int j )
{
    
    P[i][j]=true;
    if(G[i][j]=='.')return;
    if(i==h-1 && j==w-1)
    {
        flag=true;
        return;
    }
    if(G[i][j+1]!='.' && j+1<w)
    {
        dfs(i,j+1);
    }
    else if(G[i+1][j]!='.' && i+1<h)
    {
        dfs(i+1,j);
    }
    return;
}


int main()
{
    
    
    cin>>h>>w;
    rep(i,h)rep(j,w)
    {
        cin>>G[i][j];
    }
    dfs(0,0);
    bool printflag=true;
    rep(i,h)rep(j,w)
    {
        if(G[i][j]=='#' && !P[i][j])
        {
            printflag=false;
        }
    }
    if(flag && printflag)
    {
        cout<<"Possible";
    }
    else
    {
        cout<<"Impossible";
    }
}

Measured memory_bytes: 888
#include <stdio.h>

int main(void){

  int x,y,z;

  printf("");
  scanf("%d %d %d",&x,&y,&z);

  if (x>y&&y>z){
    printf("%d %d %d\n",z,y,x);
  } else if (x>z&&z>y){
    printf("%d %d %d\n",y,z,x);
  } else if (y>x&&x>z){
    printf("%d %d %d\n",y,x,z);
  } else if (y>z&&z>x){
    printf("%d %d %d\n",x,z,y);
  } else if (z>x&&x>y){
    printf("%d %d %d\n",y,x,z);
  } else if (z>y&&y>x){
    printf("%d %d %d\n",x,y,z);
  } else if (x>y&&y==z){
    printf("%d %d %d\n",y,z,x);
  } else if (y>x&&x==z){
    printf("%d %d %d\n",z,x,y);
  } else if (z>x&&x==y){
    printf("%d %d %d\n",x,y,z);
  } else if (x==y&&y>z){
    printf("%d %d %d\n",z,y,x);
  } else if (x==z&&z>y){
    printf("%d %d %d\n",y,x,z);
  } else if (y==z&&z>x){
    printf("%d %d %d\n",x,y,z);
  } else if (x==y&&y==z){
    printf("%d %d %d\n",x,y,z);
  }

  return 0;
}

  

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   int z_i = 0, a_i = 200005;
   rep(i, 0, s.size()) {
      if (s[i] == 'Z')
         chmax(z_i, i);
      else if (s[i] == 'A')
         chmin(a_i, i);
   }
   int ans = z_i - a_i + 1;
   cout << ans << endl;
   return 0;
}

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

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

  int ans = 0;
  int cnt = 0;
  for(int i = 0; i < n; i++){
    if(p[i] == i + 1) cnt++;
    else{
      if(cnt % 2 == 0) ans += cnt / 2;
      else ans += cnt / 2 + 1;
      cnt = 0;
    }
  }
  if(cnt % 2 == 0) ans += cnt / 2;
  else ans += cnt / 2 + 1;

  cout << ans << endl;
}


Measured memory_bytes: 640
#include "iostream"
using namespace std;

int main()
{
	
	int n, x;
	//cin >> n >> x;
	//int i, j, k;
	int sum;
	
	while (1){

		cin >> n >> x;
		if (n == 0&&x==0)break;
		int c = 0;
		for (int i = 1; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				for (int k = j + 1; k <= n; k++) {
					sum = i + j + k;
					if (sum==x){
						c++;
					}
					

				}
			}
		}
		cout << c << endl;
	}

	return 0;
}



Measured memory_bytes: 3068
module Mochi = Set.Make(Int32)

let main () =
  let n = Scanf.scanf "%d\n" Batteries.identity in
  let xs = Array.make n 0 in
  for i = 0 to n - 1 do
    xs.(i) <- Scanf.scanf "%d\n" Batteries.identity;
  done;
  let mochi = Array.fold_left (fun acc elm -> Mochi.add (Int32.of_int elm) acc) Mochi.empty xs in
  Printf.printf "%d\n" @@ BatList.length (Mochi.elements mochi)

let _ = main ()


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

using namespace std;

int main(){
    int n; cin >> n;
    n *= 2;
    vector<int> a(n);
    
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    
    sort(a.begin(),a.end());
    
    int sum = 0;
    
    for(int i = 0 ; i < n ; i++){
        if(i % 2 == 0)
            sum += a[i];
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 256
s = input()
f = 0
for i in range(len(s)):
    if (i%2 == 0 and s[i] != "h") or (i%2 == 1 and s[i] != "i"):
        print("No")
        f = 1
        break
if f == 0 and (len(s) == 1 or len(s)%2 == 1):
    print("No")
    f = 1
if f == 0:
    print("Yes")

Measured memory_bytes: 3060