akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define N 10001
#define INF 10000000000
using namespace std;

typedef long long ll;

int main()
{
    vector<int> v;
    vector<int> res;
    int n, tmp;
    cin >> n;
    v.push_back(0); 
    FOR(i,1,n+1)
    {
        cin >> tmp;
        v.push_back(tmp);
    }

    mFOR(i, n,0)
    {
        int check = i;
        while(check>0)
        {
            if(check == v[check])
            {
                res.push_back(check);
                v.erase(v.begin()+check);
                break;
            }
            check--;
        }
        if(check == 0)
        {
            cout << -1 << "\n";
            return 0;
        }
    }

    FOR(i,0,n)
    {
        cout << res[n-1-i] << "\n";
    }

    return 0;
}

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

using namespace std;
#define MAXN 1000
#define INF 0x3f3f3f3f
#define max(a,b) (a>b)?a:b;
int w[MAXN+1] = {0};
int v[MAXN+1] = {0};	
int N, U;	
int dp[10001] = {-1};

int search(int k, int u, int vsum){
	int res1,res2,res;
	if(k == N){ // if current item = total item
		return vsum;
	}
	else if(u < w[k]){ // weight over limit
		return search(k+1,u,vsum); // go next item 
	}
	else{
		 res1 = search(k+1,u,vsum); //
		 res2 = search(k+1, u-w[k], vsum+v[k]); // 
		 res = max(res1,res2);
		 //printf("res:\t %d\n",res);
		return res;
	}




}

int main(){

	//freopen("input21.txt", "r", stdin); // redirects standard input
	int a, b;
	int i = 0;

	
	int ans;
	scanf("%d %d", &N, &U); // N = number of item, U = Weight limit
	int total = N;
	while(total--)	{
		scanf("%d%d",&v[i],&w[i]);
		//printf("%d %d\n", w[i], v[i]);
		// getchar();
		i++;
		//printf("Count : %d\n", i);
	
	}
	//ans = search(0,U,0); // time limit exceed
	dp[0] = 0;
	for(int i = 0; i <=N ; i++){
		for(int j = U; j>=w[i] ;j--){
			dp[j] = max(dp[j-w[i]]+v[i], dp[j]);
		}

	}
	ans = *max_element(dp, dp + U + 1);
	printf("%d\n",ans);

	
}


Measured memory_bytes: 3240
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

S=input()
T=input()

if len(S) == len(T)-1 and S == T[:-1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9200
#-*-coding:utf-8-*-

def main():
    n = int(input())
    k = int(input())
    x_list = list(map(int, input().split()))

    distance = 0

    for i in x_list:
        distance += 2 * min(k - i, i)
    
    print(distance)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int A, B, C, D; cin >> A >> B >> C >> D;
  cout << min(A, B) + min(C, D) << endl;
}


Measured memory_bytes: 3584
def enq(a,x)
  b = a[i=-1]
  until b.frozen?
    return a << x  if x >= (a=b)[-1]
    return a.unshift x  if x <= a[0]
    i = a.bsearch_index {|y| x <= (y.frozen? ? y: y[0])}
    b = a[i-=1]  if (b=a[i]).frozen? ? x<b: x<b[0]
  end  if b && b=a
  return a.insert(i+1, x)  if a.size-i < 9
  i > 9 ? a[i] = [a[i],x] : a.unshift(*a.shift(i+1),x)
end
def deq(a); r = a.shift; a.unshift *a.shift if !a[0].frozen?; r end
def popq(a); r = a.pop; a += a.pop if !a[-1].frozen?; r end
N,M,*A = $<.read.split.map{|x| -x.to_i}
A.sort!
(-M).times { break if A[0]==0; enq A, -(-(deq A)/2) }
p A.flatten.inject(0,:-)

Measured memory_bytes: 14296
#include <stdio.h>
#define D_SIZE_BUFF 200000

int main()
{
    long N,K;
    int h,count=0;

    scanf("%ld %ld",&N,&K);

    for( int i=0; i<N; i++)
    {
        scanf("%d",&h);
        if(K <= h) count++;
    }

    printf("%d",count);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,q;cin>>n;
  int a[(int)1e6];
  ll ans = 0;
  rep(i,n){
    int m;cin>>m;
    a[m]++;
    ans += m;
  }
  
  cin>>q;
  rep(i,q){
    int b,c;cin>>b>>c;
    int cnt = a[b];
    a[b] = 0;
    a[c] += cnt;
    ans += (c-b)*cnt;
    print(ans);
  }
  return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int j,i,n,k;
    cin>>n>>k;
    double ara[n],ans=0,x,sum=0;
    for(i=0;i<n;i++){
        cin>>x;
        ara[i]=(x+1)/2.0;
    }
    j=0;
    for(i=0;i<n;i++){
        sum+=ara[i];
        if((i-j)+1==k){
            ans=max(ans,sum);
            sum-=ara[j];
            j++;
        }
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
    return 0;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793


   
int main(){
  int n,m;
  cin >> n >>m;
  VI l(m);
  VI r(m);
  int maxl=0;
  int minr=100000000;
  rep(i,m){
      cin >> l.at(i);
      maxl=max(l.at(i),maxl);
      cin >> r.at(i);
      minr=min(r.at(i),minr);
  }
  if(maxl>minr)cout << 0 << endl;
  else{
  int ans=minr-maxl+1;
  cout << ans << endl;
  }
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class Main{
    static public void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        long A = sc.nextLong(), B = sc.nextLong(), K = sc.nextLong();
        if(K<=A){
            A -= K;
        } else if(K <= A+B){
            B -= K-A;
            A = 0;
        } else {
            A = 0; B = 0;
        }
        System.out.println(A+" "+B);
    }
}



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

using namespace std;

vector <int> e[100005];
int dep[100005],fa[100005];

int dfs1(int x) {
  int s=x;
  for(int i=0;i<e[x].size();i++)
    if (e[x][i]!=fa[x]) {
    	int u=e[x][i];
    	fa[u]=x;dep[u]=dep[x]+1;
    	int t=dfs1(u);
    	if (dep[t]>dep[s]) s=t;
	}
  return s;
}

int d[100005],num[100005];
bool vis[100005];

int p[100005],q[100005];

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<n;i++) {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	e[x].push_back(y);
  	e[y].push_back(x);
  }
  int rt1=dfs1(1);
  fa[rt1]=dep[rt1]=0;
  int rt2=dfs1(rt1),cnt=0;
  for(int i=rt2;i;i=fa[i]) {
    num[++cnt]=i;
    vis[i]=1;
  }
  for(int i=1;i<=n;i++)
    if (!vis[i]) {
    	bool ok=0;
    	for(int j=0;j<e[i].size();j++)
    	  if (vis[e[i][j]]) {
    	  	d[e[i][j]]++;
    	  	ok=1;
    	  	break;
		  }
		if (!ok) {
			puts("-1");
			return 0;
		}
	}
  int s=0;
  for(int i=1;i<=cnt;i++) {
  	int x=num[i];
  	for(int j=1;j<=d[x];j++) p[s+j]=s+j+1;
  	p[s+d[x]+1]=s+1;
  	s+=d[x]+1;
  }
  s=0;
  for(int i=cnt;i>0;i--) {
  	int x=num[i];
  	for(int j=1;j<=d[x];j++) q[s+j]=s+j+1;
  	q[s+d[x]+1]=s+1;
  	s+=d[x]+1;
  }
  bool ok=0;
  for(int i=1;i<=n;i++)
    if (p[i]!=q[i]) {
    	ok=(p[i]<q[i]);
    	break;
	}
  if (ok) {
  	for(int i=1;i<=n;i++) printf("%d ",p[i]);
  	printf("\n");
  }
  else {
  	for(int i=1;i<=n;i++) printf("%d ",q[i]);
  	printf("\n");
  }
  return 0;
}

Measured memory_bytes: 14592
var out = function(x) {
  console.log(x);
  return x;
}

var h = function(S) {
  return Math.floor(S/3600);
}

var m = function(S) {
  return Math.floor((S%3600)/60);
}

var s = function(S) {
  return S % 60;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(input) {
  out(h(input) +':'+ m(input) + ':' + s(input));
});

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int n, t;

	cin >> n >> t;

	int cost, time;
	int ans = INT_MAX;

	int i;

	rep(i, n) {
		cin >> cost >> time;

		if (time <= t) Min(ans, cost);
	}

	if (ans == INT_MAX) Out("TLE");
  	else Out(ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int n,m,x; cin >>n>>m>>x;
    vector<int> C(n);
    int A[n][m];
    REP(i,n){
        cin>>C[i];
        REP(k,m){
            cin >> A[i][k];
        }
    }
    bool flag = false;
    int ans = INF;
    for(int bit = 0; bit < (1<<n); bit++){
        int money = 0;
        vector<int> rikai(m,0);
        REP(i,n){
            if(bit & (1<<i)){
                money += C[i];
                REP(k,m){
                    rikai[k] += A[i][k];
                }
            }
        }
        bool flag_rikai = true;
        REP(i,m){
            if(rikai[i] < x){
                flag_rikai = false; break;
            }
        }

        if(flag_rikai){
            flag = true;
            ans = min(ans,money);
        }
    }
    cout << (flag ? ans : -1) << endl;
}

Measured memory_bytes: 3660
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var sss = Console.ReadLine();
            var sum = 0;

            foreach ( var ch in sss)
            {
                if (ch == 'o')
                    sum++;
            }

            Console.WriteLine(700 + sum * 100);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
int n;
pair<int,int> p[100010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x,l;
    cin >> x >> l;
    p[i].first = x + l;
    p[i].second = x - l;
  }
  sort(p,p+n);
  int ans = 0;
  int lft = -1e9-7;
  for (int i = 0; i < n; i++) {
    if (p[i].second < lft) continue;
    ans++;
    lft = p[i].first;
  }
  cout << ans << endl;
}

/*　【提出前に確認すること】
・コンパイルできるか
・テストケース試したか
・オーバーフローあるか
*/


Measured memory_bytes: 1024
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

ll getllSubstr(string s,ll start_index,ll length){
    return atoi(s.substr(start_index,length).c_str());
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string S;
    cin >> S;

    bool flagYYMM=true;
    bool flagMMYY=true;

    ll head2 = getllSubstr(S,0,2);
    ll tail2 = getllSubstr(S,2,2);
    if(tail2==0) flagYYMM = false;
    if(head2==0) flagMMYY = false;
    if(head2>12) flagMMYY = false;
    if(tail2>12) flagYYMM = false;


    if(flagYYMM){
        if(flagMMYY){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "YYMM" << endl;
        }
    }else{
        if(flagMMYY){
            cout << "MMYY" << endl;

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

    }
    

}

Measured memory_bytes: 3620
N,M,X=map(int,input().split())
C=[list(map(int,input().split())) for _ in range(N)]

ans=inf=float('inf')
for perm in range(1,1<<N):
    tt,lvls=0,[0]*M
    for i in range(N):
        if perm&(1<<i)==0:
            continue
        tt+=C[i][0]
        for j in range(M):
            lvls[j]+=C[i][j+1]
        for j in range(M):
            if lvls[j]<X:
                break
        else:
            ans=min(ans,tt)
            break

print(ans if ans<inf else -1)


Measured memory_bytes: 74168
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int t, a, b;
int main()
{
    cin >> t >> a >> b;
    if(a > b)   swap(a, b);
    if(a + t >= b)  cout << 0;
    else
        cout << b - a - t;
    return 0;
}


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

typedef long long ll;

ll H, W;
vector<string> S;
vector<ll> Height, Left, Right;
ll R;

int main() {
  cin >> H >> W;
  S.resize(H);
  for (ll i = 0; i < H; ++i) cin >> S[i];
  Height.resize(W, 1);
  Left.resize(W, 0);
  Right.resize(W, W);
  R = max(H, W);
  for (ll i = 1; i < H; ++i) {
    vector<ll> no;
    for (ll j = 1; j <= W - 1; ++j)
      if ((S[i - 1][j - 1] == S[i - 1][j]) != (S[i][j - 1] == S[i][j])) {
        no.push_back(j);
        Height[j] = 1;
      } else
        ++Height[j];
    for (ll j = 1; j <= W - 1; ++j) {
      if (Height[j] == 1) {
        Left[j] = 0;
        Right[j] = W;
      } else {
        ll y = upper_bound(no.begin(), no.end(), j) - no.begin(), x = y - 1;
        if (x >= 0) Left[j] = max(Left[j], no[x]);
        if (y < no.size()) Right[j] = min(Right[j], no[y]);
      }
      R = max(R, (Right[j] - Left[j]) * Height[j]);
    }
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 4480
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int MOD = 1e9 + 7;

int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};

void solve()
{
    int n;
    string s;
    cin >> n >> s;
    int maxi = -1;
    rep(i, n)
    {
        map<char, int> m1, m2;
        REP(j, 0, i)
        {
            m1[s[j]]++;
        }
        REP(j, i, n)
        {
            m2[s[j]]++;
        }
        int count = 0;
        for (char c = 'a'; c <= 'z'; c++)
        {
            if (m1[c] != 0 && m2[c] != 0)
            {
                count++;
            }
        }
        maxi = max(maxi, count);
    }
    P(maxi);
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n, q;
string s;
bool check(vector<pair<char,char>> td, int mid, int type){
    int pos = mid;
    char nowchar = s[mid];
    bool res = false;
    for(int i = 0; i < q; i++){
        if(td[i].first == nowchar){
            if(td[i].second == 'L'){
                pos--;
            } else {
                pos++;
            }
            if(pos == -1){
                if(type == 0) res = true;
                break;
            }
            if(pos == n){
                if(type == 1) res = true;
                break;
            }
            nowchar = s[pos];
        }
    }

    return res;
}
int main(void){
    cin >> n >> q;
    cin >> s;

    vector<pair<char,char>> td(q);
    for(int i = 0; i < q; i++){
        cin >> td[i].first >> td[i].second;
    }

    int ok = -1;
    int ng = n;
    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if(check(td, mid, 0)){
            ok = mid;
        } else {
            ng = mid;
        }
    }

    int ans = n - ok;

    ok = n;
    ng = -1;

    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if(check(td, mid, 1)){
            ok = mid;
        } else {
            ng = mid;
        }
    }

    ans -= (n - ok + 1);

    cout << ans << endl;

}   

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

#define pb push_back
#define all(a) a.begin(), a.end()

using ll = long long;
using pii = pair<int, int>;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll D = t1 * (a1 - b1) + t2 * (a2 - b2);
    if (D == 0) {
        cout << "infinity\n";
        return 0;
    }
    if (D < 0) {
        swap(a1, b1);
        swap(a2, b2);
        D *= -1;
    }
    if (a1 > b1) {
        cout << 0 << "\n";
        return 0;
    }
    ll p = ((b1 - a1) * t1 + D - 1) / D;
    ll ans = 2 * p - 1;
    if (p * D ==  (b1 - a1) * t1)
        ++ans;
    cout << ans << "\n";
}

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

#define FIELD_WIDTH (8)
#define FIELD_HEIGHT (8)
#define BLAST_LENGTH (3)

char field[FIELD_HEIGHT][FIELD_WIDTH + 1];

void bomb(int x, int y);
void blast(int x, int y, int dx, int dy, int length);
int inBounds(int x, int y);

int main(void)
{
  int n;
  int i, j;

  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    int x, y;
    for (j = 0; j < FIELD_HEIGHT; j++) {
      scanf("%s", field[j]);
    }
    scanf("%d %d", &x, &y);
    x--;
    y--;
    bomb(x, y);

    printf("Data %d:\n", i);
    for (j = 0; j < FIELD_HEIGHT; j++) {
      printf("%s\n", field[j]);
    }
  }
  return (0);
}

void bomb(int x, int y)
{
  assert(field[y][x] == '1');
  field[y][x] = '0';
  blast(x, y, 1, 0, BLAST_LENGTH);
  blast(x, y, -1, 0, BLAST_LENGTH);
  blast(x, y, 0, 1, BLAST_LENGTH);
  blast(x, y, 0, -1, BLAST_LENGTH);
}

void blast(int x, int y, int dx, int dy, int length)
{
  if (length < 0) {
    return;
  }
  if (!inBounds(x, y)) {
    return;
  }
  if (field[y][x] == '1') {
    bomb(x, y);
  }
  blast(x + dx, y + dy, dx, dy, length - 1);
}

int inBounds(int x, int y)
{
  return (0 <= x && x < FIELD_WIDTH && 0 <= y && y < FIELD_HEIGHT);
}

Measured memory_bytes: 608
s = input()
t = input()
x = len(t)
res= 0
for i in range(len(s) - x+1):
    tmp = s[i:i+x]
    cntmp = 0
    for j in range(x):
        if t[j] == tmp[j]:
            cntmp += 1
    res = max(res, cntmp)
print(x-res)

Measured memory_bytes: 8968
N, M = map(int, input().split())
ship = [list(map(int, input().split())) for _ in range(M)]

s1 = [False] * N
sN = [False] * N

for i, s in enumerate(ship):
    if s[0] == 1:
        s1[s[1] - 1] = True

    if s[1] == N:
        sN[s[0] - 1] = True

ans = 'IMPOSSIBLE'
if any([p1 * pN for p1, pN in zip(s1, sN)]):
    ans = 'POSSIBLE'

print(ans)

Measured memory_bytes: 50056
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;

int X[4]={-1,0,1,0};
int Y[4]={0,1,0,-1};

int main()
{
  int n,x1[20001],x2[20001],y1[20001],y2[20001];
  char c;

  while(1){
    cin>>n;
    if(n==0)break;
    map<pair<int,int>,int> index;
    map<pair<int,int>,int> m;
    for(int i=0;i<n;i++){
      cin>>x1[i]>>y1[i]>>c;
      index[mp(x1[i],y1[i])]=i;
      if(c=='x'){
	x2[i]=x1[i]+1;
	y2[i]=y1[i];
      }
      else {
 	x2[i]=x1[i];
	y2[i]=y1[i]+1;
      }
      index[mp(x2[i],y2[i])]=i;
    }

    string ans="Yes";
    bool checked[20001]={};

    for(int i=0;i<n;i++){

      if(checked[i])continue;
      checked[i]=true;

      m[mp(x1[i],y1[i])]=1;
      m[mp(x2[i],y2[i])]=0;

      queue<int> q;
      q.push(i);
      while(!q.empty()){
	int u=q.front();
	q.pop();

	for(int k=0;k<4;k++){
	  pair<int,int> npii(x1[u]+X[k],y1[u]+Y[k]);
	  if(index.find(npii)==index.end())continue;
	  int next=index[npii];
	  if(next==u)continue;
	  if(m.find(npii)==m.end()){
	    m[npii]=m[mp(x1[u],y1[u])];
	    if(m.find(mp(x1[next],y1[next]))==m.end())
	      m[mp(x1[next],y1[next])]=(m[mp(x1[u],y1[u])]+1)%2;
	    else  m[mp(x2[next],y2[next])]=(m[mp(x1[u],y1[u])]+1)%2;
	    q.push(next);
	  }
	  else {
	    if(m[npii]!=m[mp(x1[u],y1[u])])ans="No";
	  }
	}
	for(int k=0;k<4;k++){
	  pair<int,int> npii(x2[u]+X[k],y2[u]+Y[k]);
	  if(index.find(npii)==index.end())continue;
	  int next=index[npii];
	  if(next==u)continue;
	  if(m.find(npii)==m.end()){
	    m[npii]=m[mp(x2[u],y2[u])];
	    if(m.find(mp(x1[next],y1[next]))==m.end())
	      m[mp(x1[next],y1[next])]=(m[mp(x2[u],y2[u])]+1)%2;
	    else  m[mp(x2[next],y2[next])]=(m[mp(x2[u],y2[u])]+1)%2;
	    q.push(next);
	  }
	  else {
	    if(m[npii]!=m[mp(x2[u],y2[u])])ans="No";
	  }
	}
	checked[u]=true;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 6580
N,D = map(int,input().split())

Xs = []

targets = []
count = 0
for i in range(0, 3000):
    targets.append(i**2)

for i in range(0,N):
    Xs.append(list(map(int,input().split())))

for i in range(0,N):
    for h in range(i,N):
        if i == h:
            continue

        dist = 0
        for index in range(len(Xs[0])):
            dist += (Xs[i][index] - Xs[h][index])**2

        if dist in targets:
            count += 1


print(count)


Measured memory_bytes: 3064
from collections import deque
def main():
    o=deque()
    e=deque()
    n=int(input())
    s=input().split()
    
    for i in range(0,len(s)):
        j=int(s[i])
        if i%2==0:
            o.append(j)
        else:
            e.append(j)
    if n%2==0:
        print(" ".join([str(k) for k in e][::-1])+" "+" ".join([str(m) for m in o]))
    else:
        print(" ".join([str(k) for k in o][::-1])+" "+" ".join([str(m) for m in e]))
if __name__=='__main__':
    main()


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

vector<vector<size_t>> edges;

pair<size_t, size_t> farthest_node_and_distance(size_t now, size_t prev){
    auto retn = now, retd = 0UL;
    for(auto i : edges[now]){
        if(i != prev){
            auto t = farthest_node_and_distance(i, now);
            if(retd < t.second + 1){
                retd = t.second + 1;
                retn = t.first;
            }
        }
    }
    return {retn, retd};
}

int main(){
    size_t N;
    cin >> N;
    edges = vector<vector<size_t>>(N);
    for(unsigned long i = 1, a, b; i < N; ++i){
        cin >> a >> b;
        --a;
        --b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    auto t = farthest_node_and_distance(0, 0).first;
    puts(farthest_node_and_distance(t, t).second % 3 == 1 ? "Second" : "First");
    return 0;
}

Measured memory_bytes: 23680
#include <stdio.h>
#include <string.h>
int main() {
  char S[2000000];
  char T[2000000];
  scanf("%s %s", &S, &T);
  int count = 0;
  for(int i = 0; i < strlen(S); i++){
    if(S[i] != T[i]){
      count++;
    }
  }
  printf("%d", count);
}

Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n;
	cin >> n;
	vector<int> l(n);
	forn(i, n) cin >> l[i];
	sort(all(l));
	int cnt = 0;
	for(int i = n-1; i >= 0; i--) {
		for(int j = i-1; j >= 0; j--) {
			auto ind = lower_bound(all(l), l[i]+l[j]);
			ll num = distance(ind, l.end());
			cnt += (n-1-i) - num;
		}
	}
	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
        using namespace std;
        typedef long long int ll; 
    // For debug
        void show_vector( vector<ll> A ){
            for(int i=0; i<A.size(); i++){
                cout<< A.at(i) << endl; 
            }
        }
        
        
        

        int main() {  
            ll P = 1000*1000*1000+7;
            

            
            string S;
            cin >> S;
            
            vector<ll> po2(S.size()+2);
            po2.at(0)=1; 
            for(int i=1; i<S.size()+2 ; i++ ){
                po2.at(i)= (2*po2.at(i-1))%P; 
            }
            
            vector<ll> po3(S.size()+2);
            po3.at(0)=1; 
            for(int i=1; i<S.size()+2 ; i++ ){
                po3.at(i)= (3*po3.at(i-1))%P; 
            }
            
            int counter = 0; 
            ll answer = 0; 
            
            
            for(int i=0; i<S.size(); i++){
                if(S.at(i)=='1'){
                    answer = answer + po2.at(counter) * po3.at(S.size()-i-1);
                    answer = (answer%P);
                    counter++; 
                }
            }
            
            answer = answer + po2.at(counter); 
            answer = answer%P;  

            cout<< answer ;   
        }


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
#include <cctype>
#include <deque>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=1e+5+10;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

LL N, M, P, q, r;
deque<pr> cards;

deque<pr> pickCards(int k){
	deque<pr> res;
	while(!cards.empty()){
		pr p = cards.front(); cards.pop_front();
		if(p.S - p.F + 1 == k){
			res.PB(pr(p.F, p.S));
			break;
		}
		else if(p.S - p.F + 1 > k){
			res.PB(pr(p.F, p.F + k - 1));
			cards.push_front(pr(p.F + k, p.S));
			break;
		}
		k -= p.S - p.F + 1;
		res.PB(pr(p.F, p.S));
	}
	return res;
}

int main() {
	while(cin >> N && N){
		cin >> M;
		cin >> P >> q >> r;
		cards.clear();
		cards.PB(pr(1, N));
		REP(i,M){
			int x, y;
			scanf("%d%d",&x, &y);
			deque<pr> top = pickCards(x);
			deque<pr> middle = pickCards(y - x);
			while(!middle.empty()){
				cards.PB(middle.front());
				middle.pop_front();
			}
			while(!top.empty()){
				cards.PB(top.front());
				top.pop_front();
			}
		}
		
		LL now = 0, ans = 0;
		pickCards(P - 1);
		deque<pr> res = pickCards(q - P + 1);
		while(!res.empty()){
			pr c = res.front();
			res.pop_front();
			if(c.S <= r){
				ans += c.S - c.F + 1;
			}
			else if(c.F <= r){
				ans += r - c.F + 1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1380
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final long INF = 1000000000000000001L;
	long count2(int[] xx, int n, int[] yy, int m, long a) {
		long cnt = 0;
		for (int i = 0, j = m - 1; i < n; i++) {
			long z = a / xx[i];
			while (j >= 0 && yy[j] > z)
				j--;
			cnt += j + 1;
		}
		return cnt;
	}
	long count1(int[] xx, int n, long a) {
		long cnt = 0;
		for (int i = 0, j = n - 1; i < j; i++) {
			long z = a / xx[i];
			while (i < j && xx[j] > z)
				j--;
			cnt += j - i;
		}
		return cnt;
	}
	void main() {
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] pp = new int[n];
		int[] qq = new int[n];
		int np = 0, nq = 0, no = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a > 0)
				pp[np++] = a;
			else if (a < 0)
				qq[nq++] = -a;
			else
				no++;
		}
		pp = Arrays.stream(pp, 0, np).boxed().sorted().mapToInt($->$).toArray();
		qq = Arrays.stream(qq, 0, nq).boxed().sorted().mapToInt($->$).toArray();
		long mq = (long) np * nq;
		long mo = (long) no * (no - 1) / 2 + (long) no * (np + nq);
		if (k > mq && k <= mq + mo) {
			println(0);
			return;
		}
		boolean positive;
		if (k <= mq) {
			positive = false;
			k = mq + 1 - k;
		} else {
			positive = true;
			k -= mq + mo;
		}
		long lower = 0, upper = INF;
		while (upper - lower > 1) {
			long a = (lower + upper) / 2;
			long cnt = positive ? count1(pp, np, a) + count1(qq, nq, a)
				: count2(pp, np, qq, nq, a);
			if (cnt >= k)
				upper = a;
			else
				lower = a;
		}
		println(positive ? upper : -upper);
	}
}


Measured memory_bytes: 62220
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    h,w = LI()
    a = [[0]*w for _ in range(h)]
    s = [S() for _ in range(h)]
    for i in range(h):
        si = s[i]
        for j in range(w):
            if si[j] != '#':
                continue
            if j < w-1:
                a[i][j+1] += 1
                if i < h-1:
                    a[i+1][j+1] += 1
                if i > 0:
                    a[i-1][j+1] += 1
            if j > 0:
                a[i][j-1] += 1
                if i < h-1:
                    a[i+1][j-1] += 1
                if i > 0:
                    a[i-1][j-1] += 1

            if i < h-1:
                a[i+1][j] += 1
            if i > 0:
                a[i-1][j] += 1

    for i in range(h):
        for j in range(w):
            if s[i][j] == '#':
                a[i][j] = '#'

    return '\n'.join([''.join(map(str, r)) for r in a])


print(main())




Measured memory_bytes: 7620
#include<iostream>
#include<string>
#include<vector>
#include<map>


using namespace std;
int main()
{  
    long long n,ans=0;
    cin>>n;
    map<string,long> m;
    for(long j=0;j<n;j++){
    	string a;
    	cin>>a;
    	m[a]+=1;
	}
	map<string, long>::iterator iter;
	for(iter=m.begin();iter !=m.end();iter++){
		ans +=1;
	}
	cout<<ans<<endl;
}
	
    

Measured memory_bytes: 19204
while 1:
	input_data = [i for i in input().split()]
	if input_data[1] == '?':
		break;
	a = int(input_data[0])
	op = input_data[1]
	b = int(input_data[2])
	if op == '+':
		print(a+b)
	elif op == '-':
		print(a-b)
	elif op == '*':
		print(a*b)
	elif op == '/':
		print(int(a/b))

Measured memory_bytes: 7736
#include<stdio.h>
int main()
{
    int N;
    scanf("%d",&N);

    int A[100];
    int i;
    int bl=1;

    for(i=0;i<N;i++){
        int x;
        scanf("%d",&x);
        if((x % 2==0) && (x %3 != 0) && (x %5 != 0)) bl=0;
    }
    if(bl) printf("APPROVED\n");
    else printf("DENIED\n");

}


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

struct UnionFind{
  int num;//連結成分の数
  vector<int> r,p;//そのグループのサイズ,自分の親っぽいやつ
  UnionFind(){}
  UnionFind(int n):num(n),r(n,1),p(n,0){iota(p.begin(),p.end(),0);}

  int find(int x){//どのグループに所属するか
    return (x==p[x]?x:p[x]=find(p[x]));//xがグループの名前と一致するまでxを親にする
  }

  bool same(int x,int y){//同じグループかどうか
    return find(x)==find(y);
  }

  void unite(int x,int y){//xとyを同じグループにする
    x=find(x);y=find(y);//xとyのグループの名前をどっちかが変える
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);//サイズが大きい方をxとする
    r[x]+=r[y];//yの親をxにする（今までyだったグループ名がxになる）
    p[y]=x;
    num--;
  }

  int size(int x){//グループの大きさ
    return r[find(x)];
  }

  int count() const{//グループの数
    return num;
  }
};
struct E{int u,v,w;};
bool cmp(E a,E b){return a.w<b.w;};
int ans;

int main(){
  int n,m;cin>>n>>m;
  UnionFind uf(n);
  vector<E> edge;
  while(m--){
    int s,t,w;cin>>s>>t>>w;
    edge.push_back({s,t,w});
  }
  sort(edge.begin(),edge.end(),cmp);
  for(E p:edge){
    if(uf.same(p.u,p.v))continue;
    ans+=p.w;
    uf.unite(p.u,p.v);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3],sum;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    sum=2*a[2]-a[0]-a[1];
    if(sum%2==0)cout<<sum/2;
    else cout<<sum/2+2;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    int th = 0;
    REP(i, N) {
        th += A[i];
    }
    if(th%(4*M) == 0) {
        th /= 4*M;
    } else {
        th = th / (4*M)+1;
    }
    
    int cnt = 0;
    REP(i, N) {
        if(A[i] >= th) cnt++;
    }
    if(cnt >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    map<string, i64> cnt;
    for (i64 i = 0; i < n; i++) {
        string s;
        cin >> s;
        cnt[s]++;
    }

    cout << cnt.size() << endl;
}

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


Measured memory_bytes: 19256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (int &x : a) {
        cin >> x;
        sum += x;
    }
    int mx = *(max_element(a.begin(), a.end()));
    cout << sum - mx / 2 << "\n";
}


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

int main(){
	int k,a,b;
	cin >> k >> a >> b;
	bool ok = 0;
	for(int i = a ; i <= b ; i++){
		if(i % k == 0)ok = 1;
	}
	if(ok)cout << "OK\n";
	else cout << "NG\n";
}

Measured memory_bytes: 3596
function Main(s) {
  s = s.split("\n");
  s[0] = s[0].split(" ");
  const n = +s[0][0];
  const x = +s[0][1];
  var sum = 0;
  var min = 1e9;
  for(var i = 0; i < n; i++){
    sum += +s[i+1];
    min = Math.min(min, +s[i+1])
  }
  console.log(n + Math.floor((x - sum) / min));
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll l = c / __gcd(c, d) * d;
  ll nc = b / c - (a - 1) / c;
  ll nd = b / d - (a - 1) / d;
  ll nl = b / l - (a - 1) / l;
  ll ans = b - a + 1 - nc - nd + nl;
  cout << ans << endl;
}

Measured memory_bytes: 256
def examA():
    R = I()
    ans = R*2*3.141592
    print(ans)
    return

def examB():
    N, M = LI()
    A = LI()
    S = sum(A)
    if N>=S:
        ans = N-S
    else:
        ans = -1
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    ans = [0]*N
    for i in range(N-2,-1,-1):
        ans[A[i]-1] +=1
    for v in ans:
        print(v)
    return

def examD():
    N, K = LI()
    S = [0]*(N+2)
    for i in range(1,N+1):
        S[i+1] = S[i] + i
    #print(S)
    ans = 0
    for i in range(K,N+2):
        cur = (S[N+1] - S[N-i+1]) - (S[i] - S[0]) +1
        ans += cur
        ans %= mod
        #print(cur)

    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 20080
S = input()
N = len(S)
dp = [[0]*2 for i in range(N+10)]

dp[0][0] = 1
dp[1][1] = 1
for i in range(N-1):
    # dp[i][0]の更新
    if S[i+1] != S[i]:
        dp[i+1][0] = dp[i][0] + 1
    dp[i+1][0] = max(dp[i+1][0], dp[i][1] + 1)
    # dp[i][1]の更新
    dp[i+2][1] = dp[i][0] + 1
print(max(dp[N-1]))    


Measured memory_bytes: 36384
// Problem : A - ∴ (Therefore)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		n = n%10;
		if(n==2||n==4||n==5||n==7||n==9)
		{
			cout<<"hon";
		}
		else if(n==3)
		{
			cout<<"bon";
		}
		else
		{
			cout<<"pon";
		}    	
    }
    return 0;
}


Measured memory_bytes: 3660
N, K = map(int, input().split())
p = list(map(int, input().split()))

best_score = 0
for i in range(K):
    best_score += p[i]+1

curr = best_score
for i in range(N-K):
    curr += p[i+K] + 1
    curr -= p[i] + 1
    if curr > best_score:
        best_score = curr

print(best_score/2)

Measured memory_bytes: 25060
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int determinant(int n) {
	int i = 0;
	while (1) {
		i++;
		if (i * 400 > n) {
			return i - 1;
			break;
		}
		else if (i * 400 >= 3200) {
			return 10;
			break;
		}
	}
}
int main() {
	int n;
	cin >> n;
	vector<int>color(8);
	int all = 0;
	rep(i, n) {
		int co;
		cin >> co;
		int j = determinant(co);
		if (j == 10) {
			all++;
		}
		else {
			color[j]++;
		}
	}
	int count = 0;
	rep(i, 8) {
		if (color[i] > 0) {
			count++;
		}
	}
	int Min = count;
	if (count == 0 && all > 0) {
		Min++;
	}
	int Max =  count + all;
	cout << Min << " " << Max << endl;
}

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

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

  ll all = 0;
  ll ans[N];
  for (int i = 0; i < N; i++)
  {
    all += A[i];
  }

  ans[0] = all;
  for (int i = 1; i < N; i += 2)
  {
    ans[0] -= 2 * A[i];
  }
  for (int i = 1; i < N; i++)
  {
    ans[i] = 2 * A[i - 1] - ans[i - 1];
  }

  for (int i = 0; i < N; i++)
  {
    cout << ans[i];
    if (i == N - 1)
      cout << endl;
    else
      cout << ' ';
  }
}

Measured memory_bytes: 2816
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll N;
ll A=0,B=0;
int main() {
	cin>>N;
	A=N;
	while(A!=0){
		B+=A%10;
		if(A<10)break;
		A=A/10;
	}
	if(N%B==0)cout<<"Yes"<<endl;
	if(N%B!=0)cout<<"No"<<endl;
	return 0;
}


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

using namespace std;

int main() {
	string a;
	int b = 0;
	cin >> a;

	for (int i = 0; i < 4; i++) {
		if (a[i] == '+') {
			++b;
		}
		else {
			--b;
		}
	}

	cout << b << endl;
}

Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))

num = [b[0]]

for i in range(1, n - 1):
  if(b[i] <  b[i - 1]):
    num[-1] = b[i]
    num.append(b[i])
  else:
    num.append(b[i])

num.append(b[0])

print(sum(num))


Measured memory_bytes: 3060
import math
def ini(): return int(input())
def inli(): return list(map(int, input().split()))
def inf(): return float(input())
def inlf(): return list(map(float, input().split()))
def inl(): return list(input())
def pli(): return "".join(list(map(str, ans)))

a = inli()
n=a[0]
m=a[1]
if n-m ==1 or m-n==1:
    if n < m:
        tmp =math.factorial(n)
        print((tmp * tmp * m)%1000000007)
    else:
       tmp = math.factorial(m)
       print((tmp * tmp *n)%1000000007)
elif n==m :
    tmp =math.factorial(m)
    print((tmp * tmp *2)%1000000007)

else :
    print(0)

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int best = INT_MAX;
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for(int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    for(int i = 0; i < n - k + 1; i++)
    {
        if(x[i + k - 1] <= 0)
        {
            best = min(best, abs(x[i]));
        }
        else if(x[i] >= 0)
        {
            best = min(best, abs(x[i + k - 1]));
        }
        else
        {
            best = min(best, min(abs(x[i]) + abs(x[i] - x[i + k - 1]), x[i + k - 1] + abs(x[i + k - 1] - x[i])));
        }
    }
    cout << best;

    return 0;
}


Measured memory_bytes: 640