akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.StringTokenizer;

public class Main{
	public static void main(String [] args) throws IOException{
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st = new StringTokenizer(br.readLine());

		int x = Integer.parseInt(st.nextToken());
		int y = Integer.parseInt(st.nextToken());
		int i = 0;
		while(i <= x){
			if(2*i + (x-i)*4 == y){
				break;
			}
			i++;
		}

		bw.write((i <= x ? "Yes" : "No"));
		bw.flush();
		bw.close();
		br.close();
	}
}

Measured memory_bytes: 32492
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>


using namespace std;

int main(){
    int A,B;
    cin>>A>>B;

    if(A>2*B){
        cout<<A-2*B<<endl;
    }

    else if(A<=2*B){
        cout<<0<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			double h = sc.nextLong();
			double n = sc.nextInt();
			
			for(int i = 0 ; i < n ; i++ )  {
				h -= sc.nextLong();
				if ( h <= 0 ) {
					System.out.println("Yes");
					return;
				}
			}
			System.out.println("No");			
		}
	}
}

Measured memory_bytes: 47924
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,x,y;
	cin>>n>>x>>y;
	x--;y--;
	vl ans(n);
	rep(i,n)range(j,i+1,n){
		ll dist=min(j-i,abs(x-i)+abs(y-j)+1);
		ans[dist]++;
	}
	range(i,1,n)cout<<ans[i]<<"\n";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if(a+b > c+d)
    printf("Left\n");
  else if(a+b == c+d)
    printf("Balanced\n");
  else if(a+b < c+d)
    printf("Right\n");
}

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

int main() {
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;

  REP(i, n) {
    cout << s[i] << t[i];
  }

  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int dp[n];
    int ans=0;
    for(int i=n-1;i>=0;i--)
    {
        dp[i]=0;
        if(i!=n-1 && arr[i+1] <= arr[i])
        dp[i] = dp[i+1]+1;
        ans = max(ans,dp[i]);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 1024
import java.math.BigInteger;
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long answer = 1;
        for(long i =1;i<=n;i++){
            answer *=i;
            answer %= 1000000007;
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 23764
def isop(s):
    if s == "+" or s == "-" or s == "*":
        return True
    return False


def main():
    line = list(input().split())
    stack = []
    while len(line) > 0:
        tmp = line.pop(-1)
        if isop(tmp):
            stack.append(tmp)
        else:
            stack.append(int(tmp))
        while len(stack) > 2 and isop(stack[-1]) == False and isop(stack[-2]) == False:
            num1 = stack.pop(-1)
            num2 = stack.pop(-1)
            op = stack.pop(-1)
            if op == "+":
                stack.append(num1 + num2)
            elif op == "-":
                stack.append(num1 - num2)
            else:
                stack.append(num1 * num2)

    print(*stack)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
#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;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll dp[222222][2];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	ll ans=0;
	int n=s.length();
	for(int i=n-1;i>=0;i--)
	{
		dp[i][1]=s[i]-'0'+dp[i+2][1];
		dp[i][0]=dp[i+1][1];
	}
	int prezeroes=0; int id=-1;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='0') prezeroes++;
		else
		{
			id=i; break;
		}
	}
	if(id==-1){cout<<0<<'\n'; return 0;}
	string t = s.substr(id,n-id);
	n=t.length();
	vi runs;
	int cur=0;
	vi ones;
	while(cur<n)
	{
		ones.pb(cur+id);
		if(cur==n-1)
		{
			runs.pb(0); break;
		}
		int nxt=cur+2;
		while(nxt<n&&t[nxt]=='0')
		{
			nxt++;
		}
		runs.pb(nxt-(cur+1));
		cur=nxt;
	}
	for(int i=0;i+1<runs.size();i++) runs[i]--;
	ll cursum=0;
	for(int i=0;i<runs.size();i++)
	{
		cursum++;
		ans+=cursum;
		if(i+1<runs.size()) ans+=cursum;
	}
	/*
	for(int x:runs)
	{
		cerr<<x<<' ';
	}
	cerr<<'\n';
	for(int x:ones)
	{
		cerr<<x<<' ';
	}
	cerr<<'\n';
	*/
	for(int i=0;i<runs.back();i++) ans+=cursum; //spam the last run first
	//cerr<<ans<<'\n';
	for(int i=int(runs.size())-2;i>=0;i--)
	{
		ll presum=i+1;
		//cerr<<runs[i]<<' '<<presum<<'\n';
		for(int j=0;j<runs[i];j++)
		{
			ans+=presum+dp[ones[i+1]][j%2];
		}
	}
	for(int i=0;i<prezeroes;i++)
	{
		ans+=dp[id][i%2];
	}
	cout<<ans<<'\n';
}


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

int main(){
    string str;
    getline(cin, str);
    for(int i = 0; i < str.length() - 4; i++){
        if(str.substr(i, 5) == "apple"){
            str.replace(i, 5, "peach");
        }else if(str.substr(i, 5) == "peach"){
            str.replace(i, 5, "apple");
        }
    }
    cout <<str <<endl;
    return 0;
}

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

int main()
{
    int n, m; cin>>n>>m;
    vector<int> a(m), b(m);
    for(int i=0; i<m; ++i) {
        cin>>a[i]>>b[i];
        --a[i], --b[i];
    }
    int res=0;
    for(int i=0; i<m; ++i) {
        vector<vector<int>> g(n);
        vector<bool> vis(n);
        function<void(int)> dfs=[&](int v)->void
        {
            vis[v]=true;
            for(int u: g[v]) if (!vis[u]) dfs(u);
        };
        for(int j=0; j<m; ++j) if (i!=j) {
            g[a[j]].push_back(b[j]);
            g[b[j]].push_back(a[j]);
        }
        dfs(0);
        res+=count(begin(vis), end(vis), false)>0;
    }
    cout<<res<<endl;
}


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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while(true){
        C -= B;
        if(C <= 0){
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if(A <= 0){
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3624
import numpy as np
n, w = map(int, input().split())
dp = np.zeros(w+1)

for i in range(1,n+1): #n個の荷物をそれぞれ持つか否か
  wn, vn = map(int, input().split())
  dp[wn:] = np.maximum(dp[wn:], dp[:-wn]+vn)#wnより小さい=>持てない=>価値変わらない
print(int(dp[-1]))

Measured memory_bytes: 15480
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string x;
    while(cin >> x) {
        int x_sum = 0;
        if (x == "0") {
            break;
        }
        REP(i, x.size()) {
            x_sum += (x[i] - '0');
        }
        cout << x_sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
import java.util.Scanner;

class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[]$){
		long
		i=g(),
		o=g(),
		t=g(),
		j=g(),
		l=g(),
		S=g(),
		z=g();
		long r=l/2*2+j/2*2+i/2*2;
		if(l>0&&j>0&&i>0)
			r=Math.max(r,3+(l-1)/2*2+(j-1)/2*2+(i-1)/2*2);
		System.out.println(r+o);
	}
	static long g(){
		return s.nextLong();
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
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;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void OUT(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void OUT(T t,Ts... ts){cout<<t<<" ";OUT(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type FILL(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type FILL(T&t,const V&v){for(auto &e:t)FILL(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int N;
	cin>>N;
	map<string,int>mp;
	REP(i,N){
		string s;
		cin>>s;
		mp[s]++;
	}
	int ans = mp["E869120"];
	OUT(ans);
}


Measured memory_bytes: 3348
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();
            var a = Reads();
            double di = a.Sum()/2.0;
            long sum = 0;
            double min = double.MaxValue;
            for (int i = 0; i < n; i++)
            {
                sum += a[i];
                min = Math.Min(min, Math.Abs(di - sum));
            }
            Console.WriteLine(min * 2);

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 37200
void main()
{
    dchar c = rdElem!dchar;

    writeln((c + 1).to!dchar);
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

using namespace std;
// using namespace atcoder;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    ll ans = 0;
    rep2(a, 1, N + 1) {
        for (ll b = 1; a * b <= N - 1; b ++) {
            ans ++;
        }
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int sum=0;
    sum+=n/100000000;
    sum+=(n/10000000)%10;
    sum+=(n/1000000)%10;
    sum+=(n/100000)%10;
    sum+=(n/10000)%10;
    sum+=(n/1000)%10;
    sum+=(n/100)%10;
    sum+=(n/10)%10;
    sum+=n%10;
    if(n%sum==0)puts("Yes");
    else puts("No");
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  double x[N];
  string u[N];
  double ans=0;
  for(int i=0; i<N; i++){
    cin >> x[i] >> u[i];
    if(u[i]=="JPY") ans+= x[i];
    else ans+= 380000*x[i];
  }
  cout << std::setprecision(18) << ans << endl;  
}

Measured memory_bytes: 256
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<cmath>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mkp(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
    //IO;
    string s,t;
    cin>>s>>t;
    int res=1e9;
    for(int i=0;i+t.size()<=s.size();i++)
    {
        int cnt=0;
        for(int j=0;j<t.size();j++) 
            if(s[j+i]!=t[j]) cnt++;
        res=min(cnt,res);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3624
/*
 * g.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_D = 20;

typedef long long ll;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

struct Stat {
  ll c;
  int d, i;
  Stat() {}
  Stat(ll _c, int _d, int _i): c(_c), d(_d), i(_i) {}
  bool operator<(const Stat &s) const {
    return c > s.c || (c == s.c && d > s.d);
  }
};

/* global variables */

int ts[MAX_N];
vpii nbrs[MAX_N];
ll costs[MAX_N];
int dists[MAX_N], prts[MAX_N][MAX_D];

/* subroutines */

/* main */

int main() {
  int n, m;
  int tmp = scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) tmp = scanf("%d", &ts[i]);

  for (int i = 0; i < m; i++) {
    int ai, bi, ci;
    tmp = scanf("%d%d%d", &ai, &bi, &ci);
    ai--, bi--;
    nbrs[ai].push_back(pii(bi, ci));
    nbrs[bi].push_back(pii(ai, ci));
  }

  for (int i = 0; i < n; i++) costs[i] = LINF;
  costs[0] = 0;
  dists[0] = 0;
  prts[0][0] = -1;

  priority_queue<Stat> q;
  q.push(Stat(0, 0, 0));

  while (! q.empty()) {
    Stat u = q.top(); q.pop();
    if (costs[u.i] != u.c || dists[u.i] != u.d) continue;

    int vd = u.d + 1;
    vpii &nbru = nbrs[u.i];

    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      ll vc = u.c + vit->second;

      if (costs[vi] > vc) {
	costs[vi] = vc;
	dists[vi] = vd;
	prts[vi][0] = u.i;
	q.push(Stat(vc, vd, vi));
      }
      else if (costs[vi] == vc) {
	if (dists[vi] > vd) {
	  dists[vi] = vd;
	  prts[vi][0] = u.i;
	  q.push(Stat(vc, vd, vi));
	}
	else if (dists[vi] == vd && ts[prts[vi][0]] > ts[u.i]) {
	  prts[vi][0] = u.i;
	}
      }
    }
  }

  for (int d = 1; d < MAX_D; d++)
    for (int i = 0; i < n; i++) {
      int j = prts[i][d - 1];
      prts[i][d] = (j < 0) ? -1 : prts[j][d - 1];
    }

  int k;
  tmp = scanf("%d", &k);

  while (k--) {
    int xi, di, pi;
    tmp = scanf("%d%d%d", &xi, &di, &pi);
    xi--;

    int r = dists[xi] - di;
    int yi = xi;
    //printf("xi=%d,di=%d,pi=%d: costs=%lld,dists=%d,r=%d\n",
    //xi, di, pi, costs[xi], dists[xi], r);

    if (r > 0)
      for (int d = MAX_D - 1; d >= 0; d--)
	if (r & (1 << d)) yi = prts[yi][d];
    //printf("  yi=%d\n", yi);
    
    ll cost = costs[xi] - costs[yi];
    if (cost < costs[xi] - pi) cost = costs[xi] - pi;

    printf("%lld\n", cost);
  }

  return 0;
}

Measured memory_bytes: 28244
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,k;cin>>n>>k;
  vl sum(n+1);
  vl resum(n+1);
  sum[0]=0;
  resum[n]=n;
  for(ll i=1;i<=n;i++){
    sum[i]=sum[i-1]+i;
  }
  for(ll i=n-1;i>=0;i--){
    resum[i]=resum[i+1]+i;
  }
  ll ans=0;
  for(ll i=k-1;i<=n;i++){
    ans+=resum[n-i]-sum[i]+1;
    //cout<<resum[n-i]<<" "<<sum[i]<<endl;
    ans%=MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6428
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	vector<int> L(N);
	REP(i, N) cin >> L[i];
	sort(L.begin(), L.end());

	int sum = 0;
	REP(i, N - 1) sum += L[i];

	if (L[N - 1] < sum) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
const long long INF = 1LL << 60;
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 main(){
    int N, K;
    cin >> N >> K;
    vector<long long> h(N), d(N);
    rep(i, N) cin >> h.at(i);
    rep(i, N) d.at(i) = INF;

    d.at(0) = 0;
    for(int i=0;i<N;i++){
        for(int j=1;j<=K;j++){
            if(i+j>=N) break;
            chmin(d.at(i+j),d.at(i) + abs(h.at(i) - h.at(i+j)));
        }
    }
     
    cout << d.at(N-1) << endl;
    return 0;
}


Measured memory_bytes: 4844
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimze("02")
using namespace std;
using ll =long long;
const ll  maxn=4e5+5,inf=1e9+5;
ll  n,m,q,a[100],b[100],c[100],d[100],i[11],ans,m2;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n>>m>>q;
	for(int j=0;j<q;j++){
		cin>>a[j]>>b[j]>>c[j]>>d[j];
	}
	for( i[1]=1;i[1]<=m;i[1]++){
		for( i[2]=i[1];i[2]<=m;i[2]++){
			if(n==2){
				m2=0;
				for(int j=0;j<q;j++){
					if(i[b[j]]-i[a[j]]==c[j]){
						m2+=d[j];
					}
				}
				ans=max(ans,m2);
				continue;
			}
			for( i[3]=i[2];i[3]<=m;i[3]++){
				if(n==3){
					m2=0;
					for(int j=0;j<q;j++){
						if(i[b[j]]-i[a[j]]==c[j]){
							m2+=d[j];
						}
					}
					ans=max(ans,m2);
					continue;
				}
				for( i[4]=i[3];i[4]<=m;i[4]++){
					if(n==4){
						m2=0;
						for(int j=0;j<q;j++){
							if(i[b[j]]-i[a[j]]==c[j]){
								m2+=d[j];
							}
						}
						ans=max(ans,m2);
						continue;
					}
					for( i[5]=i[4];i[5]<=m;i[5]++){
						if(n==5){
				m2=0;
				for(int j=0;j<q;j++){
					if(i[b[j]]-i[a[j]]==c[j]){
						m2+=d[j];
					}
				}
				ans=max(ans,m2);
				continue;
			}
						for( i[6]=i[5];i[6]<=m;i[6]++){
							if(n==6){
				m2=0;
				for(int j=0;j<q;j++){
					if(i[b[j]]-i[a[j]]==c[j]){
						m2+=d[j];
					}
				}
				ans=max(ans,m2);
				continue;
			}
							for( i[7]=i[6];i[7]<=m;i[7]++){
								if(n==7){
				m2=0;
				for(int j=0;j<q;j++){
					if(i[b[j]]-i[a[j]]==c[j]){
						m2+=d[j];
					}
				}
				ans=max(ans,m2);
				continue;
			}
								for( i[8]=i[7];i[8]<=m;i[8]++){
									if(n==8){
				m2=0;
				for(int j=0;j<q;j++){
					if(i[b[j]]-i[a[j]]==c[j]){
						m2+=d[j];
					}
				}
				ans=max(ans,m2);
				continue;
			}
									for( i[9]=i[8];i[9]<=m;i[9]++){
										if(n==9){
				m2=0;
				for(int j=0;j<q;j++){
					if(i[b[j]]-i[a[j]]==c[j]){
						m2+=d[j];
					}
				}
				ans=max(ans,m2);
				continue;
			}
										for( i[10]=i[9];i[10]<=m;i[10]++){
											if(n==10){
				m2=0;
				for(int j=0;j<q;j++){
					if(i[b[j]]-i[a[j]]==c[j]){
						m2+=d[j];
					}
				}
				ans=max(ans,m2);
				continue;
			}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout<<ans;
}


Measured memory_bytes: 3592
// E - Flatten

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

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct ModInt {
	long long val;
	constexpr ModInt(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr ModInt operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr ModInt operator + (const ModInt& r) const noexcept { return ModInt(*this) += r; }
	constexpr ModInt operator - (const ModInt& r) const noexcept { return ModInt(*this) -= r; }
	constexpr ModInt operator * (const ModInt& r) const noexcept { return ModInt(*this) *= r; }
	constexpr ModInt operator / (const ModInt& r) const noexcept { return ModInt(*this) /= r; }
	constexpr ModInt& operator += (const ModInt& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr ModInt& operator -= (const ModInt& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr ModInt& operator *= (const ModInt& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr ModInt& operator /= (const ModInt& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const ModInt& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const ModInt& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const ModInt<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr ModInt<MOD> modpow(const ModInt<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

const int MOD = 1000000007;
using mint = ModInt<MOD>;

vector<pair<ll, ll>> prime_factorize(ll n) {
	vector<pair<ll, ll> > result;
	for (ll p=2; p*p<=n; p++) {
		if (n % p != 0) continue;
		ll num = 0;
		while (n % p == 0) {
			num++;
			n /= p;
		}
		result.push_back(make_pair(p, num));
    }
    if (n != 1) {
    	result.push_back(make_pair(n, 1));
    }
    return result;
}

int A[10000];
map<ll, ll> lcm_pf;

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

	for (int i=0; i<N; i++) {
		cin >> A[i];
		vector<pair<ll, ll>> A_pf = prime_factorize(A[i]);
		for (auto p : A_pf) {
			ll e = p.first;
			ll c = p.second;

			if (c > lcm_pf[e]) lcm_pf[e] = c;
		}
	}

	mint lcm = 1;
	for (auto itr : lcm_pf) {
		mint e = itr.first;
		ll c = itr.second;
		lcm *= modpow(e, c);
	}

	mint ans = 0;
	for (int i=0; i<N; i++) {
		ans += lcm / A[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 896
n = int(input())
s= str(n)

if n<10:
    print(n)
    exit()

ans = 0

for i in range(1,len(s)):
    if int(s[i])!=9:
        for j in range(i):
            ans += int(s[j])
        ans-=1
        ans += 9*(len(s)-i)
        print(ans)
        exit()

ans=0
for i in range(len(s)):
    ans += int(s[i])
print(ans)

Measured memory_bytes: 3064
n,m=map(int,input().split())
M=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    M[a].append(b)
    M[b].append(a)
yes="POSSIBLE";no="IMPOSSIBLE"

for i in M[0]:
    if n-1 in M[i]:
        print(yes);exit()
print(no)



Measured memory_bytes: 41780
// Shift-JIS（シフトジス）

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

int gcd(long long a, long long b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

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

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

    int x[N + 1] = {};
    int M = 0;
    vector<int> b;
    for (int i = N; i >= 1; i--)
    {
        int bit = 0;
        for (int j = i; j <= N; j += i)
        {
            bit ^= x[j];
        }
        x[i] = bit ^ a[i];
        if (x[i] == 1)
        {
            M++;
            b.push_back(i);
        }
    }

    cout << M << endl;
    for (int i = 0; i < b.size(); i++)
    {
        cout << b[i] << endl;
    }
}

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

int input[100],N,M;
int situ[2] = {-1,1};
long long memo[200][21];

long long solve(int n,int dep){
    long long ans=0;
    if(n>20 || n<0) return 0;
    if(dep==N-1){
        //printf("%d %d\n",N,M);
        if(n==M) return 1;
        else return 0;
    }
    if(memo[dep][n] != -1) return memo[dep][n];

    for(int i=0;i<2;i++){
        ans += solve(n+input[dep]*situ[i],dep+1);
    }
    memo[dep][n]=ans;
    return ans;
}

int main(){
    for(int i=0;i<200;i++)for(int j=0;j<=20;j++) memo[i][j]=-1;
    cin >> N;
    for(int i=0;i<N-1;i++){
        cin >> input[i];
    }
    cin >> M;
    /*for(int i=0;i<N-1;i++) printf("%d ",input[i]);
    puts("");*/
    printf("%lld\n",solve(input[0],1));
    return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<ll>p(N);
    rep(i, N){
        cin >> p[i];
        p[i]++;
    }
    vector<ll>s(N+1, 0);
    rep(i, N) s[i+1] = s[i] + p[i];
    ll ans = 0;
    for(int i=0; i+K<=N; ++i){
        ans = max(ans, s[i+K]-s[i]);
    }
    cout << (fixed) << setprecision(12) << (double)(ans)/2.0 << endl;

}


Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main()
{
	int n,d;
	cin>>n>>d;
	d=d*2+1;
	int a;
	if(n%d==0)
	{
		a=0;
	}
	else
	{
		a=1;
	}
	cout<<n/d+a;
	return 0;
}

Measured memory_bytes: 256
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out = 0, fh = 1;
	char jp = getchar();
	while ((jp > '9' || jp < '0') && jp != '-')
		jp = getchar();
	if (jp == '-')
		fh = -1, jp = getchar();
	while (jp >= '0' && jp <= '9')
		out = out * 10 + jp - '0', jp = getchar();
	return out * fh;
}
void print(int x)
{
	if (x >= 10)
		print(x / 10);
	putchar('0' + x % 10);
}
void write(int x, char c)
{
	if (x < 0)
		putchar('-'), x = -x;
	print(x);
	putchar(c);
}
const int P = 998244353;
int add(int a, int b)
{
	return a + b >= P ? a + b - P : a + b;
}
void inc(int &a, int b)
{
	a = add(a, b);
}
int mul(int a, int b)
{
	return 1LL * a * b % P;
}
const int N = 300 + 10;
char s[N];
int n, dp[N][N][N], f[N][N][N], valid[N][N][N];
void upd(int &x, int y)
{
	x = max(x, y);
}
int main()
{
	scanf("%s", s + 1), n = strlen(s + 1), dp[n][0][0] = 1;
	for (int i = n; i >= 1; --i)
		for (int j = 0; j + (n - i) <= n - 1; ++j)
			for (int k = 0; j + k + (n - i) <= n - 1; ++k)
			{
				inc(dp[i - 1][j][k], dp[i][j][k]);
				if (s[i] == '0')
					inc(dp[i][j][k + 1], dp[i][j][k]);
				else
					inc(dp[i][j + 1][k], dp[i][j][k]);
			}
	memset(f, -1, sizeof f);
	f[0][0][0] = 0;
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= (i >> 1); ++j)
			for (int k = 0; j + k <= (i >> 1); ++k) if (f[i][j][k] != -1)
			{
				int tmp = f[i][j][k];
				if (i + 1 <= n && tmp != 0)
				{
					if (s[i + 1] == '0')
						upd(f[i + 1][j + 1][k], tmp - 1);
					else
						upd(f[i + 1][j][k + 1], tmp - 1);	
				}
				if (i + 2 <= n)
				{
					if (s[i + 1] == '0' || s[i + 2] == '0')
						upd(f[i + 2][j + 1][k], tmp);
					if (s[i + 1] == '1' || s[i + 2] == '1')
						upd(f[i + 2][j][k + 1], tmp);
					upd(f[i + 2][j][k], tmp + 1);
				}
			}
	for (int i = 0; i <= n; ++i)
		for (int j = n; j >= 0; --j)
			for (int k = n; k >= 0; --k)
			{
				valid[i][j][k] = (f[i][j][k] != -1);
				if (i)
					valid[i][j][k] |= valid[i - 1][j][k];
				valid[i][j][k] |= valid[i][j][k + 1];
				valid[i][j][k] |= valid[i][j][k + 1];
			}
	int ans = 0;
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j + (n - i) <= n; ++j)
			for (int k = 0; j + k + (n - i) <= n; ++k)
				if (valid[i][j][k] && (n - i) + j + k != 0)
					inc(ans, dp[i][j][k]);
	write(ans, '\n');
	return 0;
}


Measured memory_bytes: 286896
//
//  main.cpp
//  1234
//
//  Created by Moha Jain on 14/04/20.
//  Copyright © 2020 Moha Jain. All rights reserved.
//

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<math.h>
#include <iomanip>
#include <numeric>
#define _USE_MATH_DEFINES

using namespace std;




int main()
{
    int x,y;
    cin>>x>>y;
   
        for(int i=0;i<=x;i=i+1)
        {
            if(y==i*2 + (x-i)*4){cout<<"Yes"<<endl;return 0;}
        }
        cout<<"No"<<endl;
    
}




Measured memory_bytes: 3620
#include<stdio.h>

int main(){
    long long int n,a,b,c;
    scanf("%lld",&n);
    a=1;
    b=n;
    c=a;
    while(a<=n/a+1){
        if(n%a==0){
            b=n/a;
            c=a;
        }
        a++;
    }
    printf("%lld",c-1+b-1);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 const INF = 1001001001;


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

int N; cin >> N;
map<int, int> mp;
rrep(i,N) mp[i] = 0;
rep(i,N-1) {
    int a; cin >> a;
    mp[a]++;
}
for(auto x : mp) cout << x.second << endl;
return 0;
}

Measured memory_bytes: 13024
num = int(input())
sequence = list(map(int, input().split()))
sequence.sort(reverse = True)

sameCnt = 1
valueCnt = 0
x, y = 0, 0
i = 0

while i < (num - 1):
  if sequence[i] == sequence[i+1]:
    if valueCnt == 0:
      x = sequence[i]
      valueCnt += 1
    elif valueCnt == 1:
      y = sequence[i]
      break
    i += 1
  i += 1

ans = x * y
print(ans)

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

int main() {
  int N=0;
  int K=0;
  int count=0;
  cin>>N>>K;
  int a[N+1];
  for(int i=0;i<N;i++){
    cin>>a[i];
    if(a[i]>=K){
      count++;
    }
  }
  cout<<count<<endl;

  return 0;

  
}



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

#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint{
public:
  ll x;
  mint(ll x=0) : x(x%mod){}
  mint& operator+=(const mint rhs){
    x += rhs.x;
    while(x >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint rhs){
    x -= rhs.x;
    while(x < 0) x += mod;
    return *this;
  }
  mint & operator*=(const mint rhs){
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  bool operator>(const ll rhs) const {
    return x > rhs;
  }
  bool operator<(const ll rhs) const {
    return x < rhs;
  }
  bool operator>=(const ll rhs) const {
    return x >= rhs;
  }
  bool operator<=(const ll rhs) const {
    return x <= rhs;
  }
  bool operator==(const ll rhs) const {
    return x == rhs;
  }
  bool operator!=(const ll rhs) const {
    return x != rhs;
  }
  friend ostream& operator<<(ostream& os,const mint rhs){
    os << rhs.x;
    return os;
  }
};

#define rep(index,num) for(int index=0;index<num;++index)

int main(){
  std::string S,T;
  std::cin >> S >> T;

  bool ret = true;
  T.pop_back();
  if(S != T) ret = false;
  if(ret) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;

#define fi first
#define se second
using ll = long long;

const int INF = (int) 1e9 + 9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll best = n-1;
    for (ll x = 1; x*x <= n; ++x) {
        if (n % x == 0) {
            best = min(best, x + n/x - 2);
        }
    }
    cout << best << '\n';
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;


int main() {
  ll n;
  cin >> n;
  ll ans = 1000000000000000;

  double sqrtNum = sqrt(n);
  sqrtNum += 0.5;

  int i = 0;
  while(i <= sqrtNum){
    ll m = 0;
    if(i != 0){
      if(n % i == 0){
        m += i;
        m += n / i;
        ans = min(ans,m);
      }
    }
    i++;
  }
    

  cout << ans-2 << endl;
  
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int n;
  cin >> n;
  vector<vector<pair<int, int> > > data(n);
  for (int i = 0; i < n; i++) {
    int sz;
    cin >> sz;
    data[i].resize(sz);
    for (int j = 0; j < sz; j++) {
      cin >> data[i][j].first >> data[i][j].second;
      data[i][j].first--;
    }
  }
  int mask = (1 << n) - 1;
  while (mask > 0) {
    int ppl = mask, i = n - 1;
    bool poss = true;
    while (ppl) {
      if (ppl & 1) {
        for (pair<int, int> p : data[i]) {
          if (p.second ^ (bool)(1 << (n - 1 - p.first)&mask))
            poss = false;
        }
      }
      ppl /= 2;
      i--;
    }
    if (poss)
      break;
    mask--;
  }
  cout << __builtin_popcount(mask);
  return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}
/*
 Atcoder 100~200点代
 アな問題が多いので,まとめる
*/
// https://abc042.contest.atcoder.jp/tasks/abc042_a
//void solve(){ ll A,B,C; cin >> A >> B >> C; if(A == 5 && B == 5 && C == 7){ cout << "YES" << endl; return;} if(A == 5 && B == 7 && C == 5){ cout << "YES" << endl; return;} if(A == 7 && B == 5 && C == 5){ cout << "YES" << endl; return;} cout << "NO" << endl; return ; }
// https://abc043.contest.atcoder.jp/tasks/abc043_a
//void solve(){ ll N; cin >> N; cout << N*(N+1)/2 << endl; }
// https://abc044.contest.atcoder.jp/tasks/abc044_a
//void solve(){ll N,K,X,Y;cin>>N>>K>>X>>Y; cout<<X*min(N,K)+Y*max(0LL,N-K)<<endl;}
// https://abc045.contest.atcoder.jp/tasks/abc045_a
//void solve(){ll a,b,h;cin>>a>>b>>h;cout<<(a+b)*h/2<<endl;}
// https://abc046.contest.atcoder.jp/tasks/abc046_a
//void solve(){ ll a,b,c; cin >> a >> b >> c; set<ll> s; s.insert(a); s.insert(b); s.insert(c); cout << s.size() << endl; }
// https://abc047.contest.atcoder.jp/tasks/abc047_a
//void solve(){ll a,b,c;cin>>a>>b>>c;if(a==b+c||b==a+c||c==a+b)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
// https://abc048.contest.atcoder.jp/tasks/abc048_a
//void solve(){string s1,s2,s3;cin>>s1>>s2>>s3;cout<<"A"<<s2[0]<<"C"<<endl;}
// https://abc049.contest.atcoder.jp/tasks/abc049_a
//void solve(){char c;cin>>c;string s="aiueo";if(s.find(c)!=string::npos)cout<<"vowel"<<endl;else cout<<"consonant"<<endl;}
// https://abc050.contest.atcoder.jp/tasks/abc050_a
//void solve(){ll A,B;char op;cin>>A>>op>>B;if(op=='+')cout<<A+B<<endl;else cout<<A-B<<endl;}
// https://abc051.contest.atcoder.jp/tasks/abc051_a
//void solve(){string s;cin>> s;cout<<s.substr(0,5)<<" "<<s.substr(6,7)<<" "<<s.substr(14)<<endl;}
// https://abc052.contest.atcoder.jp/tasks/abc052_a
//void solve(){ll A,B,C,D;cin>>A>>B>>C>>D;cout<<max(A*B,C*D)<<endl;}
// https://abc053.contest.atcoder.jp/tasks/abc053_a
//void solve(){ll x;cin>>x;cout<<(x<1200?"ABC":"ARC")<<endl;}
// https://abc054.contest.atcoder.jp/tasks/abc054_a
//void solve(){ll A,B;cin>>A>>B;if(A==1)A=14;if(B==1)B=14;cout<<(A>B?"Alice":(A==B?"Draw":"Bob"))<<endl;}
// https://abc055.contest.atcoder.jp/tasks/abc055_a
void solve(){ll N;cin>>N;cout<<800*N-200*(N/15)<<endl;}
// Main function
int main(void) {cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }


Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())

// code
// ------------------------------------------------
bool isKaibun(string ss)
{
  string sr = ss;
  reverse(all(sr));
  if (ss == sr) return true;
  else return false;
}

int main() {

  string s;
  cin >> s;

  bool is = false;
  if(isKaibun(s))
  {
    string a = s.substr(0, (sz(s) - 1 )/ 2);
    if(isKaibun(a))
    {
      string b = s.substr((sz(s) + 3) / 2 - 1, sz(s) - 1);
      if(isKaibun(b))
      {
        is = true;
      } 
    }
  }

  if(is) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

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

template <class Abel>
class UnionFind{
    vector<int> par_, weight_;
public:
    UnionFind(size_t n){
        par_.assign(n, -1);
        weight_.assign(n, 0);
    }

    int root(int x){
        if (par_[x] < 0) {
            return x;
        }else{
            int res = root(par_[x]);
            weight_[x] += weight_[par_[x]];
            return par_[x] = res;
        }
    }

    int weight(int x){
        root(x);
        return weight_[x];
    }

    int weight(int x, int y){
        return weight(y) - weight(x);
    }

    int size(int x){
        return -par_[root(x)];
    }

    bool IsSame(int x, int y){
        return root(x) == root(y);
    }

    void Merge(int x, int y, Abel w){
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y)
            return;
        if (size(x) < size(y)) {
            w = -w;
            swap(x, y);
        }
        par_[x] += par_[y];
        par_[y] = x;
        weight_[y] = w;
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    UnionFind<int> dsu(n);
    
    for (int i = 0; i < q; i++){
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0)
            dsu.Merge(u, v, 0);
        else
            printf("%d\n", dsu.IsSame(u, v));
    }
}

Measured memory_bytes: 4764
from collections import defaultdict
d = defaultdict(lambda: 0)
N = int(input())
a = list(map(int, input().split()))
for tmp_a in a:
    d[tmp_a] += 1
key_list = list(d.keys())
key_list.sort()
counter = 0
for key in key_list:
    if d[key]>=key:
        counter += d[key]-key
    else:
        counter += d[key]

print(counter)


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

constexpr int64_t mod{1'000'000'007};

class Combination {
private:
	const int64_t mod_;

public:
	std::vector<int64_t> inv, fact, finv;

	Combination(const int max = 200'000, const int64_t mod = 1'000'000'007)
		: mod_(mod),
		inv(max + 1), fact(max + 1), finv(max + 1)
	{
		inv[0] = inv[1] = fact[0] = fact[1] = finv[0] = finv[1] = 1;
		for (int num{2}; num <= max; num++)
		{
			inv[num] = (mod_ - inv[mod_ % num] * (mod_ / num) % mod_) % mod_;
			fact[num] = num * fact[num - 1] % mod_;
			finv[num] = inv[num] * finv[num - 1] % mod_;
		}
	}

	int64_t getCombi(const int n, const int r)
	{
		if (r < 0 || n < 0 || n - r < 0) return 0;
		return fact[n] * finv[r] % mod_ * finv[n - r] % mod_;
	}

	int64_t getPerm(const int n, const int r)
	{
		if (r < 0 || n < 0 || n - r < 0) return 0;
		return fact[n] * finv[n - r] % mod_;
	}
};

int main()
{
	int64_t N, M, K;
	scanf("%lld%lld%lld", &N, &M, &K);
	if  (N > M) std::swap(N, M);

	Combination combi;
	int64_t ans{}, tmp{};
	for (int i{1}; i + 1 <= N; i++)
		tmp = (tmp + i * (N - i) % mod) % mod;
	tmp = tmp * M % mod * M % mod;
	ans = tmp;
	
	tmp = 0;
	for (int i{1}; i + 1 <= M; i++)
		tmp = (tmp + i * (M - i) % mod) % mod;
	tmp = tmp * N % mod * N % mod;
	ans = (ans + tmp) % mod;

	ans = ans * combi.getCombi((N * M - 2) % mod, (K + mod - 2) % mod) % mod;
	printf("%lld\n", ans); 

	return 0;
}

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

int main() {
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    ll ans = 0;
    if(n == 1) {
        cout << 0;
        return 0;
    }
    if(s[0] == 'R' && s[1] == 'R') ++ans;
    if(s[n-1] == 'L' && s[n-2] == 'L') ++ans;
    for(ll i = 1; i <= n-2; ++i) {
        if(s[i] == 'L' && s[i-1] == 'L') ++ans;
        if(s[i] == 'R' && s[i+1] == 'R') ++ans;  
    } 
    ans = ans + 2*(k);
    ans = min(ans, n-1);
    cout << ans;
    return 0;
}

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

using ll = long long;
#define mod 1000000007
#define init ios::sync_with_stdio(0), cin.tie(0);
typedef vector<int> vi;
typedef pair<int, int> pi;
#define MS(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair

int main()
{
    init;

    char c;
    cin >> c;

    if (c > 91)
        cout << 'a';
    else
    {
        cout << 'A';
    }
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
using namespace std;
string a;
int n,o,r[3],run,ans;
int main() {
        cin>>n;
    for(int loop=0;loop<n;loop++){
        for(int i=0;i<3;i++)r[i]=0;
        o=0;ans=0;run=0;
        while(o<3){
            cin>>a;
            if(a=="HOMERUN"){
                ans+=(run+1);
                run=0;
                for(int i=0;i<3;i++)r[i]=0;
            }if(a=="HIT"){
                if(r[2]==1){
                    r[2]=0;
                    ans++;
                    run--;
                }
                if(r[1]==1){
                    r[1]=0;r[2]=1;
                }
                if(r[0]==1){
                    r[0]=0;r[1]=1;
                }
                r[0]=1;run++;
            }else if(a=="OUT"){
               o++;
            }   
        }
        cout<<ans<<endl;
    }
        return 0;
}

Measured memory_bytes: 1204