akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll H, W, N;
vector<ll> a, b;
unordered_map<ll, unordered_set<ll>> mp;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W >> N;
  a.resize(N);
  b.resize(N);
  for (ll i = 0; i < N; i++) {
    ll ai, bi;
    cin >> ai >> bi;
    ai--;
    bi--;
    a[i] = ai;
    b[i] = bi;
    mp[ai].insert(bi);
  }

  set<pair<ll, ll>> used;
  vector<ll> ans(10, 0);
  for (ll i = 0; i < N; i++) {
    ll ai = a[i], bi = b[i];
    for (ll h = ai - 2; h <= ai; h++) {
      for (ll w = bi - 2; w <= bi; w++) {
        pair<ll, ll> p = make_pair(h, w);
        if (0 <= h && h < H - 2 && 0 <= w && w < W - 2 && used.find(p) == used.end()) {
          used.insert(p);
          ll cnt = 0;
          for (ll j = h; j < h + 3; j++) {
            for (ll k = w; k < w + 3; k++) {
              if (!mp[j].empty() && mp[j].find(k) != mp[j].end()) {
                cnt++;
              }
            }
          }
          ans[cnt]++;
        }
      }
    }
  }

  ll sum = 0;
  for (auto &e : ans) {
    sum += e;
  }
  ans[0] = (H - 2) * (W - 2) - sum;
  for (auto &e : ans) {
    cout << e << endl;
  }
  return 0;
}

Measured memory_bytes: 107508
def c_minimization(N, K, A):
    return ((N - 1) + (K - 1) - 1) // (K - 1)  # (N-1)/(K-1)を切り上げ

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(c_minimization(N, K, A))

Measured memory_bytes: 13880
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	long long int A, B;
	cin >> A >> B;
	if (A % 2 && !(B % 2)) {
		if ((B - A + 1 - 2) % 4 == 0)cout << (A^B);
		else cout << ((A^B) ^ 1);
	}
	if (!(A % 2) && B % 2) {
		if ((B - A + 1) % 4 == 0)cout << 0;
		else cout << 1;
	}
	if (A % 2 && B % 2) {
		if ((B - A + 1 - 1) % 4==0)cout << (A ^ 0);
		else cout << (A ^ 1);
	}
	if (!(A % 2) && !(B % 2)) {
		if ((B - A + 1 - 1) % 4==0)cout << (B ^ 0);
		else cout << (B ^ 1);
	}
}


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

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<vector<int>> G;
vector<ll> P;

void dfs(int v, int par){
    for(auto nv : G[v]){
        if(nv == par) continue;
        P[nv] += P[v];
        dfs(nv, v);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    G.resize(N);
    P.resize(N);
    REP(i,N-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(i,Q){
        int p, x;
        cin >> p >> x;
        --p;
        P[p] += x;
    }
    dfs(0, -1);
    REP(i,N) cout << P[i] << " ";
    cout << endl;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int K,S,count=0;

  cin >> K >> S;

  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
        int x = S-(i+j);
        if((K>=x)&&(x>=0)) count++;          
    }
  }
  
   cout << count << endl;
  
  return 0;
}

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

int main()
{
	int n;

	std::cin >> n;

	for(int i=0; i<n; ++i)
	{
		std::vector<int> length;

		int k;

		for(int i=0; i<3; ++i)
		{
			std::cin >> k;

			length.push_back(k);
		}
		std::sort(length.begin(),length.end());

		std::cout << (length[2]*length[2]==length[1]*length[1]+length[0]*length[0] ? "YES\n" : "NO\n");
	}
}

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

int main(){
  string O,E;
  cin >> O >> E;
  for(int i=0;i<E.size();i++){
    cout << O.at(i) << E.at(i);
  }
  if(O.size()>E.size()) cout << O.at(O.size()-1);
}

Measured memory_bytes: 256
import java.util.Scanner; 
class Main {
   public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     int x = scan.nextInt();
     int y = scan.nextInt();
     if(x < y){
       System.out.println("a < b");
     }
     else if (x > y){
       System.out.println("a > b");
     }
     else{
       System.out.println("a == b");
     }
  }
}


Measured memory_bytes: 26144
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int sum = 0;
  int cnt = 1;
  while(1){
    sum += a;
    if(cnt%7 == 0) sum += b;
    if(sum >= c) break;
    cnt++;
  }

  cout << cnt << endl;
}


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

// 💖 Hi, thanks for using ICIE! 💖
// 🔧 To use a custom code template, set it in Settings(Ctrl+,) in "Icie Template List" entry 🔧
// 📝 If you spot any bugs or miss any features, create an issue at https://github.com/pustaczek/icie/issues 📝
const int maxn=200000+10;
int n,k,a[maxn];
double p[maxn],mx,sum;
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i],p[i]=(a[i]+1)/2.0;
    for(int i=1;i<=n;i++)
    {
        if(i<k)
            sum+=p[i];
        else
        {
            sum=sum-p[i-k]+p[i];
            mx=max(mx,sum);
        }
    }
    cout<<fixed<<setprecision(12)<<mx;

    return 0;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  int n, k; cin >> n >> k;
  v1i v(n); vector<pii> u(n, {0, 0}); rep(i, n) cin >> v[i];
  rep(i, min(k, 65)){
    int tmp = 0;
    rep(j, n){
      ++u[max(0, j-v[j])].fi;
      ++u[min(n-1, j+v[j])].se;
    }
    rep(j, n){
      tmp += u[j].fi;
      v[j] = tmp;
      tmp -= u[j].se;
    }
    rep(j, n) u[j] = {0, 0};
  }
  rep(i, n){
    cout << v[i];
    if(i < n-1) cout << " ";
    else cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 5632
fun main(args: Array<String>) {
    val line = readLine()!!.trim()
    val (n, k) = line.split(" ").map {it.toLong()}

    var answer: Long = 0

    for (kosu in k..n+1) {
        val start = n - (kosu - 1)
        val maximum = ((start + n) * kosu) / 2
        val minimum = ((0 + (kosu - 1)) * kosu) / 2

        answer += (maximum - minimum + 1)
        // println("answer:${answer} n:${n} kosu:${kosu} start:${start} minimum:${minimum} maximum:${maximum}")
        answer = answer % (1000000000 + 7)
    }

    println("${answer}")
}

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

int main()
{
	int a, b, C;
	const double pi = M_PI;
	cin >> a >> b >> C;
	
	double radC = (C * pi) / 180;

	double S = (a * b * sin(radC)) / 2;
	double c = sqrt(a*a + b*b - 2 * a * b * cos(radC));
	double L = a + b + c;
	double h = (2 * S) / a;

	printf("%.8f\n", S);
	printf("%.8f\n", L);
	printf("%.8f\n", h);
	return 0;
}


Measured memory_bytes: 3448
#!/usr/bin/env python3
import sys

def main():
    D, N = map(int, input().split())
    l = []
    for i in range(1,10000*120):
        if i % (100**D) == 0 and i % (100**(D+1)) != 0:
            l.append(i)
    
    print(l[N-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 50048
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
#define ll long long
#define endl '\n'
const int MAX = 2e5 + 4;
const int MOD = 1e9 + 7;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	float n;
	cin >> n;
	int res = n / 2 + 0.5;
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(x,y) for(ll i=x;i<y;i++)
#define vll vector<ll>
#define sll set<ll>
#define pb push_back
#define in insert
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define tc ll t;cin>>t;while(t--)
#define rev(x) reverse(all(x))
#define low_str(x) transform(all(x),x.begin(),::tolower)
#define up_str(x) transform(all(x),x.begin(),::toupper)
#define to_digit(c) c-'0';
int main()
{
ll x, k, d;
cin >> x >> k >> d; ll ans;
if(x < 0)
x = x - (2*x);
ll y = x/d;
ll z = x%d;
if(y==k)
ans = z;
else if(y>k)
ans = z+(y-k)*d;
else
{
    ll p = k - y;
    ll a = z-d; a = a - (2*a);
    if(p%2==0)
    ans = z;
    else
    {
        ans = a;
    }
}
cout << ans << endl;

return 0;
}

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

using namespace std;

int main(void){
  int a, b, c, d, e, k;
  cin >> a >> b>>c>>d>>e>>k;
  cout << (((max({a, b, c, d, e})-min({a, b, c, d, e}))>k) ? ":(" : "Yay!") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
        int i,m,c=0;
        char s[200010],t[200010];
        scanf("%s%s",s,t);
        m=strlen(s);
        for(i=0;i<m;i++)
                if(s[i]==t[i])c++;
        printf("%d\n",m-c);
        return 0;
}


Measured memory_bytes: 2076
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
	ll n=5;
	ll x;
	rep(i,0,n) {
		cin>>x;
		if(x==0) {
			cout<<i+1<<endl;
			return;//https://pastebin.com/FcuZ4z7V
		}
	}
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 3772
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n, s, k;
	char a[11];
	scanf("%d", &n);
	scanf("%s", a, 11);
	scanf("%d", &k);
	for (int i = 0; i < n; i++)
	{
		if (a[i] != a[k - 1])
			printf("*");
		else
			printf("%c", a[i]);
	}
	//system("pause");
	return 0;
}

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

using namespace std;

int main() {
	int ab, bc, ca;
	cin >> ab >> bc >> ca;
	
	auto m = max({ab, bc, ca});
	int result = 0;
	if (ab == m)
		result = bc * ca;
	else if (bc == m)
		result = ab * ca;
	else
		result = ab * bc;
	
	cout << result / 2 << endl;
}

Measured memory_bytes: 256
# seishin.py
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]

from heapq import heappush, heappop

l0, r0 = P[0]

L = [-l0+1]
R = [l0-1]
s = t = 0

res = 0
for i in range(N-1):
    l0, r0 = P[i]
    l1, r1 = P[i+1]
    s += (r1 - l1); t += (r0 - l0)
    if -s-L[0] <= l1-1 <= t+R[0]:
        heappush(L, -l1+1-s)
        heappush(R, l1-1-t)
    elif l1-1 < -s-L[0]:
        heappush(L, -l1+1-s)
        heappush(L, -l1+1-s)
        p = -heappop(L)-s
        heappush(R, p-t)
        res += (p - (l1-1))
    elif t+R[0] < l1-1:
        heappush(R, l1-1-t)
        heappush(R, l1-1-t)
        p = heappop(R) + t
        heappush(L, -p-s)
        res += ((l1-1) - p)
print(res)

Measured memory_bytes: 36460
#include <iostream>

using namespace std;

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

   bool here = true;

   for (int i = 0; i < s.length(); i++) {

    if (s[i] == '7')
    here = false;

   }

   if (here == false)
    cout << "Yes";
    else
    cout << "No";

    return 0;
}


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

int n,m,t;
int x[100005],y[100005];
int ans[100005];
int val[100005];
map<int,int>M;
bitset<50005>B[50005];

void solve_hard(){
	repn(i,n) B[i][i] = 1;
	for(int j=m-1;j>=0;j--){
		B[x[j]] |= B[y[j]];
		B[y[j]] |= B[x[j]];
	}
	for(int i=2;i<=n;i++) B[1] &= B[i];
	int v = -1;
	rep(i,50005){
		if(B[1][i] == 1){
			v = i;
			break;
		}
	}
	if(v == -1){
		puts("-1");
		return ;
	}
	string ans = "";
	repn(i,n){
		val[i] = i;
	}
	for(int j=m-1;j>=0;j--){
		int f1 = val[x[j]] == v;
		int f2 = val[y[j]] == v;
		
		if(f1 && f2){
			val[y[j]] = val[x[j]];
			ans.pb('^');
		}
		else if(!f1 && !f2){
			val[y[j]] = val[x[j]];
			ans.pb('^');
		}
		else if(f1 && !f2){
			val[y[j]] = val[x[j]];
			ans.pb('^');
		}
		else{
			val[x[j]] = val[y[j]];
			ans.pb('v');
		}
	}
	repn(i,n) assert(val[i] == v);
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
}
int main(){
	scanf("%d%d%d",&n,&m,&t);
	rep(i,m) scanf("%d%d",&x[i],&y[i]);
	
	if(t == 1){
		solve_hard();
		return 0;
	}
	repn(i,n){
		val[i] = i;
		M[i]++;
	}
	for(int i=m-1;i>=0;i--){
		int a = val[x[i]];
		int b = val[y[i]];
		if(M[a] < M[b]){
			ans[i] = 1;
			M[a]++;
			M[b]--;
			val[y[i]] = a;
		}
		else{
			ans[i] = 0;
			M[a]--;
			M[b]++;
			val[x[i]] = b;
		}
	}
	for(auto a:M){
		if(a.sc == n){
			puts("-1");
			return 0;
		}
	}
	rep(i,m) printf(!ans[i]?"v":"^"); puts("");
	//repn(i,n) cout << val[i] << endl;
}


Measured memory_bytes: 307072
import math
N, M = map(int, input().split())
if N > 2:
    ans_N = math.factorial(N) // (math.factorial(N - 2) * math.factorial(2))
    if M > 2:
        ans_M = math.factorial(M) // (math.factorial(M - 2) * math.factorial(2))
        print(ans_N + ans_M)
    elif M == 2:
        print(ans_N + 1)
    elif M < 2:
        print(ans_N)
elif N == 2:
    if M > 2:
        ans_M = math.factorial(M) // (math.factorial(M - 2) * math.factorial(2))
        print(1 + ans_M)
    elif M == 2:
        print(1 + 1)
    elif M < 2:
        print(1 + 0)
elif N < 2:
    if M > 2:
        ans_M = math.factorial(M) // (math.factorial(M - 2) * math.factorial(2))
        print(0 + ans_M)
    elif M == 2:
        print(0 + 1)
    elif M < 2:
        print(0 + 0)

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	const int MAX = 100010;
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> cnt(MAX);
	long long sum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		++cnt[a[i]];
		sum+=a[i];
	}
	int q; cin >> q;
	while(q--){
		int b,d; cin >> b >> d;
		sum -=1ll *  cnt[b] * b;
		sum +=1ll *  cnt[b] * d;
		cnt[d] += cnt[b];
		cnt[b] = 0;
		cout << sum << "\n";
	}
	return 0;
}


Measured memory_bytes: 3916
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::char;
use std::cmp::{min, max};
use itertools::Itertools;
use std::ops::{Add, AddAssign};
use num_integer::{Integer, gcd, lcm};
use std::collections::VecDeque;
use smallvec::alloc::collections::LinkedList;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}

fn read_tuple3<T: FromStr, S: FromStr, R: FromStr>() -> (T, S, R) {
    let a = read();
    let b = read();
    let c = read();
    (a, b, c)
}

fn lower_bound<T: Copy, F>(v: &Vec<T>, f: F) -> Option<usize> where
    F: Fn(T) -> bool
{
    let mut left = 0;
    let mut right = v.len() - 1;
    if !f(v[left]) {
        return None;
    }
    if f(v[right]) {
        return Some(right);
    }
    loop {
        if right - left == 1 {
            return Some(left);
        }
        let mid = (left + right) / 2;
        if f(v[mid]) {
            left = mid;
        } else {
            right = mid;
        }
    }
}

fn main() {
    let n:u32 = read();
    for i in (1..) {
        let yen = i * 1000;
        if (n <= yen) {
            println!("{}", yen - n);
            return;
        }
    }

}



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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n,k;
    cin>>n>>k;
    int c=0;
    loop(i,0,n)
    {
        int x,y;
        cin>>x>>y;
        double d=sqrt(x*x+y*y);

        if(d<=k) c++;
    }
    cout<<c;


    return 0;
}


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

int main(){
  int n,x;
  cin>>n>>x;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  sort(num.begin(),num.end());
  int i=0,sum=num[0];
  while(sum<=x){
    ++i;
    if(i==n) break;
    else if(i==n-1){
      if(num[i]!=x-sum) break;
    }
    sum+=num[i];
  }
  cout<<i<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    #region library
    static int n = 0;
    static int r = 0;
    static int c = 0;
    static int x = 0;
    static int y = 0;
    static string s = "";
    static string[] ss;
    static long sum = 0;
    static long cnt = 0;
    static long max = -1;
    static long min = 2147483647;
    static bool flg = false;
    static bool flg2 = false;
    static string alpha = "abcdefghijklmnopqrstuvwxyz";
    static int[] arr;
    static char[,] map;
    static int[,] imap;
    static string rl()
    {
        return Console.ReadLine();
    }
    static string[] rls()
    {
        return Console.ReadLine().Split();
    }
    static void wl(object obj = null)
    {
        Console.WriteLine(obj);
    }
    static void w(object obj)
    {
        Console.Write(obj);
    }
    static int Int(string s)
    {
        return int.Parse(s);
    }
    static void yes()
    {
        wl("YES");
    }
    static void no()
    {
        wl("NO");
    }
    static void Sum()
    {
        wl(sum);
    }
    static void Cnt()
    {
        wl(cnt);
    }
    static void setarray(int num = -1)
    {
        if (n == 0)
        {
            n = Int(rl());
        }
        arr = new int[n];
        if (num == -1) ss = rls();
        for (int i = 0; i < n; i++)
        {
            if (num == -1)
                arr[i] = Int(ss[i]);
            else
                arr[i] = num;
        }
    }
    static void setmap(char def = '@')
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        map = new char[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == '@') s = rl();
            for (int j = 0; j < c; j++)
            {
                map[i, j] = (def == '@') ? s[j] : def;
            }
        }
    }
    static void setimap(int def = -1)
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        imap = new int[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == -1) s = rl();
            for (int j = 0; j < c; j++)
            {
                imap[i, j] = (def == -1) ? Int(s[j].ToString()) : def;
            }
        }
    }
    #endregion

    static void Main(string[] args)
    {
        ss = rls();
        s = ss[0];
        string t = ss[1];
        wl(t+s);
    }

}



Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <cassert>
#include <functional>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int p, q, r;
    cin >> p >> q >> r;
    cout << min(r + p,min(p + q, q + r)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    ll a[n];
    rep(i,n)cin>>a[i];
    ll res = 0;
    rep(i,n)res^=a[i];
    ll ans = 0;
    ll cur = 0;
    vector<int> used(n);
    for(int j= 61;j>=0;--j){
        if(res&(1ll<<j)){
            rep(i,n){
                if(a[i]&(1ll<<j))a[i]^=1ll<<j;
            }
        }
        
        rep(i,n){
            if(used[i])continue;
            if(a[i]&(1ll<<j)){
                used[i]=1;
                rep(k,n){
                    if(i==k)continue;
                    if(a[k]&(1ll<<j))a[k]^=a[i];
                }
                break;
            }
        }
    }
    sort(a,a+n);
    reverse(a,a+n);
    if(n>65){
        n=65;
    }
    rep(_,40000){
    rep(i,n)used[i]=0;
    cur = 0;
    for(int j= 61;j>=0;--j){
        if(cur&(1ll<<j))continue;
        rep(i,n){
            if(!used[i]&&a[i]&(1ll<<j)){
                cur^=a[i];
                used[i]=1;
                break;
            }
        }
    }
    ans = max(ans,cur+(cur^res));
    random_shuffle(a, a+n);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  int sum = 0;
  int A, B, C;
  A = 0;
  B = 0;
  C = 0;
  for(int i = 0; i <= N;i++){
    for(int j = 0; j <= N;j++){
      sum = 10000*i + 5000*j + 1000*(N - i - j);
      if(sum == K && N - i - j >= 0){
        A = i;
        B = j;
        C = N - i - j;
      break;
      }
    }
  }
  if(A == 0 && B == 0 && C == 0){
    cout << -1 << " " <<  -1 << " " << -1 << endl;
  }
  else{
    cout << A << " " <<  B << " " << C << endl;
  }
}

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

int main()
{
	//ios::sync_with_stdio(0),cin.tie(0);
	int x,count5 = 0,count7=0;
	for (int i = 0; i < 3; i++)
	{
		cin >> x;
		if (x==5)
		{
			count5 ++;
		}else if(x == 7){
			count7 ++;
		}
	}
	count5 == 2 and count7 == 1 ? printf("YES\n") : printf("NO\n");
}


Measured memory_bytes: 3536
#とりまNまで素因数分解しておくか,dpか？

#nまでの素数を列挙
n = int(input())

#is_prime[i]にはi-1画素数か否かを示すboolが入る，[0]に1の素数判定がある．
is_prime = [True]*(n+1)
is_prime[0] = False

for i in range(2, n+1):
    if is_prime[i-1]:
        j = 2 * i
        while j <= n:
            is_prime[j-1] = False
            j += i

table = [ i for i in range(1, n+1) if is_prime[i-1]]

#素因数の個数リスト
hist=[0]*len(table)

#素因数分解して，histに追加
def p_fact(a):
    for i in range(len(table)):
        while a%table[i]==0:
            hist[i]+=1
            a=a//table[i]
            
for i in range(2,n+1):
    p_fact(i)

over2=0
over4=0#4個以上
over14=0
over24=0
over74=0
for i in range(len(hist)):
    if hist[i]>=2:
        over2+=1
        if hist[i]>=4:
            over4+=1
            if hist[i]>=14:
                over14+=1
                if hist[i]>=24:
                    over24+=1
                    if hist[i]>=74:
                        over74+=1
                    
        
ans=0
#素因数が(2,4,4)の組みを，素因数2のものから探す
for i in range(len(hist)):
    if hist[i]>=2:
        a=over4
        if hist[i]>=4:
            a-=1
        ans+=(a*(a-1))//2
        
    if hist[i]>=14:#素因数が(4,14)の組みは，素因数が14のものから探す
        ans+=over4-1
    
    if hist[i]>=24:
        ans+=over2-1

if over74==1:
    ans+=1
        
print(ans)



Measured memory_bytes: 38512
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
n, x = map(int, input().split())
l = list(map(int, input().split()))
d = [0]*n
for i in range(n):
  d[i] = abs(l[i]-x)
  
print(gcd_list(d))

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


int main() {
  int64 N;
  cin >> N;
  int64 ret = 0;
  for(auto &p : divisor(N)) {
    if(p > 1 && N / (p - 1) == N % (p - 1)) ret += p - 1;
  }
  cout << ret << endl;
}


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

using namespace std;

int main() {

    string arr[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin>>s;
    int x = find(arr,arr+7,s)-arr;
    cout<<7-x<<endl;



    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef unsigned long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
ll gcd(ll a,ll b){
     if (b) return gcd(b,a%b);
     else return a;
}
ll ans=1;
map<long long,int> prime_factor(long long n){
	 map<long long,int> ret;
	 for (ll i=2LL;i*i <= n;i++){
           bool f = true;
		 while(n%i==0){
		 	if (n%i==0){
				 ret[i]++;
				 n/=i;
                     if (f) {
                          ans++;
                          f=false;
                     }
		 	}
		}
	 }
	 if (n != 1) {
           ret[n]=1;
           ans++;
      }    
	 return ret;
}

int main(){
     ll a,b;
	cin >> a >> b;
     ll w;
     w=gcd(a,b);
     //cout << w << endl;
     map<long long,int> z=prime_factor(w);
     cout << ans << endl;
     //cout << w << endl;
     return 0;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define MOD (10000)
string A,B;
int a[511],b[511];
int M,N;
int dp[501][501][10][2][3];//桁、割ったあまり、前回の値、減少or増加、aを使ったかbを使ったか
int lth(int num,int n){
  return (num*10+n)%M;
}
//桁,割ったあまり,前回の値,1:増加or2:減少,1bit:aを使ったか2bit:bを使ったか,0以外が出たかどうか
int solve(int no,int m,int zg,int zgf,int fl,bool uz){
  //  printf("%d %d %d %d %d\n",no,m,zg,zgf,fl);
  if(no==N){
    if(m==0 && uz)
      //printf("%d %d %d %d %d\n",no,m,zg,zgf,fl);
      return 1;
      //return 1;
    else 
      return 0;
    //return 0;
  }
  if(zgf>=0) if(dp[no][m][zg][zgf][fl]!=-1) return dp[no][m][zg][zgf][fl];
  int ret = 0;
  for(int i=0;i<=9;i++){
    /*    if(!uz){
      if( i < a[no] ) continue;
      ret += solve(no+1,lth(m,i),i,0,fl,(uz || i!=0));
      ret %= MOD;
      } else{*/
      if(zgf==0 && zg<i) continue;
      if(zgf==1 && zg>i) continue;
      if(zg==i  && uz) continue;
      if( i < a[no] && (fl&1) ) continue;
      if( i > b[no] && (fl&2) ) continue;
      int fl2 = fl;
      if( i != a[no] ) fl2=fl2&~1;
      if( i != b[no] ) fl2=fl2&~2;
      int zgf2;
      if(zg<i) zgf2=0;
      else zgf2=1;
      if(!uz) zgf2=-1;
      ret += solve(no+1,lth(m,i),i,zgf2,fl2,uz || i!=0);
      ret%=MOD;
    
  }
  if(zgf>=0)
    return dp[no][m][zg][zgf][fl]=ret;
  return ret;
    //return ret;
}
int solve(){
  int ret=0;
  for(int i=0; i<=9; i++){
    int fl=3;
    if( i < a[0] ) continue;
    if( i > b[0] ) continue;
    if( i != a[0]) fl=fl&~1;
    if( i != b[0] ) fl=fl&~2;
    ret += solve(1,i%M,i,-1,fl,i!=0);
    ret%=MOD;
  }
  return ret;
}
int main(){
  memset(dp,-1,sizeof(dp));
  cin >> A >> B >> M;
  N = B.size();
  for(int i=0;i<N;i++){
    b[i]=B[i]-'0';
    if(N-(int)A.size()<=i) a[i]=A[i-(N-(int)A.size())]-'0';
  }
  /*  for(int i=0;i<N;i++) cout << a[i];
  puts("");
  for(int i=0;i<N;i++) cout << b[i];
  puts("");*/
  cout << solve() << "\n";
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

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

int sx,sy,h,w;
string fld[20];
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int bfs() {
	bool used[h][w];
	REP(i,h) REP(j,w) used[i][j]=false;
	int cnt=1;
	queue<P> q;
	used[sy][sx]=true;
	q.push(P(sx,sy));
	while(!q.empty()) {
		P p=q.front();q.pop();
		REP(i,4) {
			int nx=p.fi+dx[i],ny=p.se+dy[i];
			if(nx<0||nx>=w||ny<0||ny>=h||used[ny][nx]||fld[ny][nx]=='#') continue;
			used[ny][nx]=true;
			cnt++;
			q.push(P(nx,ny));
		}
	}
	return cnt;
}

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

	while(true) {
		cin>>w>>h;
		if(w==0) break;
		REP(i,h) {
			cin>>fld[i];
			REP(j,w) if(fld[i][j]=='@') sx=j,sy=i;
		}
		cout<<bfs()<<endl;
	}

	return 0;
}



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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    string s, t;
    cin >> s >> t;
    VSORT(s); RSORT(t);
    if (s < t) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

int kosuu(int x){
    map<int,int>memo;
    for(int i=2;i<=sqrt(x);i++){
        while(x%i==0){
            x /=i;
            memo[i]++;
        }
    }
    int ans=1;
    for(auto it=memo.begin();it!=memo.end();it++){
        ans *=(it->second+1);
    }
    if(x!=1){
        ans*=2;
    }
    return ans;
}

signed main(){
    int N;
    cin >>N;
    int ans=kosuu(N-1);
    for(int i=2;i<=sqrt(N);i++){
        int N1=N;
      	if(N1%i!=0){
          continue;
        }
      	while(N1%i==0){
            N1 /=i;
        }
        if(N1%i==1){
            ans++;
        }
        int N2=N;
        int j=N/i;
        if(i==j){
            continue;
        }
        while(N2%j==0){
            N2 /=j;
        }
        if(N2%j==1){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import Control.Applicative

main = do
    [a, b] <- map read . words <$> getLine
    f a b
    
f :: Int ->Int -> IO ()    
f a b = if (a > b)
            then putStrLn "a > b"
            else if (a < b)
                then putStrLn "a < b"
                else putStrLn "a == b"
            


Measured memory_bytes: 3580
#include <stdio.h>
 
int main(){
  int a;
  int b;
  int d;
  double f;
  int r;
  scanf("%d %d", &a,&b);
  d = a / b;
  r = a % b;
  f =  a /(double) b;
  printf("%d %d %.8lf\n", d,r,f);
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int dp[4][202020];
int dx[4] = { 0,0,-1,1 };
int dy[4] = { -1,1,0,0 };
int to[555];
typedef pair<int, int>pii;
pii solve(vector<pii>v, int gen)
{
	int lb = 0, ub = gen - 1;
	reverse(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++)
	{
		if (v[i].first == 0)
		{
			if (v[i].second == 0)lb++;
			else ub--;
		}
		else
		{
			if (v[i].second == 0)ub++;
			else lb--;
		}
		lb = max(lb, 0), ub = min(ub, gen - 1);
		if (lb > ub)return make_pair(gen, -1);
	}
	return make_pair(lb, ub);
}
int main()
{
	int mx, my, num, sx, sy;
	scanf("%d%d%d%d%d", &mx, &my, &num, &sx, &sy);
	string s1, s2;
	cin >> s1 >> s2;
	sx--, sy--;
	vector<pii>v1, v2;
	for (int i = 0; i < num; i++)
	{
		if (s1[i] == 'L')v1.push_back(make_pair(0, 0));
		if (s1[i] == 'R')v1.push_back(make_pair(0, 1));
		if (s1[i] == 'U')v2.push_back(make_pair(0, 0));
		if (s1[i] == 'D')v2.push_back(make_pair(0, 1));
		if (s2[i] == 'L')v1.push_back(make_pair(1, 0));
		if (s2[i] == 'R')v1.push_back(make_pair(1, 1));
		if (s2[i] == 'U')v2.push_back(make_pair(1, 0));
		if (s2[i] == 'D')v2.push_back(make_pair(1, 1));
	}
	pii a = solve(v1, my), b = solve(v2, mx);
	//printf("%d %d  %d %d\n", a.first, a.second, b.first, b.second);
	if (a.first <= sy&&sy <= a.second&&b.first <= sx&&sx <= b.second)printf("YES\n");
	else printf("NO\n");
}

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

int main() {
    int a,b,sum,taf,time;
    cin >> a >> b;
    sum = a + b;
    taf = a - b;
    time = a*b;
   
    if (sum > taf && sum > time  ) {
        cout << sum;
    }
    else if (taf > sum && taf > time) {
        cout << taf;
    }
    else if (time > taf && time > sum) {
        cout << time;
    }
    else{
        cout << sum;
    }

    
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int main(){
    long long N, K;
    cin >> N >> K;
    long long ans = 0;
    for(long long  i = K; i <= N + 1; i++){
        ans += (N + N - i + 1)*i / 2 - (i)*(i - 1)/2 + 1;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k;
	cin >> n >> k;
	int l[50]={};
	for(int i=0;i<n;i++){
		cin >> l[i];
	}
	sort(l,l+50);
	int ans=0;
	for(int i=49;i>49-k;i--) ans+=l[i];
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 60000

using namespace std;

int c[20], n, m, val[50010];
bool done[50010];

int solve (int p)
{
    if (p<0) return INF;
    if (p==0) return 0;
    if (done[p]) return val[p];
    int best=INF;
    for (int i=0; i<m; i++)
    {
        best=min(best,solve(p-c[i])+1);
    }
    done[p]=true;
    val[p]=best;
    return best;
}

int main ()
{
    cin>>n>>m;
    for (int i=0; i<m; i++) cin>>c[i];
    for (int i=0; i<50010; i++) done[i]=false;
    cout<<solve(n)<<'\n';
    return 0;
}



Measured memory_bytes: 5684
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
typedef long long ll; typedef long double ld; typedef double dd;typedef vector<int> vi; typedef pair<int, int> pii;typedef pair<ll,ll> pll;
const ll INFLL=(ll)4e18, MOD=1e9+7; const int INF=0x3f6f6f6f;
//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vi vis, color, level; int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

int n;
ll tree[(int)2e5+10];
ll query(int idx){
	ll ans=0;
	for(;idx;idx-=idx&-idx){
		ans=max(tree[idx], ans);
	}
	return ans;
}
void update(int pos, ll val){
	for(int idx=pos;idx<=n;idx+=idx&-idx) tree[idx]=max(tree[idx],val);
}
///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

cin>>n;
vv<ll> h(n), a(n);
for(int i=0;i<n;++i) cin>>h[i];
for(int i=0;i<n;++i) cin>>a[i];
//for(int i=0;i<n;++i) DD(h[i], a[i]);
for(int i=0;i<n;++i){
	ll val=query(h[i]-1)+a[i];
	update(h[i], val);	
//	cerr<<val<<el;
}
cout<<query(n)<<el;

return 0;
}


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

int main(){
  ll x,y; cin >> x >> y;
  vector<ll> A;
  A.push_back(x);
  for (int i = 0; A.at(i) * 2 <= y; i++)
  {
    A.push_back(A.at(i)*2);
  }
  cout << A.size() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  string s1, s2 ;
  cin >> s1 >> s2;
  reverse(ALL(s2));
  if (s1 == s2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int n, s[105], M, m, S, i;
    n=1;
    while (n!=0) {
        scanf("%d", &n);
        if (n==0) break;
        M=-1; m=1001; S=0;
        for (i=1; i<=n; i++) {
            scanf("%d", &s[i]);
            if (s[i]>M) M=s[i];
            if (s[i]<m) m=s[i];
            S+=s[i];
        }
        printf("%d\n", (S-M-m)/(n-2));
    }
    return 0;
}


Measured memory_bytes: 2040
#include <cstdio>
#include <algorithm>

const int MN = 205;

int N, A[MN];

int main() {
	scanf("%d", &N), N *= 2;
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	std::sort(A + 1, A + N + 1);
	int Sum = 0;
	for (int i = 1; i <= N; i += 2) Sum += A[i];
	printf("%d\n", Sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
map<char, int> s;
int main()
{
	int n, *p, *q, count = 0;
	cin>>n;
	p = new int[n + 5];
	q = new int[n + 5];
	q[0] = 0;
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		cin>>p[i];
		sum = sum + p[i];
		if(p[i] % 10)
			q[count++] = p[i];
	}
	if(!q[0]) {cout<<"0"<<endl;delete [] p;delete [] q;return 0;}
	sort(p, p + n);
	sort(q, q + count);
	int flag = 0;
	for(int i = 0; i < n; i++)
	{
		if(sum % 10)
		{
			flag = 1;
			break;
		}
		if((sum - p[i])%10)
			sum = sum - p[i];
	}
	flag == 1? cout<<sum<<endl:cout<<"0"<<endl;
	delete [] p;
	delete [] q;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
int N;
double dist[8][8];
vector <double> d;

void calcdist(int st, unsigned long left, double now) {
	if (left==0) {
		d.push_back(now);
		return;
	}
	for (int i = 0; i < N; i++) {
		if ((left & (1<<i)) > 0) {
			calcdist(i, left-(1<<i), now+dist[st][i]);
		}
	}
	return;
}


int main(void) {
	int x[8], y[8];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

	for (int st = 0; st < N; st++) {
		for (int en = 0; en < N; en++) {
			dist[st][en] = sqrt((x[en]-x[st])*(x[en]-x[st])+(y[en]-y[st])*(y[en]-y[st]));
		}
	}


	long pattern = 1;
	unsigned long used = 0;
	for (int i = 1; i <= N; i++) used += (1 << (i-1));

	d.clear();
	for (int st = 0; st < N; st++) {
		calcdist(st, used - (1 << st), 0);
	}

	double sum = 0;
	for (unsigned int i = 0; i < d.size(); i++) {
		sum += d.at(i);
	}
	cout << setprecision(10);             // 出力精度を10桁にする
	cout << setiosflags(ios::scientific); // 出力精度を小数部に適用
	cout << sum / d.size() << endl;
	return 0;
}


Measured memory_bytes: 892
#include<iostream>

int main()
{
    int A,B,C;
    std::cin>>A>>B;
    std::string res;
    
    if(A==2 || B==2)
    {
        res="No";
    }
    else
    {
        res="Yes";
    }
    std::cout<<res.c_str()<<std::endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
import heapq
que = []
for i, b in enumerate(B):
    heapq.heappush(que, (-b, i))
flag = True
ans = 0
while que:
    b, i = heapq.heappop(que)
    b = -b
    if b == A[i]:
        continue
    a, c = B[(i-1)%N], B[(i+1)%N]
    if b-A[i]<a+c:
        flag = False
        break
    r = (b-A[i])//(a+c)
    b-=(a+c)*r
    B[i] = b
    ans+=r
    if b!=A[i]:
        heapq.heappush(que, (-b, i))
if flag:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 122904
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string Replace(string,string,string);

int main(){
  string str;
  bool flag = false;
  while(cin >> str){
    
    str = Replace(str,"apple","-");
    str = Replace(str,"peach","apple");
    str = Replace(str,"-","peach");

    if(flag){
      cout << " ";
    }
    cout << str;
    flag = true;
  }
  cout << endl;
}

//  ツ閉カツ篠堋療アツづーツ置ツ環キツつキツづゥ
string Replace( string String1, string String2, string String3 )
{
    string::size_type  Pos( String1.find( String2 ) );

    while( Pos != string::npos )
    {
        String1.replace( Pos, String2.length(), String3 );
        Pos = String1.find( String2, Pos + String3.length() );
    }

    return String1;
}

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

ll p(ll a, int n) {
  ll b = 1;
  for(int i=0;i<n;i++) {
    b *= a;
    b %= MOD;
  }
  return b;

}

ll solve(ll n) {
  if(n == 1) {
    return 0;
  }
  ll res = p(10, n) % MOD;
  res = (res - p(9, n)) % MOD;
  if(res < 0)
    res += MOD;
  res = (res - p(9, n)) % MOD;
  if(res < 0)
    res += MOD;
  res = (res + p(8, n)) % MOD;
  /*
  ll res=p(10,n)-p(9,n)-p(9,n)+p(8,n);
  res%=MOD;
  res=(res+MOD)%MOD;
  */
  return res;
}

int main() {
  ll n;
  cin >> n;
  cout << solve(n);
}

Measured memory_bytes: 3564