akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int N;
  long long D, A;
  scanf("%d",&N);
  scanf("%lld",&D);
  scanf("%lld",&A);
  std::vector<std::pair<long long, long long> > op(N);
  for (int i=0; i<N; i++){
    scanf("%lld",&op[i].first);
    scanf("%lld",&op[i].second);
  }
  std::sort(op.begin(), op.end());
  long long current_fire = 0;
  long long ans = 0;
  std::queue<std::pair<long long, long long > > queue;
  for (int i=0; i<op.size(); i++){
    while (queue.size()>0 && queue.front().first<op[i].first){
      current_fire -= queue.front().second;
      queue.pop();
    }
    if (current_fire < op[i].second){
      ans += (op[i].second-current_fire+A-1)/A;
      queue.push(std::make_pair(op[i].first+2*D, ((op[i].second-current_fire+A-1)/A)*A));
      current_fire += ((op[i].second-current_fire+A-1)/A)*A;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 4992
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 日 10/ 8 19:56:21 2017
 * Ended  Time*  : 日 10/ 8 20:06:14 2017
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

map<int, int>cnt;
int n, m;

int main()
{
	bool flag = true;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d", &x);
		cnt[x]++;
	}
	scanf("%d", &m);
	for(int i = 1; i <= m; i++){
		int x;
		scanf("%d", &x);
		if(cnt[x] <= 0) flag = false;
		cnt[x]--;
	}
	if(flag) printf("YES\n");
	else printf("NO\n");
    return 0;
}


Measured memory_bytes: 9728
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long x,a,b,l=0;
    cin>>x;
    for(b=-1000;b<=1000;b++)
    {
        for(a=0;a<=1000;a++)
        {
            if(((a*a*a*a*a)-(b*b*b*b*b))==x)
            {
                l++;
               cout<<a<<" "<<b<<endl;
                break;
            }
        }
        if(l>0)
        {
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
int m,n;
bool t[22][11000];
int dp[10000][11000];
int main(){
while(cin>>m>>n,n||m){
rep(i,2000)rep(j,10000)dp[i][j]=0;
rep(i,22)rep(j,10000)t[i][j]=0;
rep(i,m){
	rep(j,n)cin>>t[i][j];
}

int ans=0,cnt=0;
rep(i,(1<<m)){

	cnt=0;
	rep(j,n){
		rep(k,m){
			if(i&(1<<k)&&t[k][j])dp[i][j]++;
			if((!(i&(1<<k)))&&!t[k][j])dp[i][j]++;
			
		}
	}
	rep(j,n)cnt+=max(dp[i][j],m-dp[i][j]);
	ans=max(cnt,ans);
}

	cout<<ans<<endl;
}
	return 0;
}



Measured memory_bytes: 89160
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

constexpr int MAX_N = 100005;

bool prime[MAX_N];
bool ok[MAX_N];
int sum[MAX_N+10];  // ok[0..i)

int main(){
    rep(i,MAX_N) prime[i] = true;
    prime[0] = false;
    prime[1] = false;
    for(int i=2;i<MAX_N;i++) if(prime[i]) for(int j=2;i*j<MAX_N;j++) prime[i*j] = false;

    for(int i=0;i<MAX_N;i++) ok[i] = false;
    for(int i=1;i<MAX_N;i++) if(i%2) if(prime[i] and prime[(i+1)/2]) ok[i] = true;

    for(int i=0;i<MAX_N;i++){
        int d = ok[i];
        sum[i+1] = sum[i] + d;
    }

    int q;
    cin >> q;
    rep(i,q){
        int l,r;cin >> l >> r;
        cout << sum[r+1] - sum[l] << endl;
    }
}


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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline ll toInt(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int s(ll x){
  int res = 0;
  while(x!=0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

double f(ll i){
  return (double)i/(double)(s(i));
}


ll f2(ll x){
  string s = toString(x);
  vector<pair<double,ll>> p;
  p.push_back(make_pair(f(toInt(s)),toInt(s)));
  for(int i = s.size()-1 ; i >= 0; i--){
    s[i] = '9';

    p.push_back(make_pair(f(toInt(s)),toInt(s)));
  }
  sort(all(p));
  
  return p[0].second ;
}



ll make(int digit, int n){
  string s = "";
  s += toString(digit);
  rep(i,n){
    s += "9";
  }
  return toInt(s);
}

int main(){
  ll k;
  cin >> k;
  VLL ans;
  ans.push_back(1);
  ll fNum = 1;

  rep(i,k){
    fNum = f2(fNum+1);
    ans.push_back(fNum);
  }
  rep(i,k){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
	if(b==0) return a;
	return gcd(b, a%b);
}


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	if(n%1000!=0) cout<<1000-n%1000;
	else cout<<n%1000<<endl;
	return 0;
}

Measured memory_bytes: 3676
while True:
    n, x = map(int, input().split())
    if(n == 0 and x == 0):break
    c=0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i+j+k==x:c+=1
    print(c)


Measured memory_bytes: 5596
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin>>n;
    vector<ll> c(n+1);
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j+=i) c[j]++;
    }
    ll ans=0;
    for(int i=0;i<=n;i++) ans+=i*c[i];
    cout<<ans<<endl;
}

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

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

	if(S=="hi" || S=="hihi" || S=="hihihi" || S=="hihihihi" || S=="hihihihihi")
		cout << "Yes";
	else
		cout << "No";
	cout << endl;
}

Measured memory_bytes: 256
num_man, num_candy = map(int, input().split())

lis = [0]*num_man
for i in range(num_candy):
    sum = int(input())
    l_tmp = list(map(int, input().split()))
    for j in range(sum):
        lis[l_tmp[j]-1] = 1
ans = 0
for i in range(num_man):
    if(lis[i] == 0):
        ans += 1
print(ans)


Measured memory_bytes: 9188
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
#include <string>
//typedef long long LL;
using namespace std;
 
int main(){
    int n;
    string s;
    string t;
    cin >> n;
    cin >> s >> t;
    for(int i=0; i<n; i++){
        cout << s[i] << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
use std::cmp::min;
use std::io;
use std::io::prelude::*;

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let mut iter = buf.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let k = iter.next().unwrap().parse().unwrap();
    let a: Vec<usize> = iter.map(|nstr| nstr.parse().unwrap()).collect();

    let mut i = 0;
    let mut j = 0;
    let mut occ = vec![0; k + 1];
    let mut dis = 0;
    let mut ans = std::usize::MAX;
    while j < n && ans > k {
        if a[j] <= k {
            if occ[a[j]] == 0 {
                dis += 1;
            }
            occ[a[j]] += 1;
        }
        j += 1;
        while a[i] > k || occ[a[i]] > 1 {
            if a[i] <= k {
                occ[a[i]] -= 1;
            }
            i += 1;
        }
        if dis == k {
            ans = min(ans, j - i);
        }
    }
    if ans == std::usize::MAX {
        ans = 0;
    }

    println!("{}", ans);
}



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

int main() {
  int N;
	cin >> N;
  int current_val = 0;
  int max_val = 0;
  int flg = 0;
  for(int i=0;i<N;i++) {
    cin >> current_val;
    if(max_val <= current_val) {
      max_val = current_val;
    } else if (max_val - 1 <= current_val) { 
      max_val = max_val;
    } else {
      flg = 1;
    }
  }
  if(flg == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Measured memory_bytes: 256
import numpy as np

N, M, C = map(int, input().split())
B = np.array(input().split(), dtype=np.int32)
A = np.array([list(map(int, input().split())) for _ in range(N)])

p = np.sum(A * B, axis=-1) + C
print(np.count_nonzero(p > 0))


Measured memory_bytes: 12468
import sys
for e in sys.stdin:
 d=[{'o':1,'x':-1,'s':0}[s]for s in e.strip()]
 a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])]
 print('dxo'[(-3in a)+(3in a)*2])


Measured memory_bytes: 5568
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

typedef long long ll;

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; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

ll dp[105][100005];
int v[105];
ll w[105];

int main()
{
  int n;
  ll W;
  cin >> n >> W;
  int maxV = 0;
  rep(i, n) {
    cin >> w[i+1] >> v[i+1];
    chmax(maxV, v[i+1]);
  }

  rep(i, maxV * n + 1) {
    dp[0][i] = INF;
  }
  rep(i, n+1) {
    dp[i][0] = 0;
  }
  dp[0][0] = 0;

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    for (ll j = 1; j <= maxV * n; j++) {
      if (v[i] <= j) {
        dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
      } else {
        dp[i][j] = dp[i-1][j];
      }
      if (dp[i][j] <= W) {
        chmax(ans, j);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 80128
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,i=1,x=100000000;
  cin>>n;
  if(n==1 || n==2){
  cout<<4<<endl;
  }
  else{
    for(int j=1;j<x;j++){
      if(n==1)
        break;
      else if(n%2==0){
        n=n/2;
        i++;
      }
      else{
        n=n*3+1;
        i++;
      }
    }
    cout<<i+1<<endl;
  }
}

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

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

    int a, b;
    cin >> a >> b;
    int add = 0;
    int num = 1;

    do {
        add += num;
        ++num;
    } while (num < b-a);

    cout << add - a << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>

long dx(long g){
  long goal = 2 * g;
  long count = std::sqrt(goal);
  return count;
}

int main(){
  long X;
  std::cin >> X;
  long ans = dx(X);
  long dis = ans * (ans + 1) / 2;
  while(X > dis){
    ans++;
    dis += ans;
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  string S; cin >>S;
  int A=S[0]-'0',B=S[1]-'0',C=S[2]-'0',D=S[3]-'0';
  if (A-B-C-D==7) cout <<A <<'-' <<B <<'-' <<C <<'-' <<D <<"=7" <<endl;
  else if (A-B-C+D==7) cout <<A <<'-' <<B <<'-' <<C <<'+' <<D <<"=7" <<endl;
  else if (A-B+C-D==7) cout <<A <<'-' <<B <<'+' <<C <<'-' <<D <<"=7" <<endl;
  else if (A-B+C+D==7) cout <<A <<'-' <<B <<'+' <<C <<'+' <<D <<"=7" <<endl;
  else if (A+B-C-D==7) cout <<A <<'+' <<B <<'-' <<C <<'-' <<D <<"=7" <<endl;
  else if (A+B-C+D==7) cout <<A <<'+' <<B <<'-' <<C <<'+' <<D <<"=7" <<endl;
  else if (A+B+C-D==7) cout <<A <<'+' <<B <<'+' <<C <<'-' <<D <<"=7" <<endl;
  else if (A+B+C+D==7) cout <<A <<'+' <<B <<'+' <<C <<'+' <<D <<"=7" <<endl;
  return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
s = input()

m = {
  'S': {
    'S': {'o': 'S', 'x': 'W'},
    'W': {'o': 'W', 'x': 'S'},
  },
  'W': {
    'S': {'o': 'W', 'x': 'S'},
    'W': {'o': 'S', 'x': 'W'},
  }
}
import itertools
for p, c in itertools.product(['S','W'], ['S','W']):
  ans = [p, c]
  for a in s:
    p,c = c, m[p][c][a]
    ans.append(c)
  if ans[:2] == ans[-2:]:
    print(''.join(ans[1:-1]))
    exit(0)
print(-1)

Measured memory_bytes: 4964
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S; cin >> S;
    if (S == "Sunny") cout << "Cloudy";
    else if (S == "Cloudy") cout << "Rainy";
    else cout << "Sunny";
    cout << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

s = ins()
print("Yes" if s[2] == s[3] and s[4] == s[5] else "No")

Measured memory_bytes: 9124
#include <iostream>
#include <stack>
using namespace std;
int main(){
  string name;
  cin >> name;
  int ret = 0;

  for(int i = 0 ; i < name.size()/2 ; i++){

    if(name[i] == 'i' || name[i] == 'w'){

      if(name[i] != name[name.size()-1-i])ret++;

    } else if((name[name.size() - 1 - i] == ')' ||
	       name[name.size() - 1 - i] == '('))
      {
	if(name[i] == name[name.size()-1-i])ret++;

      }else if( name[i] != name[name.size()-1-i])ret++;
  } 
  if(name.size()%2 == 1 && 
(name[ (name.size() - 1)/2 ] == ')' ||name[ (name.size() - 1)/2 ] == '('))ret++;

  cout << ret << endl;

  return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int k, a, b;
  cin >> k >> a >> b;
  cout << (b / k * k >= a ? "OK\n" : "NG\n");
}


Measured memory_bytes: 3652
require 'set'

n, m = gets.split.map(&:to_i)
s = gets.split.join.to_i(2)
g = gets.split.map(&:to_i)

queue = [s]
reached = Set[s]
step = 0

loop do
    new_queue = []
    until queue.empty?
        x = queue.pop
        if sprintf("%0#{n}b",x).scan(/0+|1+/).map(&:size) == g
            p step
            exit
        end

        (0..n-2).each do |i|
            next if [0b11, 0b00].include?((x >> i) & 0b11)
            y = x ^ (0b11 << i)
            next if reached.include?(y)
            reached << y
            new_queue << y
        end
    end
    queue = new_queue
    step += 1
    break if queue.empty?
end

Measured memory_bytes: 9388
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    		Scanner scan =new Scanner(System.in);
    		int n=Integer.parseInt(scan.next());
    		int m=Integer.parseInt(scan.next());
    		
    		
    		int ans=n*(n-1)/2+m*(m-1)/2;
    		System.out.print(ans);
    }
    }
// end 

Measured memory_bytes: 21588
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
// #include <atcoder/all>

#define REPI(i, S, N) for(int i=int(S); i<int(N); i++)
#define REP(i, N) REPI(i, 0, N)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
// using mint = atcoder::modint1000000007;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> N;


  ll r = 0;
  for (ll i = 1; i <= N; i++) {
    ll b = N / i;
    if (i*b == N) b--;
    r += b;
  }
  return r;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void){
  int n, h;
  cin >> n >> h;
  int a[n], b[n];
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
  sort(a, a + n, greater<int>());
  sort(b, b + n, greater<int>());
  int ans = 0;
  int sum = 0;
  bool flag = false;
  for(int i = 0; i < n; i++){
    if(!flag){
      if(b[i] < a[0]) break;
      sum += b[i];
      ans++;
      if(sum >= h) flag = true;
    }
  }
  h -= sum;
  if(h > 0){
    int temp = ceil((double) h / a[0]);
    ans += temp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

string s,t;

int32_t main(){
	cin>>s>>t;
	for(int i=s.length()-1;i>=0;i--){
		for(int j=0;j<t.length();j++){
			if(s[i+j]!=t[j] && s[i+j]!='?'){
				goto fin;
			}
		}
		for(int j=0;j<t.length();j++){
			if(s[i+j]=='?'){
				s[i+j]=t[j];
			}
		}
		for(int j=0;j<s.length();j++){
			if(s[j]=='?'){
				cout<<"a";
			}
			else {
				cout<<s[j];
			}
		}
		return 0;
		fin:1;
	}
	cout<<"UNRESTORABLE";
}


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

int main()
{
    int x,y,z,a,b;
    cin>>x>>y>>z;

    a=y/x+1;
    b=a*x;

    if(b<=z)
        cout<<"OK";
    else if(y%x==0 || z%x==0)
        cout<<"OK";
    else
        cout<<"NG";
    return 0;
}


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

using namespace std;


#define MAXN 502
#define MAXM 200001
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, Q, a[MAXN][MAXN] = {};
  cin >> n >> m >> Q;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    a[l][r]++;
  }
  int sum[MAXN][MAXN] = {};
  for (int i = MAXN-2; i >= 0; --i) {
    for (int j = 1; j < MAXN; ++j) {
      sum[i][j] = a[i][j] + sum[i+1][j] + sum[i][j-1] - sum[i+1][j-1];
    }
  }

  while(Q--) {
    int p, q;
    cin >> p >> q;
    cout << sum[p][q] << '\n';
  }
  return 0;
}


Measured memory_bytes: 2944
/*
AIZU
A0507.c
*/
#include <stdio.h>


int result[100];
int resultptr;

extern void bunpai(int,int,int);

main()
{
int n;
  
resultptr = 0;

  
  while(EOF != scanf("%d",&n) && n > 0)
    {
      bunpai(n,n,0);
    }
  return(0);
}

void print_result(int resultptr)
{
  
  int i;
  for(i=0;i<resultptr;i++)
    {
      if(i)
        printf(" ");
      printf("%d",result[i]);
    }
  printf("\n");
  
}


void bunpai(int sum,int maxval,int resultptr)
{
        int i;

/* printf("s m r=%d %d %d\n",sum,maxval,resultptr); */
  

  if(0 == sum)
  {
     print_result(resultptr);
    return;
  }
  else if(maxval > 1)
    {
      for(i=maxval;i>=2;i--)
        { 
          if(sum >= i)
            {
                result[resultptr] = i;
                bunpai(sum - i,i,resultptr+1);
            }
        }
    }
  
    {
      for(i=0;i<sum;i++)
        result[resultptr++]=1;

      print_result(resultptr); 
    }
}

Measured memory_bytes: 0
using System;

class Program
{
    static void Main()
    {
            int i;
            string len = Console.ReadLine();
            int[] su = new int[int.Parse(len)];
            string inp = Console.ReadLine();
            string[] data = inp.Split(' ');
            for(i=0;i<=int.Parse(len)-1; i++)
            {
                su[i] = int.Parse(data[i]);
            }
            for (i = int.Parse(len)-1; i >= 0; i--)
            {
                Console.Write("{0}", su[i]);
                if (i != 0)
                {
                    Console.Write(" ");
                }
            }
            Console.Write("\n");
    }
}


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

int main(){
    int x;cin>>x;
    
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

   for(int i=x;i<100010;i++) if(is_prime[i]){ x=i;break; }

cout<<x<<endl;
    }

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include <vector>
#include<map>
#include<algorithm>
#include<iomanip>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	int a, b;
	cin >> a >> b;
	int c;
	int i = 0;
	while (true) {
		int t = a * i - (i - 1);
		if (t >= b) break;
		i++;
	}
	cout << i << endl;
}

Measured memory_bytes: 256
/* vim:set foldmethod=marker: */
#include <bits/stdc++.h>
using namespace std;

//{{{
#define all(x) (x).begin(),(x).end()
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define RREP(i,a,b) for(int i=(int)(a); i>=b; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

#define dump(x) (cerr << #x << "=" << x << endl)
template<class T> ostream& osContainer(ostream& os,T c) { os<<'[';for(decltype(c.begin()) it=c.begin();it!=c.end();it++)os<<*it<<',';os<<']';return os; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { return osContainer(os,v); }
template<class T> ostream& operator<<(ostream& os,const set<T>& s) { return osContainer(os,s); }
template<class T> ostream& operator<<(ostream& os,const multiset<T>& s) { return osContainer(os,s); }
template<class T,class S> ostream& operator<<(ostream& os,const map<T,S>& m) { return osContainer(os,m); }
template<class T,class S> ostream& operator<<(ostream& os,const multimap<T,S>& m) { return osContainer(os,m); }
template<class T1,class T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p){ os << '(' << p.first << ',' << p.second << ')'; return os; }

//}}}

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

void solve()
{
    int N;

    while(cin>>N, N) {
        int lx=0, ly=0, ux=0, uy=0;
        vector<pair<int, int>> v{mp(0,0)};
        rep(i, N-1) {
            int n, d;
            cin >> n >> d;

            auto p = v[n];
            int py = p.first + dy[d], px = p.second + dx[d];
            v.push_back(mp(py, px));
            lx = min(lx, px);
            ly = min(ly, py);
            ux = max(ux, px);
            uy = max(uy, py);
        }

        cout << ux - lx + 1 << " " << uy - ly + 1 << endl;
    }

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(12);
    solve();
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	cout<<(a+b/2)<<"\n";
	return 0;
}

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

#define lld long long int
#define llu unsigned long long

int main()
{
    //freopen("input.txt", "w", stdin);

    int x,y;
    while(cin>>x>>y)
    {
        if( !(x%3) || !(y%3) || !((x+y)%3) )
            cout<<"Possible"<<endl;
        else
            cout<<"Impossible"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
import math
import random
N = int(input())
X = []
Y = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
suma = 0
for i in range(N):
    r = []
    for j in range(N):
        if i == j:
            continue
        r.append(math.atan2(Y[j] - Y[i], X[j] - X[i]))
    r.sort()
    dr = [r[i + 1] - r[i] for i in range(len(r) - 1)]
    dr.append(r[0] + 2 * math.pi - r[-1])
    print((max(dr) - math.pi) / (2 * math.pi) if max(dr) > math.pi else 0)


Measured memory_bytes: 5224
n=int(input())
a=list(map(int,input().split()))

find_num=1
break_num=0
flag = False
for i in range(n):
    if a[i] == find_num:
        find_num+=1
        flag = True
    else:
        break_num+=1

if flag:
    print(break_num)
else:
    print(-1)


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


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

    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        if(s == "Y"){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>

using namespace std;

using P = pair<int, int>;
using i64 = int64_t;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;


int main(int argc, char **argv) {
    int n;
    cin >> n;
    cout << n * n * n <<endl;

    return 0;
}

Measured memory_bytes: 256
import math

times = []
for i in range(5):
    time = int(input())
    times.append(time)

mods = [i % 10 for i in times]
index = 0
mod = 10
all_time = 0

if sum(mods) == 0:
    for time in times:
        all_time += time
else:
    for i in range(5):
        if mods[i] <= mod and mods[i] != 0:
            index = i
            mod = mods[i]
    all_time = 0
    for i in range(5):
        if i == index:
            all_time += times[i]
        else:
            all_time += math.ceil(times[i]/10.0) * 10

print(all_time)

Measured memory_bytes: 3064
#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define SF scanf
#define PF printf
#define PC putchar

const int MAXN = 200005;

int n, K, L, fa[MAXN], father[MAXN];

int find1(int x) { return (father[x] == 0) ? x : father[x] = find1(father[x]); }
int find2(int x) { return (fa[x] == 0) ? x : fa[x] = find2(fa[x]); }

map<pair<int, int> , int> s;

int main ()
{
	int x, y;
	SF("%d%d%d", &n, &K, &L);
	for(int i = 1; i <= K; i++)
	{
		SF("%d%d", &x, &y);
		int xx = find1(x), yy = find1(y);
		if(xx != yy) father[yy] = xx;
	}
	for(int i = 1; i <= L; i++)
	{
		SF("%d%d", &x, &y);
		int xx = find2(x), yy = find2(y);
		if(xx != yy) fa[yy] = xx;
	}
	for(int i = 1; i <= n; i++) s[make_pair(find1(i), find2(i))]++;
	for(int i = 1; i <= n; i++) PF("%d ", s[make_pair(find1(i), find2(i))]);
}

Measured memory_bytes: 12672
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100010];

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

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 1; i < N; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 5112
#include <iostream>

using namespace std;

int main(){
  int a[3][3];

  for(int i = 0; i<3; i++){
    for(int j = 0; j<3; j++){
      cin >> a[i][j];
    }
  }

  int m = 0, N;
    cin >> N;
  while(m < N){
    int b;
    cin >> b;
    for(int i = 0; i < 10; i++){
      for(int j = 0; j < 10; j++){
        if(a[i][j] == b) a[i][j] = 0;
      }
      //if(a[i][0] == a[i][1] || a[i][1] == a[i][2] || a[i][] == a[][])
    }
    ++m;
  }

  if(a[0][0]==a[0][1]&&a[0][1]==a[0][2]){
    cout << "Yes" << endl;
    //break;
  }
  else if(a[1][0]==a[1][1]&&a[1][1]==a[1][2]){
    cout << "Yes" << endl;
    //break;
  }
  else if(a[2][0]==a[2][1]&&a[2][1]==a[2][2]){
    cout << "Yes" << endl;
    //break;
  }
  else if(a[0][0]==a[1][0]&&a[1][0]==a[2][0]){
    cout << "Yes" << endl;
    //break;
  }
  else if(a[0][1]==a[1][1]&&a[1][1]==a[2][1]){
    cout << "Yes" << endl;
   // break;
  }
  else if(a[0][2]==a[1][2]&&a[1][2]==a[2][2]){
    cout << "Yes" << endl;
    //break;
  }
  else if(a[0][0]==a[1][1]&&a[2][2]==a[1][1]){
    cout << "Yes" << endl;
    //break;
  }
  else if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]){
    cout << "Yes" << endl;
    //break;
  }

  else cout << "No" << endl;
  
}


Measured memory_bytes: 256
S=input()
N=len(S)
mod=998244353
red=[0]*N
blue=[0]*N
for i in range(N):
    if S[i]=="0":
        red[i]+=2
    elif S[i]=="1":
        red[i]+=1
        blue[i]+=1
    else:
        blue[i]+=2
    if i!=0:
        red[i]+=red[i-1]
        blue[i]+=blue[i-1]
R=red[-1]
B=blue[-1]

dp=[[0 for i in range(2*N+1)] for i in range(2*N+1)]

dp[2*N][R]=1

for i in range(2*N-1,-1,-1):
    for j in range(2*N+1):
        if i>=N:
            r=R-j
            b=B-(i-j)
            if r and 2*N>=j+1:
                dp[i][j]+=dp[i+1][j+1]
                dp[i][j]%=mod
            if b:
                dp[i][j]+=dp[i+1][j]
                dp[i][j]%=mod
        else:
            r=red[i]-j
            b=blue[i]-(i-j)
            if r and 2*N>=j+1:
                dp[i][j]+=dp[i+1][j+1]
                dp[i][j]%=mod
            if b:
                dp[i][j]+=dp[i+1][j]
                dp[i][j]%=mod


print(dp[0][0])

Measured memory_bytes: 170504
#include<bits/stdc++.h>  
using namespace std;
const int INF = 999;
//世界一競技プログラミングができない人のソース
int N, M, b, Exit, mask;
int v[1 << 15];
int ret;
void rec(int digit, int cnt){
  if(cnt >= ret) return;
  if(digit == Exit || digit == ((~Exit) & mask)){
    ret = min( ret, cnt);
    return;
  } else if(v[digit & mask] <= cnt){
    return;
  } else {
    v[digit] = cnt;
    const int prev = digit;
    for(int i = 0; i < N - 1; ++i){
      digit &= ~(3 << i);
      digit |= ((prev >> i) & 1) << (i + 1);
      digit |= ((prev >> (i + 1)) & 1) << i;
      rec( digit, cnt + 1);
      digit = prev;
    }
  }
}

int main(){
  fill_n( v, 1 << 15, INF);
  ret = INF;

  cin >> N >> M;
  mask = (1 << N) - 1;
  for(int i = 0; i < N; ++i){
    bool d;
    cin >> d;
    b |= d << (N - i - 1);
  }
  int cnt = 0;
  bool flip = false;
  for(int i = 0; i < M; ++i){
    int p;
    cin >> p;
    while(p--){
      Exit |= (int)flip << (N - cnt - 1);
      ++cnt;
    }
    flip ^= 1;
  }
  rec(b, 0);
  cout << ret << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:
const ll inf=1LL<<50;

// Description: ??°??????????????????
using edge=struct{int to;ll cost;};
using G=vector<vector<edge>>;

void add_edge(G &graph,int from,int to,ll cost){
	graph[from].push_back({to,cost});
}

//TimeComplexity $\mathcal{O}(E\log V)$
template <typename W> auto dijkstra(const G &graph,int s,W inf){
    const int n=graph.size();
    vector<W> dist(n,inf);
    using state=tuple<W,int>;
    priority_queue<state,vector<state>,greater<state>> q;
    dist[s]=0,q.push(state(0,s));
    
    while(!q.empty()){
        W c; int v;
        tie(c,v)=q.top();q.pop();
        for(auto &e:graph[v]){
            W nc=c+e.cost; int nv=e.to;
            if(chmin(dist[nv],nc)) q.push(state(nc,nv));
        }
    }
    return dist;
}

int main(void){
	int n,m,s;
	cin >> n >> m >> s;
	G graph(n);

	rep(i,m){
		int a,b; ll c;
		cin >> a >> b >> c;
		add_edge(graph,a,b,c);
	}

	auto dist=dijkstra<ll>(graph,s,inf);
	rep(i,n){
		if(dist[i]==inf)
			cout << "INF" << endl;
		else
			cout << dist[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 19444
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

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

    cout << int(pow(2, int(log2(n)))) << endl;
}

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

int main() {
	vector<int>v;
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int h, m;
		cin >> h >> m;
		v.push_back(h * 60 + m);
	}
	int l;
	cin >> l;
	for (int i = 0;i < l;i++) {
		int h, m;
		cin >> h >> m;
		v.push_back(h * 60 + m);
	}
	sort(v.begin(), v.end());
	int a = v.size();
	for (int i = 0;i < a;i++) {
		int b = v[i] / 60;
		int c = v[i] % 60;
		printf("%d:%02d", b, c);
		if (i!=a-1&&v[i] == v[i + 1])i++;
		if (i == a - 1)cout << endl;
		else cout << ' ';
	}
	return 0;
}

Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int MAXN = 209;
ll a[MAXN]; char s[MAXN];
int main()
{
	int T; scanf("%d", &T);
	while (T--)
	{
		int n; scanf("%d", &n);
		for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
		scanf("%s", s + 1);
		vector<ll> v;
		bool flag = 1;
		for (int i = n ; i >= 1; i--)
		{
			ll b = a[i];
			for (int k = 0; k < v.size(); k++) b = min(b, b ^ v[k]);
			if (b) {
				if (b) {
					if (s[i] == '1') {flag = 0; break;}
					v.push_back(b);
				}
			}

		}
		if (flag) puts("0");
		else puts("1");
	}
	return 0;
}

Measured memory_bytes: 3616
N,K = input().split()

CalcList = tuple(range(int(K), int(N)+2))
N = int(N)
#print(CalcList)

ans = 0

for i in CalcList:
    tmp = 0
    min = i * (i-1) /2
#    print(min)
    max = i * N -min
#    print(max)

    tmp = max - min +1
    ans += tmp

ans = ans % (10 ** 9 +7)
    
print(int(ans))


Measured memory_bytes: 72556
a = [[] for _ in range(3)]
for i in range(3):
    a[i] = list(map(int, input().split()))
n = int(input())
b_arr = [int(input()) for _ in range(n)] 
for b in b_arr:
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = 0
isB = False
for c in range(3):
    if a[0][c] + a[1][c] + a[2][c] == 0:
        isB = True
for r in range(3):
    if a[r][0] + a[r][1] + a[r][2] == 0:
        isB = True
if a[0][0] + a[1][1] + a[2][2] == 0:
    isB = True
if a[0][2] + a[1][1] + a[2][0] == 0:
    isB = True
print("Yes" if isB else "No")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = scan.nextInt();
		}


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

		System.out.println(cnt);
	}
}

Measured memory_bytes: 80804
#include <stdio.h>

int main(void){
  int n, m;
  scanf("%d%d", &n, &m);
  int x = 0;
  if(n >= 2) x += n * (n - 1) / 2;
  if(m >= 2) x += m * (m - 1) / 2;
  printf("%d\n", x);
}

Measured memory_bytes: 1720
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

const int maxn = 6e5 + 10; 
int a[maxn];
int m[maxn << 2];
int query(int rt,int l,int r,int ll,int rr){
    if(ll >= l && rr <= r){
        return m[rt];
    }
    int mid = ll + rr >> 1;
    int ans = 0;
    if(r <= mid)ans = max(ans,query(rt * 2,l,r,ll,mid));
    else if(l > mid)ans = max(ans,query(rt * 2 + 1,l,r,mid + 1,rr));
    else ans = max(ans,max(query(rt * 2,l,r,ll,mid),query(rt * 2 + 1,l,r,mid + 1,rr)));
    return ans;
}
void update(int rt,int l,int r,int v,int ll,int rr){
    if(l == ll && r == rr){
        m[rt] = v;
        return ;
    }
    int mid = ll + rr >> 1;
    if(l <= mid)update(rt << 1,l,r,v,ll,mid);
    else update(rt * 2 + 1,l,r,v,mid + 1,rr);
    m[rt] = max(m[rt << 1],m[rt * 2 + 1]);
}
void solved(){
    int n,k;cin>>n>>k;
    for(int i = 1; i <= n; i++)scanf("%d",&a[i]),a[i]++;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int res = query(1,max(a[i] - k,0),a[i] + k,1,maxn) + 1;
        update(1,a[i],a[i],res,1,maxn);
        ans = max(ans,res);
    }
    cout<<ans<<endl;
}
int main(){
    solved();
    return 0;
}

Measured memory_bytes: 8568
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;

int main()
{
	string a;
	cin >> a;
	if (a.substr(2, 1) == a.substr(3, 1) && a.substr(4, 1) == a.substr(5, 1)) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		cout << a + b << endl;
	}
	else {
		cout << max(a, b) * 2 - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int m = Integer.parseInt(tokenizer.nextToken());
        char [][]  nBoard = new char[n][];
        char [][]  mBoard = new char[m][];
        for (int i = 0; i < n; i++) {
            nBoard[i] = input.readLine().toCharArray();
        }
        for (int i = 0; i < m; i++) {
            mBoard[i] = input.readLine().toCharArray();
        }
        boolean state = false;
        TH:for (int i = 0; i < (n - m) + 1; i++) {
            for (int j = 0; j < (n - m) + 1; j++) {
                boolean state2 = true;
                MT:for (int k = 0; k < m; k++) {
                    for (int l = 0; l < m; l++) {
                        if (nBoard[i + k][j + l] != mBoard[k][l]){
                            state2 = false;
                                break MT;
                        }
                    }
                }
                if (state2){
                    state = true;
                    break TH;
                }

            }
        }
        System.out.println(state? "Yes" : "No");
    }
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string days[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	string s;
	cin >> s;
	
	for(int i = 0; i < 7; i++) {
		if(s == days[i]) {
			cout << 7 - i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int strlength(const char *s) {
	int len = 0;
	while (*s++)len++;
	return len;
}
void sort(char *s, bool asc) {
	int len = strlength(s);
	char t;
	rep(i, 0, len) {
		rep(j, i + 1, len) {
			if (asc) {
				if (*(s + i) > *(s + j)) {
					t = *(s + i);
					*(s + i) = *(s + j);
					*(s + j) = t;
				}
			}
			else {
				if (*(s + i) < *(s + j)) {
					t = *(s + i);
					*(s + i) = *(s + j);
					*(s + j) = t;
				}
			}
		}
	}
}

int strcomp(const char *s, const char *t) {
	while (*s == *t) {
		if (*s == '\0') return 0;
		s++;
		t++;
	}
	return *s - *t;
}

int main() {
	char s[101], t[101]; cin >> s >> t;
	sort(s, true);
	sort(t, false);
	cout << ((strcomp(s, t) < 0) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int cnt=0;
    for(int i=1; i<=N; i++){
        if(i%2==1) cnt++;
    }
    cout << (double)cnt/N << endl;



    return 0;
}

Measured memory_bytes: 256