akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 1;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans %= mod;
        ans *= power(i + 1, mod - 2);
        ans %= mod;
    }
    return ans;
}
int main(){
    ll n,l,a,b;
    cin >> n >> l >> a;
    rep1(i, n - 1){
        cin >> b;
        if(a + b >= l){
            pf("Possible");
            rep1(j, i - 1)pf(j);
            rrep1(j, n - 1){
                pf(j);
                if(j == i)break;
            }
            return 0;
        }
        a = b;
    }
    pf("Impossible");
    return 0;
}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int A, B; cin >> A >> B;
  //main
  
  
  // output
  if(A<=9 && B<=9){cout << A*B << endl;}
  else{cout << -1 << endl;}

  return 0;
}

Measured memory_bytes: 892
#include <iostream>

int main()
{
    using namespace std;
    int32_t A, B, X;
    cin >> A >> B >> X;
    
    auto x = X-A;

    if (x >= 0 && A <= X && x <= B) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
from itertools import accumulate
N, K = map(int, input().split())
grid = [[0] * (4 * K + 1) for _ in range(4 * K + 1)]
for _ in range(N):
    x, y, c = input().split()
    x = int(x)
    y = int(y)
    if c == "B":
        x += K
    x %= (2 * K)
    y %= (2 * K)
    grid[x+1][y+1] += 1
    grid[x+2*K+1][y+1] += 1
    grid[x+1][y+2*K+1] += 1
    grid[x+2*K+1][y+2*K+1] += 1

for i in range(4 * K):
    grid[i + 1] = list(accumulate(grid[i + 1]))

for i in range(4 * K):
    for j in range(1, 4 * K + 1):
        grid[i+1][j] += grid[i][j]


ans = 0
for i in range(2 * K):
    for j in range(2 * K):
        x = i
        y = j
        A = grid[x][y] - grid[x + K][y] - grid[x][y + K] + grid[x + K][y + K]
        x += K
        y += K
        B = grid[x][y] - grid[x + K][y] - grid[x][y + K] + grid[x + K][y + K]
        ans = max(ans, A + B)
print(ans)

Measured memory_bytes: 238088
//
// Created on 2020/01/26.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    int h;
    int n;
    cin>>h>>n;
    vector<int>A(n);
    vector<int>B(n);
    for (int l = 0; l < n; ++l) {
        cin>>A[l];
        cin>>B[l];
    }

    vector<vector <ll > > mp (n+1,vector<ll >(h+1,LINF));
    mp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= h; ++j) {
            mp[i+1][j] = min(mp[i+1][max(0,j-A[i])]+B[i],mp[i][j]);
            //for (int k = 1; A[i]*k <=h+k ; ++k) {
            //    mp[i+1][min(h,j+A[i]*k)] = min(mp[i+1][min(h,j+A[i]*k)],mp[i][j]+B[i]*k);}
        }
    }


    cout<<mp[n][h]<<endl;
}


Measured memory_bytes: 78592
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int h,w,n;
	cin>> h >> w >> n;
	int s_y,s_x;
	cin>> s_y >> s_x;
	string taka,aoki;
	cin>>taka>>aoki;

	bool flag = false;

	int now = s_y;
	//up?
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++){
			if(j==0 && taka[i] == 'U') now--;
			if(j==1 && aoki[i] == 'D') now = min(now+1,h);
			if(now<=0) flag = true;
		}
	}

	now = s_y;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++){
			if(j==0 && taka[i] == 'D') now++;
			if(j==1 && aoki[i] == 'U') now = max(now-1,1);
			if(now>h) flag = true;
		}
	}
	now = s_x;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++){
			if(j==0 && taka[i] == 'R') now++;
			if(j==1 && aoki[i] == 'L') now = max(now-1,1);
			if(now>w) flag = true;
		}
	}
	now = s_x;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++){
			if(j==0 && taka[i] == 'L') now--;
			if(j==1 && aoki[i] == 'R') now = min(now+1,w);
			if(now<=0) flag = true;
		}
	}

	cout << (flag?"NO":"YES")<<endl;


	return 0;
}

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

using namespace std;

const int maxn = 2010;

int s[3][maxn][maxn],a[maxn][maxn],n,m,q;

int cal(int x1,int y1,int x2, int y2,int type) {
    return s[type][x2][y2] - s[type][x1-1][y2] - s[type][x2][y1-1] + s[type][x1-1][y1-1];
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
 //   freopen("in.txt","r",stdin);
    cin>>n>>m>>q;
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++) {
            char ch;
            cin>>ch;
            a[i][j]=(ch=='1');
        }
    }
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) {
                s[0][i][j]=a[i][j];
                s[0][i][j]+=s[0][i-1][j]+s[0][i][j-1]-s[0][i-1][j-1];
            }
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) {
                s[1][i][j]=(i>1 && a[i][j]==1 && a[i-1][j]==1);
                s[1][i][j]+=s[1][i-1][j]+s[1][i][j-1]-s[1][i-1][j-1];
            }
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) {
                s[2][i][j]=(j>1 && a[i][j]==1 && a[i][j-1]==1);
                s[2][i][j]+=s[2][i-1][j]+s[2][i][j-1]-s[2][i-1][j-1];
            }
    for (int i=1;i<=q;i++) {
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
       // cout<<s[0][x2][y2]<<" "<<s[1][x2][y2]<<" "<<s[2][x2][y2]<<endl;
        cout<<cal(x1,y1,x2,y2,0) - cal(x1+1,y1,x2,y2,1) - cal(x1,y1+1,x2,y2,2) <<endl;
    }
}


Measured memory_bytes: 64896
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
string S;
cin >> S;
int nen = (S.at(0) - '0') * 1000 + (S.at(1) - '0') *100 + (S.at(2) - '0') *10 + (S.at(3) -'0');
int tuki = (S.at(5) - '0') *10 + (S.at(6) - '0');
if (nen < 2019) cout << "Heisei" << endl;
else if (nen > 2019) cout << "TBD" << endl;
else if (tuki <= 4) cout << "Heisei" << endl;
else if (tuki > 4) cout << "TBD" << endl;



return 0;
}


Measured memory_bytes: 256
import fractions
from functools import reduce


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    lcm_a = lcm(*a)
    fm = sum([(lcm_a - 1) % ai for ai in a])
    return fm


def lcm_base(x, y):
    return x * y // fractions.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 5332
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int a,b,n=100;
  cin >> b >> a;
  char s[n][n];
  rep(i,n) {
    rep(j,n) s[i][j]=i<n/2?'#':'.';
  }
  a--,b--;
  rep(i,n) {
    for(int j=0; j<n; j+=2) {
      if(b) {
        s[i][j]='.';
        b--;
      }
    }
    i++;
  }
  rrep(i,n) {
    for(int j=0; j<n; j+=2) {
      if(a) {
        s[i][j]='#';
        a--;
      }
    }
    i--;
  }
  pr(n,n);
  rep(i,n) {
    rep(j,n)cout << s[i][j];
    ln;
  }
}

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


Measured memory_bytes: 256
s = input()
ret = [0] * len(s)
c = 'R'
l = 0
for i in range(0, len(s) + 1):
    if i >= len(s) or s[i] != c:
        if c == 'R':
            ret[i     - 1] += l - l // 2
            ret[i        ] +=     l // 2
            c = 'L'
        else:
            ret[i     - l] += l - l // 2
            ret[i - l - 1] +=     l // 2
            c = 'R'
        l = 0
    l += 1
print(' '.join(map(str, ret)))


Measured memory_bytes: 10484
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		String[][] board = new String[3][3];
		int count=0;
		while((str=br.readLine())!=null){
			count=0;
			for(int i = 0 ; i < 3 ; i ++){
				for(int j = 0 ; j < 3 ; j ++){
					board[i][j]=String.valueOf(str.charAt(count));
					count++;
				}
			}
			String bool = check(board);
			System.out.println(bool);
		}
	}
	public static String check(String[][] b){
		for(int i = 0 ; i < 3 ; i ++){
			if(b[i][0].equals(b[i][1]) && b[i][1].equals(b[i][2])){
				if(!b[i][0].equals("s"))
					return b[i][0];
			}
			if(b[0][i].equals(b[1][i]) && b[1][i].equals(b[2][i])){
				if(!b[0][i].equals("s"))
					return b[0][i];
			}
		}
		if(b[1][1].equals("s"))
			return "d";
		if(b[0][0].equals(b[1][1])&& b[1][1].equals(b[2][2])){
			return b[0][0];
		}
		if(b[2][0].equals(b[1][1])&& b[1][1].equals(b[0][2])){
			return b[2][0];
		}
		return "d";		
	}
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define N 140

int main() {
    i64 X;
    cin >> X;

    auto pow5 = [](i64 x) {
        return x * x * x * x * x;
    };

    for (i64 i = -1 * N; i <= N; i++) {
        i64 A5 = pow5(i);
        for (i64 j = -1 * N; j <= N; j++) {
            if (i < 0 && j >= 0) continue;
            if (i >= 0 && j >= 0 && i < j) continue;

            if ((A5 - pow5(j)) == X) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

int main() {
	int year, month, day;
	while(cin>>year>>month>>day){
		if (year < 1868) {//????????\???????????£
			cout << "pre-meiji" << endl;
		}
		else if (year == 1868) {//????????\?????¨???????????´
			if (month = 9) {
				if (day < 8)cout << "pre-meiji" << endl;
				else if (day >= 8)cout << "meiji " << year - 1868 + 1 << ' ' << month << ' ' << day << endl;
			}
			else if (month < 9)cout << "pre-meiji" << endl;
			else if (month > 9)cout << "meiji " << year - 1868 + 1 << ' ' << month << ' ' << day << endl;
		}
		else if (year > 1868 && year < 1912) {//???????????´
			cout << "meiji " << year - 1868 + 1 << ' ' << month << ' ' << day << endl;
		}
		else if (year == 1912) {//????????¨??§??£?????´
			if (month < 7)cout << "meiji " << year - 1868 + 1 << ' ' << month << ' ' << day << endl;
			else if (month > 7)cout << "taisho " << year - 1912 + 1 << ' ' << month << ' ' << day << endl;
			else if (month = 7) {
				if (day <= 29)cout << "meiji " << year - 1868 + 1 << ' ' << month << ' ' << day << endl;
				else if (day > 29)cout << "taisho " << year - 1912 + 1 << ' ' << month << ' ' << day << endl;
			}
		}
		else if (year > 1912 && year < 1926) {//??§??£?????´
			cout << "taisho " << year - 1912 + 1 << ' ' << month << ' ' << day << endl;
		}
		else if (year == 1926) {//??§??£??¨???????????´
			if (month < 12)cout << "taisho " << year - 1912 + 1 << ' ' << month << ' ' << day << endl;
			else if (month = 12) {
				if (day <= 24)cout << "taisho " << year - 1912 + 1 << ' ' << month << ' ' << day << endl;
				else if (day > 24)cout << "showa " << year - 1926 + 1 << ' ' << month << ' ' << day << endl;
			}
		}
		else if (year > 1926 && year < 1989) {//??????????????£
			cout << "showa " << year-1926+1 << ' ' << month << ' ' << day << endl;
		}
		else if (year == 1989) {//????????¨???????????´
			if (month == 1) {
				if (day <= 7)cout << "showa " << year-1926+1 << ' ' << month << ' ' << day << endl;
				else if (day > 7)cout << "heisei " << year - 1989 + 1 << ' ' << month << ' ' << day << endl;
			}
			else if (month > 1)cout << "heisei " << year - 1989 + 1 << ' ' << month << ' ' << day << endl;
		}
		else if (year > 1989) {//??????????????£
			cout << "heisei " << year - 1989 + 1 << ' ' << month << ' ' << day << endl;
		}
	}
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int maxm = max(a+b, max(a-b, a*b));
  cout << maxm << endl;
}

Measured memory_bytes: 3628
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

x = int(input())
cnt = 1
a = 100
while True:
    a *= 1.01
    a = int(a)
    if a>=x:
        break
    cnt+=1
print(cnt)

Measured memory_bytes: 9476
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <stack>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

template<typename T> bool chmax( T &a, const T b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }

template<typename Monoid, typename T = ll> struct SegTree {
	using Func = function<Monoid( Monoid, Monoid )>;
	const Func func;
	const Monoid UNITY;
	T SIZE_R;
	vector<Monoid> data;

	SegTree( T n, const Func f, const Monoid &unity ) :
		func( f ), UNITY( unity ) {
			init( n );
		}

	void init( T n ) {
		SIZE_R = 1;
		while ( SIZE_R < n ) SIZE_R *= 2;
		data.assign( SIZE_R * 2, UNITY );
	}

	void set( T idx, const Monoid &val ) { data[idx + SIZE_R] = val; }
	void build() {
		for ( T k = SIZE_R - 1; k > 0; --k )
			data[k] = func( data[k * 2], data[k * 2 + 1] );
	}

	void update( T idx, const Monoid &val ) {
		T k = idx + SIZE_R;
		data[k] = val;
		while ( k >>= 1 ) data[k] = func( data[k * 2], data[k * 2 + 1] );
	}

	Monoid get( T a, T b ) {
		Monoid vleft = UNITY, vright = UNITY;
		for ( T left = a + SIZE_R, right = b + SIZE_R;
			  left < right;
			  left >>= 1, right >>= 1 ) {
			if ( left & 1 ) vleft = func( vleft, data[left++] );
			if ( right & 1 ) vright = func( data[--right], vright );
		}

		return ( func( vleft, vright ) );
	}

	inline Monoid operator[]( ll idx ) { return ( data[idx + SIZE_R] ); }
};


int main()
{
	ll n; cin >> n;
	vector<Pll> a( n );
	rep( i, n )
	{
		cin >> a[i].F;
		a[i].S = i;
	}
	sort( ALL( a ), greater<Pll>() );
	a.eb( mp( 0, n ) );

	vector<ll> ans( n );
	ll idx = a[0].S;
	rep( i, n )
	{
		chmin( idx, a[i].S );
		ans[idx] += ( i + 1 ) * ( a[i].F - a[i + 1].F );
	}

	rep( i, n ) cout << ans[i] << endl;

	return ( 0 );
}


Measured memory_bytes: 6032
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long

int inf = (1LL <<  62);
using namespace std;

signed main(){
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> v;
    
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        pair<int, int> p;
        p.first = a;
        p.second = b;
        v.push_back(p);
    }
    
    sort(v.begin(), v.end());
    int ch = 0;
    
    for(int i = 0; i < n; i++){
        ch += v[i].second;
        if(ch >= k){
            cout << v[i].first;
            exit(0);
        }
    }
}


Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC123_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int[] count = new int[3];
            count[0] = int.Parse(strs[0]);
            count[1] = int.Parse(strs[1]);
            count[2] = int.Parse(strs[2]);

            int k = int.Parse(strs[3]);

            long[][] tasty = new long[3][];
            for (int i = 0; i < 3; ++i)
            {
                tasty[i] = new long[count[i]];

                string[] strs_ = Console.ReadLine().Split(' ');

                for (int j = 0; j < count[i]; ++j)
                {
                    tasty[i][j] = long.Parse(strs_[j]);
                }
            }

            long[] AB = new long[count[0] * count[1]];
            int indexAB = 0;
            for (int i = 0; i < count[0]; ++i)
            {
                for (int j = 0; j < count[1]; ++j)
                {
                    AB[indexAB] = tasty[0][i] + tasty[1][j];
                    ++indexAB;
                }
            }

            // LINQでソート
            //var sortedAB = AB.OrderBy(a => -a).ToArray();
            Array.Sort(AB);

            long[] ABC = new long[k * count[2]];
            int indexABC = 0;
            //int countAB = Math.Min(k, sortedAB.Count());
            int countAB = Math.Min(k, AB.Count());
            //for (int i = 0; i < countAB; ++i)
            for (int i = AB.Count() - 1; i >= AB.Count() - countAB; --i)
            {
                for (int j = 0; j < count[2]; ++j)
                {
                    //ABC[indexABC] = sortedAB[i] + tasty[2][j];
                    ABC[indexABC] = AB[i] + tasty[2][j];
                    ++indexABC;
                }
            }

            //var sortedABC = ABC.OrderByDescending(a => a).ToArray();
            Array.Sort(ABC);

            //for (int i = 0; i < k; ++i)
            for (int i = ABC.Count() - 1; i >= ABC.Count() - k; --i)
            {
                //Console.WriteLine($"{sortedABC[i]}");
                Console.WriteLine($"{ABC[i]}");
            }
        }
        
    }
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> M(H);
  vector<bool> b(H);
  char c='.';
  
  for(int i=0; i<H; i++){
    int count=0;
    b.at(i)=1;
    cin >> M.at(i);
    for(int j=0; j<W; j++){
      if(M.at(i).at(j)==c){
        count++;
      }
    }
    if(count == W){
      b.at(i)=0;
      for (int k=0; k<W; k++){
        M.at(i).at(k)='x';
      }
    }
  }
  for(int i=0; i<W; i++){
    int count=0;
    for(int j=0; j<H ; j++){
      if(M.at(j).at(i)==c || M.at(j).at(i)=='x'){
        count++;
      }
    }
    if(count == H){
      for(int k=0; k<H; k++){
        M.at(k).at(i)='x';
      }
    }
  }
      
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if( M.at(i).at(j)!='x'){
        cout << M.at(i).at(j);
      }
    }
    if(b.at(i)){
      cout << endl;
    }
  }
  
 
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;


int main(){
    int a,b;cin>>a>>b;
    char s[a+b+1];cin>>s;
    bool flag=true;
    for(int i=0;i<=a+b;i++){
        if(i!=a&&s[i]=='-')flag=false;
        if(i==a&&s[i]!='-')flag=false;
    }
    if(flag==true)printf("Yes");
    else printf("No");
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

void solve()
{

}

int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin>>s;
int c=0;
rep(i,0,2)
{
	if(s[i]=='R')c++;
}
if(c!=2)
{
	ol(c);
}
else
{
	if(s[1]=='R')ol(2);
	else ol(1);
}
return 0;
}



Measured memory_bytes: 3648
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
memo = [0] * (k + 1)
for i in range(k, 0, -1):
    ret = 0
    ret += pow(k // i, n, mod)
    for j in range(2, k // i + 1):
        ret -= memo[j * i]
    memo[i] = ret % mod

ans = 0
for l in range(1, k + 1):
    ans = (ans + l * memo[l]) % mod

print(ans)


Measured memory_bytes: 78984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main() {
    ll x,k,d;
    cin >> x >> k >> d;
    x=abs(x);
    ll c=min(k,x/d);
    x-=c*d;
    if((k-c)%2)x=d-x;
    cout << x;
}

/*



 */


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

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

    bitset<100> counts;

    for (int i = 0; i < K; ++i) {
        int d_i;
        cin >> d_i;

        for (int j = 0; j < d_i; ++j) {
            int man;
            cin >> man;
            counts[man - 1] = 1;
        }
    }

    cout << N - counts.count() << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  long long int n,k;
  cin>>n>>k;
  long long int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(long long int i = k;i<n;i++)
  {
    if(a[i] > a[i-k]){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
  }
}

Measured memory_bytes: 5204
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
    
    Scanner scan =new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    if ( (a+b) >= 24){
        System.out.println(a+b-24);
    } 
    else {
        System.out.println(a+b);
    }
    }
}

Measured memory_bytes: 21588
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,c,l[7],f[305][1<<5][305],p[6];
double ans;
bool flag[6];
void DP()
{
	memset(f,0,sizeof(f));
	f[0][0][l[0]*(n+1)]=1;
	for(int i=1;i<=c*(n+1);i++)
	{
		for(int s=0;s<(1<<n);s++)
		{
			for(int r=i;r<=c*(n+1);r++)
			{
				if(f[i-1][s][r]==0)continue;
				f[i][s][r]+=f[i-1][s][r];
				int t=i%(n+1);
				if(t==0||((1<<(t-1))&s))continue;
				f[i][s|(1<<(t-1))][min(max(r,i+l[p[t]]*(n+1)),c*(n+1))]+=f[i-1][s][r];
			}
		}
	}
	ans+=f[c*(n+1)][(1<<n)-1][c*(n+1)];
}
void dfs(int step)
{
	if(step>n)return DP();
	for(int i=1;i<=n;i++)
	{
		if(flag[i])continue;
		p[step]=i;
		flag[i]=1;
		dfs(step+1);
		flag[i]=0;
	}
}
int main()
{
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;i++)scanf("%d",&l[i]);
	sort(l+1,l+n+1);
	l[0]=l[n];
	n--;
	dfs(1);
	for(int i=1;i<=n;i++)ans/=c*i;
	printf("%.16lf\n",ans);
	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

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

    //累積のmax
    vector<int> l(n);
    vector<int> r(n);

    l[0] = a[0];
    r[n-1] = a[n-1];

    for (int i = 1; i < n; ++i) {
        l[i] = max(l[i-1], a[i]);
    }

    for (int i = n-2; i > 0; --i) {
        r[i] = max(r[i+1], a[i]);
    }

    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            cout << r[1] << endl;
            continue;
        }

        if (i == n-1) {
            cout << l[n-2] << endl;
            continue;
        }

        cout << max(l[i-1], r[i+1]) << endl;
    }
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
#define fileio freopen("template.in", "r", stdin), freopen("template.out", "w", stdout);
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;

int main() {
    fastio;
    //fileio;
        
    int n;
    cin >> n;
    bool doublet[n];
    FOR(i, 0, n) {
        int a, b;
        cin >> a >> b;
        if (a == b) {
            doublet[i] = true;
        } else {
            doublet[i] = false;
        }
    }
    bool answer = false;
    FOR(i, 0, n-2) {
        if (doublet[i] && doublet[i+1] && doublet[i+2]) {
            answer = true;
            break;
        }
    }
    if (answer) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    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;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    string S; cin >> S;
    int A[N];
    rep(i, N){
        if(S[i] == 'R') A[i] = 0;
        else if(S[i] == 'G') A[i] = 1;
        else A[i] = 2;
    }
    int appear[3][N+1];
    rep(i, 3) appear[i][0] = 0;
    rep(i, N){
        rep(j, 3) appear[j][i+1] = appear[j][i];
        if(A[i] == 0) appear[0][i+1]++;
        else if(A[i] == 1) appear[1][i+1]++;
        else appear[2][i+1]++;
    }
    ll ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            int aim;
            if(A[i] == A[j]) continue;
            if(0 != A[i] && 0 != A[j]) aim = 0;
            else if(1 != A[i] && 1 != A[j]) aim = 1;
            else if(2 != A[i] && 2 != A[j]) aim = 2;
            ans += appear[aim][j] - appear[aim][i+1];

            if((j-i) % 2 == 0 && A[(j+i)/2] == aim) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(n) cout<<a[i]<<endl printf("%s\n"," " );
#define sc(a) scanf("%d",&a);
#define scl(a) scanf("%lld",&a);
#define scf(a) ascanf("%f",&a);
#define ff first
#define ss second
#define pu push_back
#define inf 1000000001
#define MOD 1000000007 
#define INF 100000000000001
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // string s;
    int s;
	cin>>s;
	if((s/100>12 || s/100==0)&&s%100<=12 && s%100)
		cout<<"YYMM";
	else if(s/100<=12 && s/100 && (s%100>12 || s%100==0))
		cout<<"MMYY";
	else if(s/100<=12 && s%100 <=12 && s%100 && s/100)
		cout<<"AMBIGUOUS";
	else
		cout<<"NA";
	return 0;

}
    

Measured memory_bytes: 256
N,D=map(int,input().split())
X=[]
count=0
for i in range(N):
  X.append(list(map(int,input().split())))
for i in range(N):
  for j in range(i+1,N):
    sum_=0
    for k in range(D):
      sum_+=(X[i][k]-X[j][k])**2
    ans=sum_**(1/2)
    if ans.is_integer():
      count+=1
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

long h[30];
int main(){
    long n;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    long max=h[0];
    long count=1;

    for(int i=1; i<n; i++){
        if( h[i] >= max){
            count++;
            max = h[i];
        }
    }

    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
N,K = map(int,input().split())
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int,input().split())))

D = [0] * N
for k in A:
    for i in k:
        D[i-1] += 1
res = 0
for i in D:
    if i == 0:
        res += 1
print(res)        

Measured memory_bytes: 9196
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll maxn = 1e6 + 5;

ll h,w;
char e[30][30];
int dis[30][30];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};


int bfs(int x,int y){
	memset(dis,INF,sizeof(dis));
	queue<P>q;
	q.push({x,y});
	dis[x][y]=0;
	while(!q.empty()){
		P top=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int tx=top.first+dx[i];
			int ty=top.second+dy[i];
			if(tx>0 && tx<=h && ty>0 && ty<=w && e[tx][ty]=='.' && dis[tx][ty]==INF){
				dis[tx][ty]=dis[top.first][top.second]+1;
				q.push({tx,ty});
			}
		}
	}
	int ans=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(dis[i][j]!=INF) ans=max(ans,dis[i][j]);
		}
	}
	return ans;
}

int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>e[i][j];
		}
	}
	int ans=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(e[i][j]=='.') ans=max(ans,bfs(i,j));
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int n = sc.nextInt();
        final String s = sc.next();

        int ans = 0;
        for (int i = 0; i < n-2; i++) {
            if (s.charAt(i) == 'A' && s.charAt(i+1) == 'B' && s.charAt(i+2) == 'C') {
                ans++;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int x,y,z,cnt=0;
    cin>>x>>y>>z;
    x-=z;
    while(x>0)
    {
        x-=y;
        x-=z;
        if(x>=0)
        {
            cnt++;
        }
    }
    cout<<cnt<<NL;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	ll n, k;
	cin >> n >> k;
	n %= k;
	ll ans = min(n, abs(n - k));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int m = scn.nextInt();
        int f = scn.nextInt();
        int r = scn.nextInt();

        while (m != -1 || f != -1 || r != -1) {
            int sum = m + f;
            if (m == -1 || f == -1) {
                System.out.println("F");
            } else if (sum >= 80) {
                System.out.println("A");
            } else if (sum >= 65) {
                System.out.println("B");
            } else if (sum >= 50) {
                System.out.println("C");
            }else if(sum >= 30){
                if(r >= 50){
                    System.out.println("C");
                }else{
                    System.out.println("D");
                }
            }else{
                System.out.println("F");
            }
            m = scn.nextInt();
            f = scn.nextInt();
            r = scn.nextInt();
        }


        scn.close();

    }


}




Measured memory_bytes: 26408
//https://algospot.com/judge/problem/read/CLOCKSYNC
#include <iostream>
#include <cstdio>
#include <functional>
#include <algorithm>
#include <climits>
#include <utility>
#include <string>
#include <stack>
#include <vector>
#include <queue>
#include <map>

#define LF '\n';
#define MOD 1000000007

typedef unsigned long long ull;
typedef long long ll;

using namespace std;

int main(void)
{
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a*b));
	return 0;
}	

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long

int a[300000];
int main()
{
    IO;
    long long i, j, m, k, n, t, l=0, mxx,mx1,r,c,x,y=1e9+7, ans=0;
    cin>>n>>k;
    for(i=k; i<=n+1; i++){
        l=n+1-i;
        m=(n*(n+1))/2-(l*(l-1))/2-(i*(i-1))/2+1;
        ans=(ans+m)%y;
    }
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 3664
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let d = get!();
    let x = d + 1 + d;
    let ans = (n + x - 1) / x;
    println!("{}", ans);
    
}

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

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

    int n;
    cin >> n;

    set<string> s;
    while (n--) {
        string t;
        cin >> t;
        s.insert(t);
    }

    cout << s.size();

    return 0;
}


Measured memory_bytes: 19264
io = STDIN
n=io.gets.chomp.to_i
a=[]
n.times do
  a<<io.gets.chomp.to_i
end
cnt=0
srt=a.sort
hash={}
srt.each_with_index do |x,i|
  hash[x]=i
end
a.each_with_index do |x,i|
  cnt+=(hash[x]-i).odd? ? 1 : 0
end
puts cnt/2

Measured memory_bytes: 10144
#include <stdio.h>

int gcd(int a, int b) 
{
   while (b > 0) {
      int n;
      n = a % b;
      a = b;
      b = n;
   }
   return a;
}

int main() {
    int a, b, c;
    scanf ("%d %d", &a, &b);
    c = gcd(a, b);
    printf("%d\n", c);
    return 0;
}

Measured memory_bytes: 592
a1,a2,a3,a4,a5= map(int, input().split())
if a1 == 0:
  k = 1
elif a2 == 0:
  k = 2
elif a3 == 0:
  k = 3
elif a4 == 0:
  k = 4
elif a5 == 0:
  k = 5
print(k)

Measured memory_bytes: 9172
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    ll n,k;
    cin>>n>>k;
    int ans=0;
    while(1){
        n = n/k;
        if(n==0) break;
        ans++;
    } 
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N=1e5+3;
int n,q;
vector<vector<int>> g;
vector<int> wt;
void dfs(int node, int par=-1)
{
	if(par!=-1)wt[node]+=wt[par];
	for(auto u:g[node])
	{
		if(u==par)continue;
		dfs(u,node);
	}
}
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	cin>>n>>q;
	g=vector<vector<int>>(n);
	wt=vector<int>(n);
	int a,b;
	for(int i=1;i<n;i++)
	{
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	while(q--)
	{
		cin>>a>>b;
		wt[a-1]+=b;
	}

	dfs(0);

	for(int i=0;i<n;i++)cout<<wt[i]<<" ";

	

	
	
	
}

Measured memory_bytes: 25136
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int N = rei();
	string A = res();
	string B = res();
	string C = res();
	int ans = 0;
	for(int i=0;i<N;i++){
		if(A[i] == B[i] && B[i] == C[i]){
			
		}
		else if(A[i] != B[i] && B[i] != C[i] && A[i] != C[i]){
			ans += 2;
		}
		else{
			ans++;
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

int main() {
  string a,b,c;
  cin >> a >> b >> c;
  char d,e,f;
  d = toupper(a[0]);
  e = toupper(b[0]);
  f = toupper(c[0]);
  cout << d << e << f << endl;
}


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

using namespace std;
int gcd(int a,int b){
    if(b==0){return a;}

    return gcd(b,a%b);
}
int main()
{
    int n,x;
    cin>>n>>x;
    if(n==1){
        int y;
        cin>>y;
        cout<<abs(y-x)<<endl;
        return 0;
    }
    vector<int>prefix;
    vector<int>normal;
    normal.push_back(x);
    for(int i=0;i<n;i++){
        int d;
        cin>>d;
        normal.push_back(d);
    }
    sort(normal.begin(),normal.end());
    for(int i=0;i<n;i++){
        prefix.push_back(abs(normal[i]-normal[i+1]));
    }
    int ans=gcd(prefix[0],prefix[1]);
    for(int i=2;i<prefix.size();i++){
        ans=gcd(ans,prefix[i]);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) {
        if (a & 1) cout << 0 << endl;
        else cout << -1 << endl;
        exit(0);
    }
    int ans = 0;
    while (!(a & 1) && !(b & 1) && !(c & 1)) {
        ans++;
        int x = a, y = b, z = c;
        a = (y + z) / 2, b = (x + z) / 2, c = (x + y) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, Q; string S;
	cin >> N >> S >> Q;
	int sz = 1;
	while (sz < N) sz *= 2;
	vector<int> seg(2 * sz);
	for (int i = 0; i < N; ++i) {
		seg[i + sz] = 1 << int(S[i] - 'a');
	}
	for (int i = sz - 1; i >= 1; --i) {
		seg[i] = seg[2 * i] | seg[2 * i + 1];
	}
	for (int i = 0; i < Q; ++i) {
		int tp;
		cin >> tp;
		if (tp == 1) {
			int x; string s;
			cin >> x >> s;
			char c = s[0]; --x;
			S[x] = c;
			int pos = x + sz;
			seg[pos] = 1 << int(c - 'a');
			while (pos > 1) {
				pos >>= 1;
				seg[pos] = seg[2 * pos] | seg[2 * pos + 1];
			}
		}
		else {
			int l, r;
			cin >> l >> r; --l;
			l += sz; r += sz;
			int bit = 0;
			while (l != r) {
				if (l & 1) bit |= seg[l++];
				if (r & 1) bit |= seg[--r];
				l >>= 1, r >>= 1;
			}
			int cnt = 0;
			for (int j = 0; j < 26; ++j) {
				if ((bit >> j) & 1) ++cnt;
			}
			cout << cnt << '\n';
		}
	}
	return 0;
}

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

using namespace std;

typedef long long int ll;

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

  int n;
  cin >> n;
  vector < int > a(n), b (n);
  for (auto &i : a) cin >> i;
  for (auto &i : b) cin >> i;
  ll moves = 0;
  priority_queue < pair < int, int > > q;
  for (int i = 0; i < n; i++) q.push ({b[i], i});

  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    int l = u - 1, r = u + 1;
    if (l < 0) l = n - 1;
    if (r == n) r = 0;

    int k = (b[u] - a[u]) / (b[l] + b[r]);
    if (b[u] != a[u] && k <= 0) {
      cout << -1 << '\n';
      return 0;
    }
    b[u] -= k * (b[l] + b[r]);
    moves += k;

    if (b[u] != a[u]) q.push ({b[u], u});
  }

  cout << moves << '\n';
}


Measured memory_bytes: 6904
import sys
import math
import bisect

def solve(A, m):
    n = len(A)
    ans = n
    m -= sum(A)
    ans += m // min(A)
    return ans

def main():
    n, m = map(int, input().split())
    A = []
    for i in range(n):
        A.append(int(input()))
    print(solve(A, m))

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384