akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long 
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  nds; 
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int pow(int x, int y)
{ 
	if(y==0)return 1;
	int u=pow(x,y/2);
	u=u*u;
	if(y%2)u=x*u;
	return u;
    
}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
	
	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
signed main()
{
	IOS
	int l,r,d;
	cin>>l>>r>>d;
	cout<<r/d-(l-1)/d ;
	
}



Measured memory_bytes: 3672
#!/usr/bin/ruby
H,W=gets.split.map &:to_i;p [[H,W],[W,H]].map{|h,w|(1..h/2).map{|i|
	x,y=[w*i,w/2*(h-i),(w-w/2)*(h-i)].minmax
	z,q=[i*w,(h-i)/2*w,(h-i-(h-i)/2)*w].minmax
	[y-x,q-z].min
}.min}.min

Measured memory_bytes: 2684
#include <stdio.h>
int main(void){
    int n,i,x=0;
    int a[100000]={};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        if((a[a[i]-1]==i+1)&&i<a[i]){
            x++;
        }
    }
    printf("%d\n",x);
    return 0;
}

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

int main(){
	int n;
	while(cin >> n && n){
		int ans = 1;
		int s[3]={1,2,3};
		for(int i=0;i<n;i++){
			string str;
			cin >> str;
			if(str=="North"){
				int tmp = s[0];
				s[0] = s[1];
				s[1] = 7 - tmp;
			}
			else if(str=="East"){
				int tmp = s[2];
				s[2] = s[0];
				s[0] = 7 - tmp;
			}
			else if(str=="West"){
				int tmp = s[0];
				s[0] = s[2];
				s[2] = 7 - tmp;
			}
			else if(str=="South"){
				int tmp = s[1];
				s[1] = s[0];
				s[0] = 7 - tmp;
			}
			else if(str=="Right"){
				int tmp = s[1];
				s[1] = s[2];
				s[2] = 7 - tmp;
			}
			else {
				int tmp = s[2];
				s[2] = s[1];
				s[1] = 7 - tmp;
			}
			ans += s[0];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(ll i=0; i<n; i++)
#define all(v) v.begin(), v.end()
#define vec vector
typedef long long ll;
const int INF = 1001001001;

/*　<<stringで読み込んだ数列を一桁ずつint型へ変換>>
 
    string str;
    int N[桁数];
 
    cin >> str;
 
    for (int i = 0; i < 桁数; ++i) {
 
        N[i] = (int)(str[i] - '0');  //str[i]　はchar型なのでchar→intへ変換
 
        //cout << N[i] << endl;  //確認のため表示
    }
*/
 


///////////////////////////////////////////////////////////////////////////


int main() {

    string N;
    cin >> N;


    if(N.at(N.size()-1) == '2' || N.at(N.size()-1) == '4' || N.at(N.size()-1) == '5' || N.at(N.size()-1) == '7'|| N.at(N.size()-1) == '9'){
        cout << "hon" << endl;
    }

    else if(N.at(N.size()-1) == '0' || N.at(N.size()-1) == '1'  || N.at(N.size()-1) == '6' || N.at(N.size()-1) == '8'){
        cout << "pon" << endl;
    }

    else{
        cout << "bon" << endl;
    }
}


Measured memory_bytes: 3624
N = int(input())
*H, = map(int, input().split())

T = [0]*N
ans = 0
i = 0
while i<N:
    #積み上げるべきスタート地点を探す
    if T[i]<H[i]:
        start = i
        high  = T[i]+1
        ans = ans + 1
        i = 0
        for j in range(start, N, 1):
            if T[j]<H[j] and (T[j]+1==high):
                T[j] = T[j] + 1
            else:
                break
    else:
        i = i + 1

print(ans)

Measured memory_bytes: 3064
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

l = list(map(int, input().split()))
N=l[0]
X=l[1]
x=[0]*N
A=[0]*N
l = list(map(int, input().split()))
for i in range(N):
    x[i] = l[i]
    A[i] = abs(X-x[i])
g=A[0]
for i in range(N):
    g = gcd(g, A[i])
print(g)

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

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int total=0;
    for(int i=0;i<n;i++){
        int max=0,max_i = i;
        for(int j=0;j<n;j++){
            if(max < a[j]){
                max = a[j];
                max_i=j;
            }
        }
        if(i%2)
            total -= a[max_i];
        else
            total += a[max_i];
        a[max_i] = 0;
    }
    cout << total << endl;
    return 0;
}

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

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
///////////////////

int const N = 1e5 + 41;
int const INF = 1e9 + 41;

int k, ans;

int d[N][2];

struct State{
	int d, r, w;
	State(){};
	State(int d, int r, int w) : d(d), r(r), w(w) {};
	bool operator<(const State &a) const {
		if(d != a.d) return d < a.d;
		if(r != a.r) return r < a.r;
		return (w < a.w);
	};
};

void solve(){
	fi(0, N) fj(0, 2) d[i][j] = INF;
	d[0][0] = 0;
	set<State> t;
	t.insert(State(0, 0, 0));
	while(sz(t)){
		State cur = (*t.begin());
		t.erase(cur);
		int r = cur.r;
		int w = cur.w;
		fi(0, 10){
			int nr = (r * 10 + i) % k;
			int nw = w;
			if(i) nw = 1;
			if(d[nr][nw] > d[r][w] + i){
				t.erase(State(d[nr][nw], nr, nw));
				d[nr][nw] = d[r][w] + i;
				t.insert(State(d[nr][nw], nr, nw));
			}
		}
	}
	ans = d[0][1];
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&k);

	solve();

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 6016
import sys
input = sys.stdin.readline
from collections import Counter

MAX = 2*10**6+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
    
for i in range(2, MAX):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD

def C(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD

K = int(input())
S = input()[:-1]
N = len(S)
ans = 0

for i in range(K+1):
    ans += C(N+K-i-1, N-1)*pow(26, i, MOD)*pow(25, K-i, MOD)
    ans %= MOD
    
print(ans)

Measured memory_bytes: 137424
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1001001001001001001LL;
typedef pair<int,int>P;
struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b){}
};

int N,M,X;
int H[100000];

vector<edge>G[100000];
int dist[100000];

signed main(){
    cin>>N>>M>>X;
    for(int i=0;i<N;i++)cin>>H[i];
    for(int i=0;i<M;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].push_back(edge(b,c));
        G[b].push_back(edge(a,c));
    }

    fill_n(dist,N,INF);

    priority_queue<P,vector<P>,greater<P> >que;
    que.push(P(0,0));
    dist[0]=0;
    while(que.size()){
        P p=que.top();que.pop();
        if(dist[p.second]<p.first)continue;
        int h=(p.first>=X?0:X-p.first);

        for(int i=0;i<G[p.second].size();i++){
            edge &e=G[p.second][i];
            if(H[p.second]<e.cost)continue;
            int cost;
            if(h-e.cost>H[e.to])cost=h-H[e.to];
            else if(h-e.cost>=0)cost=e.cost;
            else cost=e.cost-(h-e.cost);
            if(dist[e.to]<=p.first+cost)continue;
            dist[e.to]=p.first+cost;
            que.push(P(dist[e.to],e.to));
        }
    }
    if(dist[N-1]==INF)cout<<-1<<endl;
    else cout<<dist[N-1]+H[N-1]-(dist[N-1]>=X?0:X-dist[N-1])<<endl;
    return 0;
}

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

typedef pair<int,int> PII;
typedef long long ll;

int main(){
	int a,b,k;
	cin>>a>>b>>k;

	vector<int> d;
	
	for (int i = 1; i <= 100; ++i){
		if(a%i==0&&b%i==0){
		d.push_back(i);
	}
	}
	
	cout<<d[d.size()-k]<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ll d,n; cin >> d >> n;
  
  if(d==0){
    if(n<100){
      cout << n << endl;
      return 0;
    }
    else{
      cout << n+1 << endl;
      return 0;
    }
  }
  if(d==1){
    if(n<100){
      cout << 100*n << endl;
      return 0;
    }
    else{
      cout << 100*n+100<< endl;
      return 0;
    }
  }
  if(d==2){
    if(n<100){
      cout << 10000*n << endl;
      return 0;
    }
    else{
      cout << 10000*n+10000 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3580
#include <iostream>
int ans[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 8, 8, 11, 11, 11, 11, 14, 14, 32, 32, 35, 35, 35, 35, 42, 42, 42, 42, 49, 49, 49, 49, 49, 49, 75, 75, 86, 86, 86, 86, 86, 86, 123, 123, 131, 131, 131, 131, 148, 148, 153, 153, 170, 170, 170, 170, 170, 170, 227, 227, 227, 227, 227, 227, 250, 250, 323, 323, 324, 324, 324, 324, 354, 354, 354, 354, 384, 384, 384, 384, 384, 391, 491, 491, 529, 529, 529, 529, 529, 529, 543};

int main()
{
    int N;
    std::cin >> N;
    std::cout << ans[N - 1] << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int h, w, i, j;
  while(1) {
  scanf("%d %d", &h, &w);
  if ((h == 0) && (w == 0))
    break;
  for ( i = 0; i < h; i++) {
    for ( j =0; j < w; j++) {
      printf("#");
    }
    printf("\n");
  }
  printf("\n");
  }

  return 0;

}

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

typedef long long ll;
const ll mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<vector<ll>> dp(n,vector<ll>(n,0));
    for (int i = 0;i < n;++i) dp[0][i] = 1;
    for (int i = 0;i < n-1;++i) {
        vector<ll> sums(n+1,0);
        for (int j = 0;j < n;++j) sums[j+1] = (sums[j]+dp[i][j])%mod;
        if (s[i] == '<') for (int j = 0;j < n-i-1;++j) dp[i+1][j] = (sums[j+1]-sums[0])%mod;
        else for (int j = 0;j < n-i-1;++j) dp[i+1][j] = (sums[n]-sums[j+1])%mod;
    }
    cout << (dp[n-1][0]+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

#define ll long long

int main() {
	int N; cin >> N;
	vector<vector<int>> v(N);
	if(N%2>0){
	    v[0].push_back(N);
	    for(int i=1; i<N; ++i) v[min(i, N-i)].push_back(i);
	}
	else for(int i=1; i<=N; ++i) v[min(i-1, N-i)].push_back(i);
	int ans;
	if(N%2>0) ans=(N-1)*(N-1)/2;
	else ans=N*(N/2-1);
	cout << ans << endl;
	for(int t=0; t<v.size(); ++t){
	    for(int u=t+1; u<v.size(); ++u){
	        for(int bit=0; bit<v[t].size()*v[u].size(); ++bit){
	            cout << v[t][bit/2] << ' ' << v[u][bit%2] << endl;
	        }
	    }
	}
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1<<29;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 

void solve(){
     int n, ret;
     cin >> n;
     vector<int> a(n);
     for(auto& it : a) cin >> it;
     sort(all(a));
     double check = a[n-1]*1.000/2;
     int mn=INF;
     for(int i = 0; i < n-1; i++){
		  if (abs(a[i] - check) < mn)
		     {
				 mn = abs(a[i] - check); 
				 ret = a[i];
			 }
		}
    cout << a[n-1] << " " << ret << endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define $ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define endl "\n"
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    $
    int n;
    cin >> n;
    int freq[n+1] = {0};
    for (int i = 1 ; i<n ; i++) {
        int x;cin >> x;
        freq[x]++;
    }
    for (int i = 1 ; i<=n ; i++) {
        cout << freq[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007LL;
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
//________________________________________
signed main()
{
       int k;
       cin>>k;
       while(k--)
       {
              cout<<"ACL";
       }
}


Measured memory_bytes: 3632
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

string s;
int a,b;

int main()
{
	cin>>s;
	a=atoi(s.substr(5,2).c_str());
	b=atoi(s.substr(8,2).c_str());
	if(a<=4) puts("Heisei");
	else puts("TBD");
	rt0;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
S = Hash.new(0)
gets.split.map(&:to_i).inject(0){|s,v| ((s + v) % M).tap{|mod| S[mod] += 1} }
puts S.inject(0){|s,(k,v)| s + v*(v-1)/2 + (k == 0 ? v : 0)}



Measured memory_bytes: 14724
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>
#include <algorithm>
using namespace std;

bool check(int x) {
    string str = to_string(x);
    for (auto ch : str) {
        if (ch != str[0]) return false;
    }
    return true;
}

int main() {
    int n;
    cin>>n;
    while (!check(n)) ++n;
    cout<<n;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N, A, B;
    cin >> N >> A >> B;
    int res = 0;
    for(int i = 1; i<=N; i++) {
        int sum = 0;
        int tmp = i;
        while (tmp > 0) {
            sum += tmp % 10;
            tmp /= 10;
        }
        if(A <= sum && B >= sum) res += i;
    }
    cout << res << endl;
    return 0;
}

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

#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 998244353;

#define int ll
const int N = 3e5 + 10;
int ar[N];
int L[N] , R[N];
int tree[N << 2];
//range update and point query
inline void add(int & x , int y){
    x = (x % MOD + y % MOD) % MOD;
}
void upd(const int &ql , const int &qr , const int &v , int l = 0 , int r = N , int t=1){
    if(l > qr || r < ql)
        return;
    if(l >= ql && r <= qr){
        add(tree[t] , v);
        return;
    }
    int mid = (l + r) >> 1;
    upd(ql , qr , v , l , mid , t << 1);
    upd(ql , qr , v , mid + 1 , r , t << 1 | 1);
}

int qry(const int &pos , int l = 0 , int r = N , int t = 1){
    if(l == r)
        return tree[t];
    
    int mid = (l + r) >> 1;

    if(pos <= mid)
        return (tree[t] + qry(pos , l , mid , t << 1) % MOD) % MOD;
    else
        return (tree[t] + qry(pos , mid + 1 , r , t << 1 | 1) % MOD) % MOD;
}

signed main(){

#ifndef ONLINE_JUDGE
	//freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int n , k;
    cin >> n >> k;
    fo(i , k) cin >> L[i] >> R[i];
    
    upd(1 , 1 , 1);
    for(int i = 1 ; i <= n ; i++){
        ar[i] = qry(i);
        if(i == n)
            break;
        for(int j = 0 ; j < k ; j++)
            upd(min(n + 1 , i + L[j]) , min(n + 1 , i + R[j]) , ar[i]);
    }
    cout << ar[n] << '\n';
    

    return 0;
}



Measured memory_bytes: 10696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  int N, M;
  cin >> N >> M;
  ll a[N], b[N];
  ll c[M], d[M];
  for(int i=0; i<N; i++){
    cin >> a[i] >> b[i];
  }
  for(int i=0; i<M; i++){
    cin >> c[i] >> d[i];
  }  
  
  for(int i=0; i<N; i++){
    ll ans = 4e9;
    int idx = N+1;
    for(int j=0; j<M; j++){
      ll tmp = abs(a[i] - c[j]) + abs(b[i] -d[j]);
	  if(tmp < ans){       
        ans = tmp;
        idx = j;
      }
    }
    cout << (idx + 1) << endl; 
  }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    vector<ll> p(N);
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
        p[i]++; // 1 足しておく
    }

    // 累積和
    vector<ll> s(N+1, 0);
    for (int i = 0; i < N; ++i)
    {
        s[i+1] = s[i] + p[i];
    }

    // K 差を見ていく
    ll res = 0;
    for (int i = 0; i+K <= N; ++i)
    {
        res = max(res, s[i+K] - s[i]);
    }

    cout << fixed << setprecision(10) << (double)(res)/2 << endl;
    return 0;
}

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

int main() {
    long long N,a,b,c;
    cin >> N;
    c = pow(N,0.5)+1;
    for(int i=1;i<=c;i++) {
        if(N%i==0) {
            a = i;
        }
    }
    b = N/a;
    cout << a+b-2 << endl;
}

Measured memory_bytes: 256
class DualSegmentTree():

    def __init__(self, n, op, e):
        """
        :param n: 配列の要素数
        :param op: 作用素（モノイド＝結合則＋単位元存在）
        :param e:  単位元
        """
        self.n = n
        self.op = op
        self.e = e
        self.size = 1 << (self.n - 1).bit_length()
        self.lazy = [self.e] * (self.size << 1)

    def update(self, l, r, x):
        """
        半開区間 [l, r) の値を x に更新 （ 0-indexed ）　（ O(logN) ）
        """
        l += (self.size - 1)
        r += (self.size - 1)
        self.propagate(l)
        self.propagate(r-1)
        while l < r:
            if r&1 == 0:
                r -= 1              # 半開区間なので先に引いてる
                self.lazy[r] = self.op(x, self.lazy[r])
            if l&1 == 0:
                self.lazy[l] = self.op(x, self.lazy[l])
                l += 1
            l = (l - 1) // 2
            r = (r - 1) // 2

    def propagate(self, i):
        """
        根から葉に伝搬させる。可換モノイドの場合は更新時の伝搬をサボれる。　（ O(logN) ）
        """
        tmp = []
        while i>0:
            i -= 1
            i >>= 1
            tmp.append(i)
        for x in reversed(tmp):
            if self.lazy[x] == self.e:
                continue
            self.lazy[2*x+1] = self.op(self.lazy[x], self.lazy[2*x+1])
            self.lazy[2*x+2] = self.op(self.lazy[x], self.lazy[2*x+2])
            self.lazy[x] = self.e

    def get(self, i):
        """
        i 番目の値を取得（ 0-indexed ） ( O(logN) )
        """
        i += (self.size - 1)
        self.propagate(i)
        return self.lazy[i]

    def __getitem__(self, i):
        return self.get(i)

    def __iter__(self):
        for x in range(self.size-1):
            if self.lazy[x] == self.e:
                continue
            self.lazy[2*x+1] = self.op(self.lazy[x], self.lazy[2*x+1])
            self.lazy[2*x+2] = self.op(self.lazy[x], self.lazy[2*x+2])
            self.lazy[x] = self.e
        for a in self.lazy[self.size-1:self.size-1+self.n]:
            yield a

    def __str__(self):
        for x in range(self.size-1):
            if self.lazy[x] == self.e:
                continue
            self.lazy[2*x+1] = self.op(self.lazy[x], self.lazy[2*x+1])
            self.lazy[2*x+2] = self.op(self.lazy[x], self.lazy[2*x+2])
            self.lazy[x] = self.e
        return str(self.lazy[self.size-1:self.size-1 + self.n])

##################################################################################################################
import sys
from bisect import *
input = sys.stdin.readline

N, Q = map(int, input().split())

e = -1
op = lambda x, y: x if x != e else y
st = DualSegmentTree(Q, op, e)

Qu = [list(map(int, input().split())) for _ in range(N)]
Qu.sort(key=lambda x:x[2], reverse=True)

D = [int(input()) for _ in range(Q)]

for q in Qu:
    S, T, X = q
    L = bisect_left(D,S-X)
    R = bisect_left(D,T-X)
    st.update(L, R, X)
print(*st, sep="\n")

Measured memory_bytes: 145564
#include <iostream>
#include <cmath>
#include <tuple>
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  int WA[105000];
  bool AC[105000];
  int WAnum = 0;
  int ACnum = 0;
  for(int i = 1; i <= n; i++){
    WA[i] = 0;
    AC[i] = false;
  }
  while(m--) {
    int p;
    string s;
    cin >> p >> s;
    if(AC[p]) continue;
    if(s == "AC") {
      AC[p] = true;
      ACnum++;
      WAnum += WA[p];

    }else if (s == "WA"){
      WA[p]++;
    }
  }
  cout << ACnum << " " << WAnum << endl;
}


Measured memory_bytes: 768
n = int(input())
lis=[]
for i in range(n):
    lis.append(int(input()))

lis.sort()

count=0
while len(lis)>1:
    if lis[0]==lis[1]:
        del lis[:2]
    else:
        del lis[0]
        count+=1
print(count+len(lis))

Measured memory_bytes: 7388
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
C.append(0)
m = sum(B)
for i in range(N-1):
  if A[i]+1 == A[i+1]:
    m = m+C[A[i]-1]
print(m)

Measured memory_bytes: 3060
n = int(input())

pl = [int(((4**i) - 1)/3) for i in range(1,20)]
mi = [int(-2 * ((4**i) - 1)/3) for i in range(20,0,-1)]
plli = [int(4 ** i) for i in range(20)]
mili = [int(-2 * (4**i)) for i in range(19,-1,-1)]
li = []

import bisect

def func(n):
    if n == 0:
        return None
    elif n > 0:
        inde = bisect.bisect_left(pl,n)
        li.append(2*inde + 1)
        m = n-plli[inde]
        func(m)
    else:
        inde = bisect.bisect_right(mi,n)
        li.append((20 - inde + 1) * 2 )
        m = n-mili[inde-1]
        func(m)

if n == 0:
    print(0)
else:
    func(n)
    lis2 = []
    for i in range(li[0]):
        lis2.append("0")
    for a in li:
        lis2[-a] = "1"
    st = "".join(lis2)
    print(st)

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

using namespace std;

#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
int main() {
    //OJ;
    int x,y;
    cin>>x>>y;
    if(y%2!=0){
        cout<<"No";
        return 0;
    }
    if(y<=x*4&&y>=x*2){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
	return 0;
}

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

int two(int x) {
    return x * x;
}
int main() {
    int x1, y1; cin >> x1 >> y1;
    int x2, y2; cin >> x2 >> y2;
    int x3, y3, x4, y4;
//    int x1 = 2, y1 = 3, x2 = 6, y2 = 6;
    int i, j;

    x3 = x2 - (y2 -y1);
    y3 = x2-x1 + y2;
    x4 = x1 - (y2 - y1);
    y4 = (y2-y1) * (-1) + y3;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = [input() for _ in range(n)]
s = set(l)
if(len(l) != len(s)):
    print('No')
    exit()
for i in range(1,n):
    if(l[i][0] != l[i-1][-1]):
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3060
import java.util.*;

public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K =sc.nextInt();
		int X =sc.nextInt();
		if(500 * K >= X) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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

int main(){
  int a, b;
  cin >> a >> b;
  if(a == b) cout << "Draw" << endl;
  else if(a == 1 || (a > b && b != 1)) cout << "Alice" << endl;
  else if(b == 1 || (a < b && a != 1)) cout << "Bob" << endl;
  return 0; 
}

Measured memory_bytes: 768
N, M = map(int,input().split())
p = []
S = []
for i in range(M):
    a, b = map(str,input().split())
    a = int(a)
    p.append(a)
    S.append(b)
ac_ans = 0
pn_ans = 0
tmp_dict = dict()
ac_dict = dict()
pn_dict = dict()
for i in range(N):
    ac_dict[i] = 0
    pn_dict[i] = 0
    tmp_dict[i] = 0

for i in range(M):
    if S[i] == "AC":
        tmp_dict[p[i]-1] = pn_dict[p[i]-1]
        if ac_dict[p[i]-1] == 0:
            ac_dict[p[i]-1] += 1
        else:
            pass
    else:
        if ac_dict[p[i]-1] == 0:
            pn_dict[p[i]-1] += 1
        else:
            pass
for i in range(N):
    ac_ans += ac_dict[i]
for i in range(N):
    pn_ans += tmp_dict[i]
ac_ans = str(ac_ans)
pn_ans = str(pn_ans)
print(ac_ans + " " + pn_ans)

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

using namespace std;

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

	bool swapped= false;
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int tmp;
		cin >> tmp;
		if (tmp == i && !swapped) 
		{ 
			ans++;
			swapped = true;
		}
		else swapped = false;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int gcd(int a,int b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

int N;

int main()
{
	cin >> N;
	ll a[N];
	REP(i,N){
		cin >> a[i];
	}
	map<int, int> mp;
	for (int i = 0; i < N; i++)
		mp[a[i]]++;
 
	int ans = 0;
	for (auto p: mp) {
		int x = p.first;
		int n = p.second;
		if (n < x) ans += n;
		else ans += n - x;
	}
 
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5504
N, A, B = map(int, input().split())
ans = []
for i in range(N + 1):
    j = i
    tmp = j % 10 
    while (j // 10) > 0 :
        j //= 10
        tmp += j % 10
    if tmp >= A and tmp <= B:
        ans.append(i)
print(sum(ans))

Measured memory_bytes: 3280
local n = io.read("*n")
local f = false
for i = 1, 3500 do
  for j = 1, 3500 do
    local numer = n * i * j
    local denom = 4 * i * j - n * (i + j)
    if 0 < denom and numer % denom == 0 then
      print(i .. " " .. j .. " " .. math.floor(numer / denom))
      f = true
      break
    end
  end
  if f then break end
end


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

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

/********************Template********************/

int n, a[100000], cnt = 0;
bool flag[100000] = {0};

bool check(int i){
	if(i == 1) rtn true;
	if(flag[i]) rtn false;
	flag[i] = true;
	cnt++;
	rtn check(a[i]-1);
}
signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	REP(i, n) cin >> a[i];
	if(check(0)) cout << cnt << endl;
	else cout << -1 << endl;
	rtn 0;
}

Measured memory_bytes: 768
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        long x=sc.nextLong();
        long ans=2*(x/11);
        long tmp=x%11;
        if(tmp>0){
            if(tmp<=6){
            ans++;
            }else{
                ans+=2;
            }
        }
        out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n, z, w;
    scanf("%d%d%d", &n, &z, &w);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a.at(i));
    if (n == 1) printf("%d\n", abs(w - a.front()));
    else printf("%d\n", max(abs(a.at(n - 1) - a.at(n - 2)), abs(w - a.at(n - 1))));
    return 0;
}


Measured memory_bytes: 256
<?php
list($s) = strs();
for ($i = 0; $i < strlen($s); ++$i) {
    $chr[$s[$i]] = true;
}
for ($i = 0; $i < 26; ++$i) {
    if (!isset($chr[chr(97 + $i)])) {
        echo chr(97 + $i);
        exit;
    }
}
echo 'None';
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


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

template<class T, class U = size_t> class Dinic{
    struct Edge{ U to, rev_edge_index; T cap; };
    U n;
    vector<vector<Edge>> g;
public:
    explicit Dinic(U n) : n(n), g(n) {}
    void add_edge(U from, U to, T c, T c2 = 0){
        if(from == to) return;
        g[from].push_back({to, g[to].size(),       c});
        g[to].push_back({from, g[from].size() - 1, c2});
    }
    void add_undirected_edge(U from, U to, T c){ add_edge(from, to, c, c); }
    T max_flow(U source, U sink){
        vector<U> dist(n);
        auto bfs = [&](){
            dist.assign(n, 0);
            dist[source] = 1;
            queue<U> q; q.push(source);
            while (!q.empty()){
                auto cur = q.front(); q.pop();
                for(auto&& e : g[cur]) if(e.cap > 0 && dist[e.to] == 0) {
                    dist[e.to] = dist[cur] + 1;
                    q.push(e.to);
                }
            }
            return dist[sink] > 0;
        };
        vector<U> ptr(n); // ????????????????????????????????§??¢?´¢??????????????????
        function<T(U, T)> dfs = [&](U cur, T lim) {
            if(source == cur || lim == 0) return lim;
            T sum_f = 0;
            for(auto &i = ptr[cur]; i < g[cur].size(); ++i){
                auto &e = g[cur][i], &rev_e = g[e.to][e.rev_edge_index];
                if(dist[e.to] >= dist[cur] || rev_e.cap <= 0) continue;
                T f = dfs(e.to, min(lim - sum_f, rev_e.cap));
                if(f <= 0) continue;
                rev_e.cap -= f; e.cap += f;
                sum_f += f;
                if(sum_f == lim) break;
            }
            return sum_f;
        };
        T sum_f = 0;
        while(bfs()){
            ptr.assign(n, 0);
            sum_f += dfs(sink, numeric_limits<T>::max()/8);
        }
        return sum_f;
    }
};

int main() {
    int v, e;
    cin >> v >> e;
    Dinic<int> g(v);
    REP(i, e) {
        int u, v, c; cin >> u >> v >> c;
        g.add_edge(u, v, c);
    }
    cout << g.max_flow(0, v - 1) << endl;
}

Measured memory_bytes: 3212
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

func primeFactors(n int) map[int]int {
	pfs := make(map[int]int)
	for n%2 == 0 {
		pfs[2]++
		n = n / 2
	}
	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs[i]++
			n = n / i
		}
	}
	if n > 2 {
		pfs[n]++
	}

	return pfs
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	A, B := sc.nextInt(), sc.nextInt()
	G := gcd(A, B)
	pfs := primeFactors(G)

	fmt.Fprintln(wtr, len(pfs)+1)
	wtr.Flush()
}


Measured memory_bytes: 640
open Printf open Scanf
open Array

let cost = [|0;2;5;5;4;5;6;3;7;6|]

let () = scanf " %d %d" @@ fun n m ->
  let a = init m (fun _ -> scanf " %d" @@ fun v -> v) in
  let maxstr u v =
    match compare (String.length u) (String.length v) with
    |  1 -> u
    | -1 -> v
    | _ -> max u v
  in
  let dp = make (n+1) "" in
  dp.(n) <- "0";
  for j=n downto 0 do
    if dp.(j) <> "" then (
      iter (fun i ->
        let c = cost.(i) in
        if j-c >= 0 then
          dp.(j-c) <- maxstr
            dp.(j-c)
            (dp.(j) ^ (string_of_int i))
      ) a
    )
  done;
  (* iter (print_endline) dp; *)
  print_string @@ String.(sub dp.(0) 1 (length dp.(0) - 1))


Measured memory_bytes: 59552
//
// ABC119A
//

#include <iostream>
using namespace std;

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

	string t = a.substr(0,7);

	if (t <= "2019/04") cout << "Heisei" << endl;
	else               cout << "TBD" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
using ping = pair<ll, ll>;

int main(){
    ll X;
    cin >> X;
    ll cnt500 = 0;
    for (int i = 1;; i++) {
      if (i * 500 > X) break;
      else
        cnt500++;
    }
    X = X - cnt500 * 500;
    ll cnt5 = 0;
    for (int i = 1;; i++) {
      if (i * 5 > X) break;
      else
        cnt5++;
    }
    cout <<cnt500 * 1000 + cnt5 * 5 << endl;
    return 0;
}

Measured memory_bytes: 3636
//ABC094A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int a, b, x;
	cin >> a >> b >> x;
	if(a <= x && a+b >= x){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	int n, w;
	cin >> n >> w;

	vector<vector<int>> v(n, vector<int>(2));

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

	//sort(v.begin(), v.end());
	vector<vector<int>> dp(w + 1, vector<int>(n + 1));

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

	cout << dp[w][n] << endl;
	return 0;
}

Measured memory_bytes: 82304
def main():
    INF = float('inf')
    N,W = map(int,input().split())
    wv = [list(map(int,input().split())) for _ in range(N)]
    sumv = sum([v for w,v in wv])
    dp = [[INF]*(sumv+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(sumv+1):
            if j-wv[i][1] >= 0:
                dp[i+1][j] = min(dp[i][j],dp[i][j-wv[i][1]]+wv[i][0])
            else:
                dp[i+1][j] = dp[i][j]
    ans = 0
    for i in range(sumv+1):
        if dp[N][i] <= W:
            ans = max(ans,i)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 300904
#include<bits/stdc++.h>
# define ll long long
# define mo 1000000009
using namespace std;
int main()
{
	int n,k,x=0;
	cin>>n>>k;
	while(n>0)
	{
		x++;
		n=n/k;
	}
	cout<<x;
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n;
    cin >> n;

    put(n * (n - 1) / 2);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3600
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 d = sc.nextInt();

    while(true){
      c = c - b;
      if(c<1){
        System.out.println("Yes");
        return;
      }
      a = a - d;
      if(a<1){
        System.out.println("No");
        return;
      }
    }





  }
}

Measured memory_bytes: 35728
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int ans = k*x + (n-k)*y;
  if (n < k) ans = n*x;
  cout << ans << endl;
}

Measured memory_bytes: 3556
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	while (true) {
		int n = -1, k = -1;
		cin >> n >> k;
		if (n <= 0 || k <= 0) break;
		vector<int> p(n + 1, n), conseq(n);
		for (int i = 0; i < n; ++i) {
			cin >> p[i];
		}
		int cnt = 0, ans = 0;
		for (int i = n - 1; i >= 0; --i) {
			if (p[i] >= p[i + 1]) {
				cnt = 0;
			}
			conseq[i] = ++cnt;
			if (conseq[i] >= k) {
				ans = 1;
			}
		}
		set<int> s(p.begin(), p.begin() + k);
		ans += conseq[0] < k;
		for (int i = k; i < n; ++i) {
			int low = *(s.begin());
			s.erase(p[i - k]);
			int high = *(s.rbegin());
			if ((low != p[i - k]) || (p[i] < high)) {
				ans += conseq[i - k + 1] < k;
			}
			s.insert(p[i]);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 11136
//#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
//#define int long long
#define double long double
#define vec vector
#define vi vector<int>
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first
#define S second
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first, l.second+r.second};
} 
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
// Init variables here

void input() {
}

int n;
const int MAXN = 100002;
vi adj[MAXN];
vi color(MAXN, -1); 
map<ii, int> mat;

void dfs(int s, int e) { // s - cur node, e - prev node
	// process node s
	if(s==1) color[s-1] = 0;
	if(s!=1) {
		color[s-1] = (color[e-1] + mat.at(make_pair(e, s)))%2;
	}
	
//	cout << s << " processed, color is:" << endl;
//	FORE(i, 1, n) cout << color[i-1] << ", ";
//	cout << endl;
	
	for (auto u : adj[s]) {
		if (u != e) dfs(u, s);
	}
}

void solve() {
	cin >> n;
	
//	cout << " n = " << n << endl;
	
	FORE(i, 1, n-1) {
		
//		cout <<  " i = " << i << endl;
		
		int u, v, w; cin >> u >> v >> w;
		mat.insert(make_pair(make_pair(u, v), w%2));
		mat.insert(make_pair(make_pair(v, u), w%2));
		adj[u].PB(v); 	adj[v].PB(u);
	}
	
//	cout << "Adj list:" << endl;
//	FORE(i, 1, n) {
//		cout << " adj to " << i << endl;
//		for(auto x : adj[i]) cout << x << ", ";
//		cout << endl;
//	}
//	
//	cout << "Map:" << endl;
//	for(auto m : mat) cout << m.F.F << " " << m.F.S << ", " << m.S << endl;
	
	
	dfs(1, 0);
	FOR(i, 0, n) cout << color[i] << endl;
}

//#undef int
signed main() {
//#define int long long
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

  //int t; cin >> t;
  //while (t--) 
  {
    input();
    solve();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



Measured memory_bytes: 20864
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    vector<int> ans(N);
    vector<int> rs;
    for(int i=0; i<N-1; i++){
        if(S[i] == 'R' && S[i+1] == 'L')
            rs.push_back(i);
    }
    for(int r : rs){
        int rr = 0, ll = 0;
        for(int i=r; i>=0; i--){
            if(S[i] == 'L') break;
            if((r-i)%2==0)rr++;
            else ll++;
        }
        for(int i=r+1; i<N; i++){
            if(S[i] == 'R') break;
            if((i-(r+1))%2==0)ll++;
            else rr++;
        }
        ans[r] = rr;
        ans[r+1] = ll;
    }
    for(int i=0; i<N; i++)
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

K, T = two_int()

A=many_int()

A = sorted(A)

maxs = A[-1]
other = sum(A[:-1])

if maxs <= other:
    print(0)
else:
    print(maxs-other-1)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(ll i=1;i<(n);i++)
#define rrep(i,n) for(ll i=0;i<(n);i++)
int main() {
	ll a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	a[0] = a[2] - a[0];
	a[1] = a[2] - a[1];
	a[2] = 0;
	ll ans = a[1];
	a[0] -= a[1];
	if (a[0] % 2 == 0) {
		ans += a[0] / 2;
	}
	else {
		ans += a[0] / 2;
		ans += 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
const int maxn = 1e5;
LL n,num[maxn+5];
int cmp (int x,int y){
	return x>y;
}
int main(){
	for(int i = 0;i<3;i++)
		cin >> num[i];
	sort(num,num+3);
	if(num[2]%2==0)
		cout << 0 << endl;
	else
		cout << num[1]*num[0] << endl;
	return 0;  
}

Measured memory_bytes: 256