akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

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

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;


int main()
{
	FAST;

	int y, m, d;
	char c1, c2;
	cin >> y >> c1 >> m >> c2 >> d;
	if (y<=2019) {
		if (m <= 4) {
			if (m <=30) {
				cout << "Heisei\n";
				return 0;
			}
		}
	}
	cout << "TBD\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int main()
{
    std::ios::sync_with_stdio(false);
    int a,b,c;
    while(cin>>a>>b>>c)
    {
        map<ll,ll> mp;
        int flag=0;
        for(int i=1;;++i)
        {
            if(mp[i*a%b])
            {
                flag=0;
                break;
            }
            mp[i*a%b]=1;
            if(i*a%b==c%b)
            {
                flag=1;
                break;
            }
        }
        if(flag)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main(){
    fast();

/* you get what you work for not what you wish for */
    string s;
    cin >> s;
    inp(k);
    string ss = s;
    string r = s+s;
    ll cnt1=0, cnt2=0;
    for(int i=1; i<s.size(); i++){
        if(s[i]==s[i-1]){
            cnt1++;
            s[i]='*';
        }
    }
    for(int i=1; i<r.size(); i++){
        if(r[i]==r[i-1]){
            cnt2++;
            r[i]='*';
        }
    }
    ll x = cnt2-2*cnt1;
    char y = s[0];
    bool check = 1;
    for(auto i:ss){
        if(i!=y){
            check = 0;
        }
    }
    if(check){
        cout << k*s.size()/2 << endl;
        return 0;
    }
    if(x==0){
        cout << k*cnt1 << endl;
    }
    else{
        cout << k*cnt1 + (k-1)*x << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
vector<int> f(int x,int n){
  vector<int> r(n);
  for(int i=0;i<n;i++){
    r[i]=x%3;
    x=x/3;
  }
  return r;
}

int main(){
  int N;
  scanf("%d",&N);
  vector<vector<long long>> L(N,vector<long long>(3));
  for(int i=0;i<N;i++){
    scanf("%lld%lld%lld",&L[i][0],&L[i][1],&L[i][2]);
  }
  long long INF=10000000000000000;
  vector<int> D(21);
  vector<int> T(21);
  D[0]=1;
  T[0]=1;
  for(int i=0;i<20;i++){
    D[i+1]=D[i]*2;
    T[i+1]=T[i]*3;
  }
  vector<vector<long long>> X(D[N],vector<long long>(N,INF));
  vector<vector<long long>> Y(D[N],vector<long long>(N,INF));
  for(int i=0;i<D[N];i++){
    for(int j=0;j<N;j++){
      X[i][j]=min(abs(L[j][0]),abs(L[j][1]));
      Y[i][j]=X[i][j];
      for(int k=0;k<N;k++){
        if(i&D[k]){
          X[i][j]=min(X[i][j],abs(L[j][0]-L[k][0]));
          Y[i][j]=min(Y[i][j],abs(L[j][1]-L[k][1]));
        }
      }
      X[i][j]*=L[j][2];
      Y[i][j]*=L[j][2];
    }
  }
  vector<int> s;
  int t;
  long long u;
  vector<long long> P(N+1,INF);
  int x,y;
  for(int i=0;i<T[N];i++){
    s=f(i,N);
    x=0;
    y=0;
    for(int j=0;j<N;j++){
      if(s[j]==1){
        x+=D[j];
      }else if(s[j]==2){
        y+=D[j];
      }
    }
    t=N-count(s.begin(),s.end(),0);
    u=0;
    for(int j=0;j<N;j++){
      u+=min(X[x][j],Y[y][j]);
    }
    P[t]=min(P[t],u);
  }
  for(int i=0;i<=N;i++){
    printf("%lld\n",P[i]);
  }
}

Measured memory_bytes: 13032
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int a;
	cin>>a;
	if(a%10==7 || a%100/10==7 || a/100==7){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int a(int,int);
int S[100000];

int main()
{

  int count, n, q, i;

  count = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  int T[q];
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    if(a(n,T[i]) != -1){
      count++;
    }
  }

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

  return 0;

}


int a(int n,int key)
{

  int left, right, mid;

  left = 0;
  right = n;
  while(left < right){
    mid = (left + right)/2;
    if(key == S[mid]){
      return mid;
    }
    if(key > S[mid]){
      left = mid + 1;
    }
    else if(key < S[mid]){
      right = mid;
    }
  }
  return -1;
}



Measured memory_bytes: 2348
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
using namespace std;


int main(void)
{
	int N, W; cin >> N >> W;
	vector<int> w(N), v(N);
	int v_max = 0;
	rep(i, 0, N) {
		cin >> w[i] >> v[i];
		v_max += v[i];
	}

	vector<vector<lli>> dp(N + 1, vector<lli>(v_max + 1, MOD));
	dp[0][0] = 0;
	rep(i, 1, N + 1) {
		rep(sum_v, 0, v_max + 1) {
			dp[i][sum_v] = dp[i - 1][sum_v];
			if (sum_v >= v[i - 1])dp[i][sum_v] = less(dp[i - 1][sum_v], dp[i - 1][sum_v - v[i - 1]] + w[i - 1]);
		}
	}

	lli ans = 0;
	rep(sum_v, 1, v_max + 1) {
		if (dp[N][sum_v] <= W)ans = sum_v;
		//else break;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 80256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(12); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> B(N - 1);
    rep(i, N - 1) cin >> B[i];

    vector<int> A(N);
    A[0] = B[0];
    rep(i, 1, N - 1) {
        A[i] = min(B[i - 1], B[i]);
    }
    A[N - 1] = B[N - 2];

    int ans = accumulate(all(A), 0);
    write(ans);
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,maxp=0,p[10],ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&p[i]);
        ans+=p[i];
        maxp=max(maxp,p[i]);
    }
    printf("%d\n",ans-maxp/2);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
typedef struct {
    double x, y;
} coor;
 
void input_coor(coor *rec)
{
    scanf("%lf %lf", &rec->x, &rec->y);
}
 
int main(void)
{
    coor a, b, c, d;
    int n;
    int i;
 
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        input_coor(&a);
        input_coor(&b);
        input_coor(&c);
        input_coor(&d);
        if ((a.x - b.x) * (c.y - d.y) - (a.y - b.y) * (c.x - d.x) == 0) puts("YES");
        else puts("NO");
    }
 
    return (0);
}

Measured memory_bytes: 620
local par={}
local rank={}

local function init(n)
    for i=1,n do
        par[i]=i
        rank[i]=1
    end
end

local function root(x)
    return par[x]==x and x or root(par[x])
end

local function same(x,y)
    return root(x)==root(y)
end

local function unite(x,y)
    x=root(x)
    y=root(y)
    if x==y then
        return
    end
    if rank[x]>rank[y] then
        x,y=y,x
    end
    par[x]=y
    rank[y]=rank[y]+rank[x]
end

local function size(x)
    return rank[root(x)]
end

local n,m,k=io.read("n","n","n")

init(n)

local graph={}
for i=1,n do
    graph[i]={}
end
for i=1,m do
    local a,b=io.read("n","n")
    table.insert(graph[a],b)
    table.insert(graph[b],a)
    unite(a,b)
end
for i=1,k do
    local c,d=io.read("n","n")
    if same(c,d) then
        table.insert(graph[c],d)
        table.insert(graph[d],c)
    end
end

for i=1,n do
    local kouho=size(i)-#graph[i]-1
    io.write(kouho.." ")
end
print()

Measured memory_bytes: 26356
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n =sc.nextInt();
				int q=sc.nextInt();
				if(n+q==0) break;
				int [] data=new int[101];
				int max=q;
				for(int i=0; i<n; i++) {
					int m=sc.nextInt();
					for(int j=0; j<m; j++) {
						int k=sc.nextInt();
						data[k]++;
						max=Math.max(max, data[k]);
					}
				}
				int ans=0;
				for(int i=1; i<100; i++) {
					if(data[i]>=max) {
						ans=i;
						break;
					}
				}
				System.out.println(ans);
				
			}

		}
	}
}


Measured memory_bytes: 68576
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
typedef pair<int, int> P;

int main(){
    string s;
    rep(i, 2) cin >> s;
    cout << "A" << s[0] << "C" << endl;
}


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

using namespace std;

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

	int x;
	cin >> x;

	if (x >= 400 && x <= 599) {
		cout << "8" << endl;
	}

	else if (x >= 600 && x <= 799) {
		cout << "7" << endl;
	}

	else if (x >= 800 && x <= 999) {
		cout << "6" << endl;
	}

	else if (x >= 1000 && x <= 1199) {
		cout << "5" << endl;
	}

	else if (x >= 1200 && x <= 1399) {
		cout << "4" << endl;
	}

	else if (x >= 1400 && x <= 1599) {
		cout << "3" << endl;
	}

	else if (x >= 1600 && x <= 1799) {
	       cout << "2" << endl;
	}

	else if (x >= 1800 && x <= 1999) {
		cout << "1" << endl;
	}

	return 0;
}


Measured memory_bytes: 3632
H, W = map(int, input().split())
a = [[int(x) for x in input().split()] for _ in range(H)]


def check(i, j):
    for dx, dy in [(0, 1), (1, 0)]:
        x, y = j + dx, i + dy
        if 0 <= x < W and 0 <= y < H:
            if a[y][x] % 2 == 1:
                return y, x
    if i + 1 < H:
        return i + 1, j
    elif j + 1 < W:
        return i, j + 1
    else:
        return -1, -1


ans = []
for i in range(H):
    for j in range(W):
        if a[i][j] % 2 == 0:
            continue
        y, x = check(i, j)
        if x != -1:
            a[y][x] += 1
            a[i][j] -= 1
            ans.append((i + 1, j + 1, y + 1, x + 1))

print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 26100
l = list(map(int, input().split()))
ma = max(l)
c = 0

for i in l:
    c += int((ma - i)/2)
    l[l.index(i)] += int((ma - i)/2) * 2

if l.count(ma-1) == 2:
    c += 1
elif l.count(ma-1) == 1:
    c += 2

print(c)

Measured memory_bytes: 3060
#include <stdio.h>

int max(int a, int b){
	if(a > b){
		return a;
	}
	else{
		return b;
	}
}

int main(){
	int W, a, b;
	scanf("%d%d%d", &W, &a, &b);
	if(a < b){
		printf("%d\n", max(b - a - W, 0));
	}
	else{
		printf("%d\n", max(a - b - W, 0));
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

ll merge_count(vector<int> &a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<int> b(a.begin(), a.begin()+n/2);
    vector<int> c(a.begin()+n/2, a.end());

    cnt += merge_count(b);
    cnt += merge_count(c);

    int ai = 0, bi = 0, ci = 0;

    while (ai < n) {
        if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);

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

    cout << merge_count(a) << endl;

    return 0;
}



Measured memory_bytes: 5380
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
    public static void process()throws IOException
    {
        int n=ni();
        int m=ni();
        pn((n*(n-1)/2)+(m*(m-1)/2));
    }

    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        boolean oj =true;
        if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
        else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
        int t=1;
        // t=ni();
        while(t-->0) {process();}
        out.flush();out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}

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

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
int main(){
   int N,X;
   cin>>N>>X;

   vector<int> L={0};
   for(int i=0;i<N;i++){
      int l;
      cin>>l;
      L.push_back(l);
   }

   for(int i=1;i<N+1;i++){
      L.at(i)+=L.at(i-1);
   }
   
   int count=0;
   for(int i=0;i<N+1;i++){
      if(L.at(i)<=X)
         count++;
      else
         break;
   }
   cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//方針
//x * y の最大値を小さくする
//x : A[i]
//y : F[i]
ll N,K;

vector <int> A;
vector <int> F;

//t: 完食の最小値
bool kaesu(ll t)
{
  //K
  ll tmp = 0;

  //4 * 2 <= 3
  //4 - 3/2 == 3 -> A[i]を3減らす必要がある
  //A[i] * F[i] <= tをすべてにおいて満たす必要がある。
  //A[i] <= t/ F[i]を満たす必要がある
  //A[i]のほうが大きい場合は、A[i] - t/F[i]
  for(ll i = 0; i < N; ++i)
  {
    tmp += max(0ll,A[i] - t/F[i]);
  }

  bool res;
  if(tmp <= K)
  {
    res = true;
  }
  else
  {
    res = false;
  }

  return res;
}

int main(){
  cin >> N >> K;
  A.resize(N);
  F.resize(N);

  REP(i,N)
  {
    cin >> A[i];
  }
  REP(i,N)
  {
    cin >> F[i];
  }
  //Aを昇順
  sort(A.begin(),A.end());
  //Fを降順
  sort(F.begin(),F.end(), greater<ll>());

  //K減らした後の列をA'とする

  ll l = -1, r = 1e12;
  while(l + 1 < r)
  {
    ll mid = (l + r) / 2;

    //関数化
    if(kaesu(mid) == true)
    {
      //さらに小さい値を探しにいく
      r = mid;
    }
    else
    {
      l = mid;
    }
  }

  cout << r << endl;

  return 0;    
}



Measured memory_bytes: 1792
let (l, r, d) = readInts().mapToTuple()
print((l...r).filter { $0.isMultiple(of: d) }.count)


// MARK: -----------------------------------------------------------------------


func readInt() -> Int {
    Int(readLine()!)!
}

func readInts() -> [Int] {
    readLine()!.split(separator: " ").map { Int($0)! }
}

extension Collection {
    func mapToTuple() -> (Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!, i.next()!)
    }
    
    func safe(at index: Index) -> Element? {
        self.indices.contains(index) ? self[index] : nil
    }
}

struct DP<Argument: Hashable, Element> {
    var dictionary = [Argument: Element]()
    
    var expression: (Argument, (Argument) -> Element) -> Element
    
    init(expression: @escaping (_ argument: Argument, _ note: (Argument) -> Element) -> Element) {
        self.expression = expression
    }
    
    subscript(_ argument: Argument) -> Element {
        mutating _read {
            if let note = dictionary[argument] {
                yield note
            } else {
                let result = expression(argument) { self[$0] }
                dictionary[argument] = result
                yield result
            }
        }
    }
}


Measured memory_bytes: 8088
#include <iostream>
using namespace std;
static const int MAX = 100;

void bubbleSort(int A[], int n)
{
	int cnt = 0;
	bool flag = true;
	
	for (int i = 0; flag == true; i++){
		flag = false;
		for (int j = n-1; j > i; j--){
			if (A[j] < A[j-1]){
				int temp;
				temp = A[j-1];
				A[j-1] = A[j];
				A[j] = temp;
				flag = true;
				cnt++;
			}
		}
	}
	for (int i = 0; i < n; i++){
		if (i > 0)
			cout << " ";
		cout << A[i];
	}
	cout << endl << cnt << endl;
}

int main()
{
	int A[MAX];
	int n;
	
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> A[i];
	}
	bubbleSort(A, n);
	
	return 0;
}


Measured memory_bytes: 3092
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
P = getList()

cnt = 0
for i in range(N - 1):
    now = P[i]
    next = P[i + 1]
    if i + 1 == now:
        P[i] = next
        P[i + 1] = now
        cnt += 1
if P[-1] == N:
    print(cnt + 1)
else:
    print(cnt)


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;

int MOD = 1e9+7;

//ll po(ll b, ll p){ return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD;}
// ll pomd(ll a, ll k, ll md) { ll p; if (k == 0){ return 1; } p = pomd(a, k / 2, md); p = p * p % md; if (k % 2){ p = p * a % md; } return p; }
// counting divsrs: vi arr(N); for(int i{1}; i<N; ++i) for(int j=i; j<N; j+=i) d[j]++;

#define mp make_pair
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)

void setIO(string name = ""){
    freopen((name+".in").c_str(), "r", stdin); 
    freopen((name+".out").c_str(), "w", stdout);
}	

int main(){
 	ios_base::sync_with_stdio(0); cin.tie(0); 
	// setIO();
	int n;
 	cin >> n;
  	int k = 1;
  	while (k * n % 360 != 0) k++;
  	cout << k << "\n";


}





Measured memory_bytes: 3648
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    unsigned int N,L;

    cin >> N >>L;

    vector<string> s(N);
    rep(i,N){
        cin >> s[i];
    }
    sort(s.begin(),s.end());

    for(string x:s){
        cout << x;
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;

int main(){    
    int l ;
    cin >> l ;
    double length = l/3.0 ;
    long double ans = length*length*length ;
    cout << fixed << setprecision(15) << ans << endl ;
    
}

Measured memory_bytes: 256
def koyaku(A, B):
    ans = []
    for i in range(1,A+1):
        if A%i == 0 and B%i == 0:
            ans.append(i)    
    return ans
if __name__ == "__main__":
    A, B, K = map(int, input().split())
    if B > A:
        tmp = A
        A = B
        B = tmp
    ans = koyaku(A, B)
    print(ans[-K])

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

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		NScanner sc = new NScanner(System.in);
		int[] a = new int[6];
		for(int i = 0; i < 6; ++i)
			a[i] = sc.nextInt();
		Dice d1 = new Dice(a);
		int[] b = new int[6];
		for(int i = 0; i < 6; ++i)
			b[i] = sc.nextInt();
		Dice d2 = new Dice(b);
		boolean match = false;
		if(d1.equals(d2)){
			match = true;
		}
		ent: for(int i = 0; i < 4; ++i){
			d2.turnE();
			if(d1.equals(d2)){
				match = true; break ent;
			}
			for(int j = 0; j < 4; ++j){
				d2.turnN();
				if(d1.equals(d2)){
					match = true; break ent;
				}
				for(int k = 0; k < 4; ++k){
					d2.turnE();
					if(d1.equals(d2)){
						match = true; break ent;
					}
				}
				
			}
		}
		System.out.println(match ? "Yes" : "No");
	}

}

class Dice{
	int Top, Front, Right, Left, Back, Bottom;

	Dice(int[] a){
		Top = a[0];
		Front = a[1];
		Right = a[2];
		Left = a[3];
		Back = a[4];
		Bottom = a[5];
	}

	void turnN(){
		int tmp = Top;
		Top = Front;
		Front = Bottom;
		Bottom = Back;
		Back = tmp;
	}

	void turnS(){
		int tmp = Top;
		Top = Back;
		Back = Bottom;
		Bottom = Front;
		Front = tmp;
	}

	void turnE(){
		int tmp = Top;
		Top = Left;
		Left = Bottom;
		Bottom = Right;
		Right = tmp;
	}

	void turnW(){
		int tmp = Top;
		Top = Right;
		Right = Bottom;
		Bottom = Left;
		Left = tmp;
	}
	boolean equals(Dice D){
		if(Top != D.Top) return false;
		if(Front != D.Front) return false;
		if(Right != D.Right) return false;
		if(Left != D.Left) return false;
		if(Back != D.Back) return false;
		if(Bottom != D.Bottom) return false;
		return true;
    }
}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	public boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


Measured memory_bytes: 24480
N = int(input())
S = input()

pares = S[:]

counter = 0
pares_num = []
for s in pares:
    if s == '(':
        counter += 1
        pares_num.append(counter)
    else:
        counter -= 1
        pares_num.append(counter)
        
min_num = min(pares_num)
if min_num < 0:
    pares = '(' * (-1*min_num) + pares
    

counter = 0
pares_num = []
for s in pares:
    if s == '(':
        counter += 1
        pares_num.append(counter)
    else:
        counter -= 1
        pares_num.append(counter)
#print(pares)
#print(pares_num)

pares += ')' * pares_num[-1]


print(pares)

Measured memory_bytes: 3064
class DisjointSet

  def initialize n
    @ps = n.times.map.to_a
  end

  def union x, y
    x = find x
    y = find y
    @ps[y] = x
  end

  def find x
    if x == @ps[x]
      x
    else
      @ps[x] = find @ps[x]
    end
  end

end

n, m = gets.split.map &:to_i
ds = DisjointSet.new n
es = m.times.map { gets.split.map(&:to_i) }.sort_by!(&:last).reverse!
c, r = n, 0
until c == 1
  s, t, w = es.pop
  s, t = ds.find(s), ds.find(t)
  next if s == t
  ds.union s, t
  c -= 1
  r += w
end
p r

Measured memory_bytes: 18536
#include <iostream>

 

 

 

using namespace std;

 

 

 

int main()
{
    int i, ans, a, b, c,d;
    
    cin >> a >> b >> c;
    ans = 0;
    d=0;
    for(i=a; i<=b; i++)
    {
        if(ans== c % i )
        d++;
    }
    cout << d << endl;
}


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

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

    vector <bool> s(n,false), g(n,false);


    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        if(a==1){
            s[b-1]=true;
        }
        if(b==n){
            g[a-1]=true;
        }
    }

    bool ok=false;

    for(int i=0; i<n; i++){
        if(s[i]){
            if(g[i]){
                ok=true;
                break;
            }
        }
        if(ok) break;
    }



    if(ok) cout << "POSSIBLE" <<endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define INFTY 2000000000
 
void merge(int *,int,int,int);
void mergeSort(int *,int,int);
  
int S[100000000];
int L[1000000],R[1000000];
long long int cnv=0; 
  
void merge(int *A,int left,int mid,int right){
  int i,j,k;
  int n1,n2;
 
  n1=mid-left;
  n2=right-mid;
 
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
 
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
 
  L[n1]=INFTY;
  R[n2]=INFTY;
 
  i=0;
  j=0;
 
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }else{
      A[k]=R[j];
      j=j+1;
      cnv+=n1-i;
    }
  }
}
 
void mergeSort(int *A,int left, int right){
  int mid;
  int v1,v2,v3;
 
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
  int i;
  int n;
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
 
  mergeSort(S,0,n);
 
  printf("%lld\n",cnv);
  return 0;
}

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

int main() {
  int N;
  string s, t;
  cin >> N >> s >> t;
  for (int i = 0; i < N; i++) {
    if (s.substr(i, N-i) == t.substr(0, N-i)) {
      cout << N + i << endl;
      return 0;
    }
  }
  cout << 2 * N << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
left, right = [None]*m, [None]*m

for i in range(m):
    a, b = map(int, input().split())
    left[i] = a
    right[i] = b

ans = min(right)-max(left)+1
if ans < 0:
    print(0)
else:
    print(ans)


Measured memory_bytes: 10868
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  ll a,b; cin>>a>>b;
  if(a*b>0){
    if(a>0&&b>0) cout<< "Positive" << endl;
    else{
      if((b-a)%2) cout<< "Positive" << endl;
      else cout << "Negative" << endl;
    }
  }else{
    cout << "Zero" <<endl;
  }

  return 0;
}


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


# Start template
# This template is from https://atcoder.jp/contests/abc156/submissions/10279810.
# Thank you Mr./Ms.convexineq.

SIZE = 4 * 10 ** 5 + 1;
MOD = 10 ** 9 + 7  # 998244353 #ここを変更する
SIZE += 1

inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
fac = [0] * SIZE  # fac[j] = j! mod MOD
finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD

inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1

for i in range(2, SIZE):
    inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
    fac[i] = fac[i - 1] * i % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def choose(n, r):  # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n] * finv[r] % MOD) * finv[n - r] % MOD
    else:
        return 0
def chofuku(ball, box):  # nHk mod MOD の計算
    return choose(box + ball - 1, box)

# End template



ans = 0
MAX = min(k,n- 1)
for i in range(0,MAX + 1):
    # print(choose(n,i) * chofuku(n-i,n))
    ans += choose(n,i) * chofuku(n - i ,i)
    ans %= MOD
    # print(ans)
print(ans % MOD)

Measured memory_bytes: 50548
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int mod=1000000007;

int main() {
  long double N;
  cin>>N;
  for(long double h=1;h<=3500;h++){
    for(long double n=1;n<=3500;n++){
      if(4*h*n-N*n-N*h==0){continue;}
       long double w=N*h*n/(4*h*n-N*n-N*h);
        if(w>0&&floor(w)==w){cout<<h<<" "<<n<<" "<<(int64_t)w<<endl;return 0;}
      }
    }
  return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, p, res, mx;

int main() {
	cin >> N;
	for (int i = 0; i != N; ++i) {
		cin >> p;
		res += p;
		mx = max(mx, p);
	}
	cout << res - mx / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;
const int INF = 1e9;
#define rep(i,n)for(int i=0;i<n;++i)
#define p pair<int,int>
int main() {
	int N;
	cin >> N;
	int T[1010], A[1010];
	for (int i = 0; i < N; ++i) {
		cin >> T[i] >> A[i];
	}
	ll b = T[0];ll c = A[0];
	for (int i = 0; i < N; ++i) {
		ll ratio = max((b + T[i] - 1) / T[i], (c + A[i] - 1) / A[i]);
		b = ratio * T[i];
		c = ratio * A[i];
	}
	cout << b + c << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
L = []
for _ in range(N):
    L.append(list(map(int, input().split())))
L = sorted(L, key=lambda x: x[0])

cnt = 0
for l in L:
    cnt += l[1]
    if cnt >= K:
        print(l[0])
        break

Measured memory_bytes: 29912
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};

struct nod{
	int x, y;
	nod(int x_,int y_): x(x_), y(y_){};
};

bool operator<(nod & a, nod & b){
  return a.y < b.y;
}

char tab[207][207];

vector<string> printVertically(string s) {
	for(int i = 0; i < 207; i++){
		for(int j = 0; j < 207; j++)
			tab[i][j] = ' ';
	}
	s += "$";
	vector<string> v;
	int r = 1,c = 1;
	for(int i = 0; i < (int)s.size(); i++){
		
		c = 1;
		while( s[i] != ' ' && s[i] != '$'){
			
			tab[r][c] = s[i];
			i++;
			c++;
			
		}
		r++;
	
	}
	
	for(int i = 1; i < 207; i++){
		string str = "";
		bool flag = false;
		for(int j = 206; j >= 1; j--){
			if(tab[j][i] != ' ')
				flag = true;
			if(flag){
				str+= tab[j][i];
			}
		}
		if(str.size() > 0){
			reverse(str.begin(),str.end());
			v.push_back(str);
		}
		
	}
	
	for(string x: v)
		cout<<x<<"-"<<endl;
	return v;
}
    
int main(){
	
	int n, m; cin>> n >> m;
	if(n == m){
		cout<<"Yes";
	}
	else
		cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define ll long long
#define ull  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 201000;
int f[1 << 26];
int a[N], dp[N];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    set < pair < int, int > > ss;
    int n = s.length();
    for (int i = 1; i <= n; i++){
        int k = s[i - 1] - 'a';
        a[i] = ((a[i - 1]) ^(1 << k));
        for (int j = 0; j < 26; j++){
            f[(a[i] ^ (1 << j))] = 1e9;
        }
    }
    dp[0] = 1;
    f[0] = 0;
    for (int i = 1; i <= n; i++){
        int x = f[a[i]];
        for (int j = 0; j < 26; j++){
            x = min(f[(a[i] ^ (1 << j))], x);
        }
        x++;
        f[a[i]] = min(f[a[i]], x);
        dp[i] = x;
    }
    cout << dp[n];
}


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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=n; i++)
#define rep0(i,n) for (int i=0; i<n; i++)
#define chmin(a,b) if ((a)>(b)) { a=(b); }
#define chmax(a,b) if ((a)<(b)) { a=(b); }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) do{printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);}while(0)
#else
#define debug(...) do{}while(0)
#endif

#define MOD 1000000007

int main() {
    std::ios::sync_with_stdio(false); std::cin.tie(nullptr); // disable when using stdio
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    for(ll i=k; i<=n+1; i++) {
        ll max = n*(n+1)/2 % MOD - (n-i)*(n-i+1) / 2 % MOD + MOD;
        ll min = (i)*(i-1)/2 % MOD;
        debug(max, min);
        ans += max - min + 1;
        ans %= MOD;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3520
#include<bits//stdc++.h>
using namespace std;
const int N = 200000 + 5;
typedef long long ll;
#define rep(i,n) for(ll i = 1; i <= n;i++)
int main() {
    ll a[N],n, x, y;cin >> n >> x >> y;
    rep(i,n) {
        for (ll j = i + 1; j <= n; j++) {
            ll z = min(j - i, abs(i - x) + 1 + abs(y - j));
            a[z]++;
        }
    }
    rep(i,n - 1) cout << a[i] << endl;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

long long ngcd(vector<long long> a) {
  long long res = a[0];
  for(int i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
long long nlcm(vector<long long> a){
  long long res = a[0];
  for(int i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(long long n) {
  if(n < 2) return false;
  for (long long i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
int digsum(int n) {
  int res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
int digcnt(int n){
  int res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<int> divisor(int n) {
  vector<int> res;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w,a,b; cin>>h>>w>>a>>b;
  vector<vector<char>> ans(h,vector<char>(w,'0'));
  rep(i,h){
    if(i<b){
      rep(j,a) ans[i][j]='1';
    }else{
      irep(j,a,w) ans[i][j]='1';
    }
  }
  rep(i,h){
    rep(j,w) cout<<ans[i][j];
    cout<<endl;
  }
}

Measured memory_bytes: 2304
<?php
// $tmp = [];
while($line = fgets(STDIN)){
   $tmp[] = explode(" ",trim($line));
}
// var_dump($tmp);
foreach($tmp as $v){
    if($v[0] == "0" && $v[1] == "0"){
        break;
    }
    echo str_repeat("#", $v[1]),PHP_EOL;
    for($i=2; $i<$v[0]; $i++){
        echo "#" . str_repeat(".", $v[1]-2) . "#",PHP_EOL;
    }
    echo str_repeat("#", $v[1]),PHP_EOL;
    echo PHP_EOL;
}


Measured memory_bytes: 9288
#include <iostream>

int main(void){
    int N, M, X, a=0, b=0, ans;
    std::cin >> N >> M >> X;
    for (int i=0; i<M; i++){
        int tmp;
        std::cin >> tmp;
        if (tmp < X) {
            ++a;
        } else {
            ++b;
        }
    }

    if (a < b) ans = a;
    else ans = b;

    std::cout << ans << std::endl;

    return 0;
}


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

int main() {
  int a,b; cin >> a >> b;
  if(a<10 && b < 10) cout << a*b << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 256
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	x := getNextInt(scanner)
	cc := make([]int, n)
	aa := makeGrid(n, m)
	for i := 0; i < n; i++ {
		cc[i] = getNextInt(scanner)
		for j := 0; j < m; j++ {
			aa[i][j] = getNextInt(scanner)
		}
	}
	var ans int = math.MaxInt32
	for i := 0; i < 1<<uint(n); i++ {
		c := 0
		xx := make([]int, m)
		for j := 0; j < n; j++ {
			if i>>uint(j)&1 == 0 {
				continue
			}
			for k := 0; k < m; k++ {
				xx[k] += aa[j][k]
			}
			c += cc[j]
		}
		for j := 0; j < m; j++ {
			if xx[j] < x {
				c = math.MaxInt32
				break
			}
		}
		if ans > c {
			ans = c
		}
	}
	if ans == math.MaxInt32 {
		fmt.Fprintln(writer, -1)
		return
	}
	fmt.Fprintln(writer, ans)
}
func makeGrid(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 2228
#include<iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<cmath>

using namespace std;

int main() {
    int n, h;
    cin >> n;
    vector<int> dp(n, INT_MAX);
    vector<int> input(n);
    for (int i=0; i<n; ++i) {
        cin >> h;
        input[i] = h;
    }
    dp[0] = 0;
    for (int i=0; i<input.size()-1; ++i) {
        dp[i+1] = min(dp[i+1], dp[i] + abs(input[i+1]-input[i]));
        if (i+2>=n) continue;
        dp[i+2] = min(dp[i+2], dp[i] + abs(input[i+2]-input[i]));
    }
    cout << dp[n-1] << endl;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				cout << "DENIED";
				return 0;
			}
		}
	}
	cout << "APPROVED";
}

Measured memory_bytes: 3636