akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
	std::cin >> N;

	if (N == 0) {
		std::cout << "0" << std::endl;
		return;
	}

	std::string S = "";
	while(N != 0) {
		int64_t r = N % 2;
		if (r == 0) {
			S += "0";
		} else {
			S += "1";
		}
		if (r < 0) {
			r = 1;
		}
		N = (N - r) / (-2);
	}
	std::reverse(S.begin(), S.end());
	for (auto const& ch : S) {
		std::cout << ch;
	}

}

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


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  ll ans;
  if (a > b)
    ans = 0;
  else if (n == 1 && a < b)
    ans = 0;
  else if (n == 1 && a == b)
    ans = 1;
  else {
    ans = (n - 2) * (b - a) + 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int x = 0;
	int maxi = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'S')x++;
		else x--;
		if (x < 0)maxi = max(maxi, -x);
	}
	printf("%d\n", maxi * 2);
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,d,x;
	cin>>n>>d>>x;
	lp2(i,n){
		int a;
		cin>>a;
		for(int j=1;j<=d;j+=a){
			x++;
			}
	}
	cout<<x<<endl;
	return 0;
}

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

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

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPR(i,n) for(int (i)=(n-1);(i)>=0;i--)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);i++)
#define FORR(i,m,n) for(int (i)=(m-1);(i)>=(n);i--)
#define PRINT(x) {cout<<(x)<<"\n";}

int main(){
    string s = "753";
    string x;
    cin >> x;
    if (s.find(x) != string::npos) PRINT("YES")
    else PRINT("NO")
}

Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll m,d;
  std::cin>>m>>d;

  ll ans=0;

  rep(i,4,m+1){
    rep(j,1,d+1){
      ll d1=j%10,d2=(j-d1)/10;
      if(d1>=2&&d2>=2&&d1*d2==i)ans++;
    }
  }

  std::cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
map<int,int>mp;
int n,x;
bool ans=true;
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>x;
		if(mp[x])
		{
			ans=false;
		}
		mp[x]=1;
	}
	if(ans)
		puts("YES");
	else
		puts("NO");
	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <stdlib.h>

int main()
{
   int A,B,C,K;
   scanf("%i %i %i %i",&A,&B,&C,&K);

   if(K<=A){
    printf("%i\n",(K*1));
   }
   else if((K>=A)&&(K<=A+B)){
     printf("%i\n",((A*1)+(K-A)*0));
   }
   else if((K>=A+B)&&(K<=A+B+C)){
    printf("%i\n",((A*1)+(B*0)+((K-A-B)*(-1))));
   }

    return 0;
}


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

int main() {
    int a;
    cin >> a;
    int x[4]={a/1000, (a/100)%10, (a/10)%10,  a%10}, y[3];
    int ans;
    for (y[0] = 0; y[0] < 2; ++y[0]) {
        for (y[1] = 0; y[1] < 2; ++y[1]) {
            for (y[2] = 0; y[2] < 2; ++y[2]) {
                ans = 2 * (x[0] + y[0] * x[1] + y[1] * x[2] + y[2] * x[3])
                        - (x[0] + x[1] + x[2] + x[3]);
                if (ans== 7) {
                    cout << x[0];
                    for (int l = 0; l < 3; ++l) {
                        cout << char('-' - 2 * y[l]);
                        cout << x[l+1];
                    }
                    cout << "=7\n";
                    return 0;
                }
            }
        }
    }
}

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

template<typename T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define inf 1000000000000000000
#define iinf -1000000000000000000
#define __   ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define mod 1000000007
#define base 1949313259
#define en '\n'

ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }

ll ar[]={0,0,1,-1};
ll br[]={1,-1,0,0};

ll bigmod(ll n,ll pow){
if(pow==0) return 1;
if(pow==1) return n%mod;

ll ans=bigmod(n,pow/2);
ans=(ans*ans)%mod;

if(pow%2==1){ans=(ans*n)%mod;}
return ans%mod;
}

ll fact[1000005];

ll nCr(ll n,ll r){

ll ans=fact[n];
ans=(ans*bigmod(fact[r],mod-2))%mod;
ans=(ans*bigmod(fact[n-r],mod-2))%mod;
return ans;
}

string s,s1,s2;
ll n,m;
ll arr[500010];
ll brr[500010];
vector<ll>v,v1;

map<ll,ll>mp;
ll vis[500005];

int main()
{__
        ll i,j,a,b,c,d,e,f,g,x,y,z,t,k,l,r;
        fact[0]=1;

      //  for(i=1;i<=1000000;i++) fact[i]=(fact[i-1]*i)%mod;
        ll ans=0,sum=0,temp;
        cin>>n>>k;

        for(i=0;i<n;i++) cin>>arr[i];

        sort(arr,arr+n);

        for(i=0;i<k;i++){
            sum+=arr[i];
        }
        cout<<sum<<endl;
}




Measured memory_bytes: 3612
#include <iostream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

typedef long long lint;

using namespace std;

int main(){
  int N,x;
  cin>>N>>x;
  int a[N];
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  lint ans=0;
  if(a[0]>x){
    ans+=a[0]-x;
    a[0]=x;

  }
  for(int i=1;i<N;i++){
    if(a[i]+a[i-1]>x){
      ans+=a[i]+a[i-1]-x;
      a[i]=x-a[i-1];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<pll,ll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define piii pair<pii, int>
#define pb push_back
const ll llinf = 2e18 + 7;
const int inf = 2e9 + 7;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 1;
const ll M = 1e3 + 5;
const ld pi = 3.14159265358979; 
void solve() {
    ll n;
    cin>>n;
    ll ans = 0;
    for(ll i=1;i<=n;i++) {
        ll cnt = (n/i);
        cnt = (cnt * (cnt + 1))/2;
        ll sum = i * (cnt);
        ans += sum;
    }
    cout<<ans;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    
    // cin>>t;
    while(t--) {
        solve();
        cout<<"\n";
    }
    return 0; 

}


Measured memory_bytes: 3664
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0; i< int(n); (i)++)
int main()
{
    int n;
    cin >> n;
    
    if(n==1)
    {
        cout << "1" <<endl;
        return 0;
    }
    
    REP(i,n)
    {
        if((i+1)*(i+1) > n)
        {
            cout << i*i << endl;
            i=n;
        }
    }
    return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d %d %d", $N, $A, $B, $C);
$L = [];
for ($i = 0; $i < $N; ++$i) {
    fscanf(STDIN, "%d", $l);
    $L[] = $l;
}

function dfs($n, $a, $b, $c) {
    global $N, $A, $B, $C, $L;

    if ($n === $N) {
        if (count($a) === 0 || count($b) === 0 || count($c) === 0) return PHP_INT_MAX;
        /* echo "a: [" . implode (', ', $a) . "], A: $A, cost: " . sum_v($a), PHP_EOL; */
        /* echo "b: [" . implode (', ', $b) . "], B: $B, cost: " . sum_v($b), PHP_EOL; */
        /* echo "c: [" . implode (', ', $c) . "], C: $C, cost: " . sum_v($c), PHP_EOL; */
        /* echo "total cost: " . (abs($A - sum_v($a)) + abs($B - sum_v($b)) + abs($C - sum_v($c)) ), PHP_EOL; */
        /* echo PHP_EOL; */

        return sum_v($a, $A) + sum_v($b, $B) + sum_v($c, $C);
    }

    $ret0 = dfs($n + 1, $a, $b, $c);
    $ret1 = dfs($n + 1, array_merge($a, [$L[$n]]), $b, $c);
    $ret2 = dfs($n + 1, $a, array_merge($b, [$L[$n]]), $c);
    $ret3 = dfs($n + 1, $a, $b, array_merge($c, [$L[$n]]));

    return min($ret0, $ret1, $ret2, $ret3);
}

function sum_v($arr, $target) {
    $sum = 0;
    foreach ($arr as $key => $val) {
        if ($key >= 1) {
            $sum += 10;
        }
    }
    return $sum + abs(array_sum($arr) - $target);
}

echo dfs(0, [], [], []);


Measured memory_bytes: 4728
#include<stdio.h>
#define SWAP(a,b) (a+=b,b=a-b,a-=b)
const int MOD = 1000000007;

int main(void){
  int N;
  long AA[100005],BB[100005];

  scanf("%d",&N);

  for(int i=0; i<N+1; i++){
    scanf("%ld",&AA[i]);
  }

  for(int i=0; i<N; i++){
    scanf("%ld",&BB[i]);
  }

  long ans = 0;
  for(int i=0; i<N; i++){
    long B = BB[i];
    if(B <= AA[i]){
      ans += B;
    }else if(AA[i] <= B && B <= AA[i]+AA[i+1]){
      ans += B;
      AA[i+1] -= (B-AA[i]);
    }else{
      ans += AA[i]+AA[i+1];
      AA[i+1] = 0;
    }
  }

  printf("%ld\n",ans);

}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
 int N; cin>>N;
 map <int,int> mp;
 for(int i=0;i<N;i++){
   int a; cin>>a;
   mp[a]++;
   mp[a] = mp[a] % 2;
 }
 ll ans = 0;
 for(auto itr = mp.begin();itr != mp.end();itr++){
   if((*itr).second == 1) ans ++;
 }
cout<<ans<<endl;
  return 0;

}

Measured memory_bytes: 4992
#!/usr/bin/env python3

a, b = map(int, input().split())

h = 98
w = 99
print(h, w)

grid = [["." for i in range(w)] for j in range(h)]

for i in range(h // 2, h):
    for j in range(w):
        grid[i][j] = "#"

def ij_k(k):
    row = (w - 1) // 2
    i = (k // row) * 2 + 1
    j = (k % row) * 2 + 1
    assert 0 < i < h // 2 - 1
    assert 0 < j < w - 1
    return i, j

for k in range(b - 1):
    i, j = ij_k(k)
    grid[i][j] = "#"

for k in range(a - 1):
    i, j = ij_k(k)
    grid[i + h // 2][j] = "."

for i in range(h):
    r = "".join(grid[i])
    print(r)


Measured memory_bytes: 3188
using System;

class Plogram
{
    static void Main()
    {
        string b = Console.ReadLine();

        if("A"==b)
        {
            Console.WriteLine("T");
        }
        else if("C"==b)
        {
            Console.WriteLine("G");
        }
        else if("G"==b)
        {
            Console.WriteLine("C");
        }
        else
        {
            Console.WriteLine("A");
        }
    }
}


Measured memory_bytes: 13140
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,C,K = mint()
T = [int(input()) for _ in range(N)]
T.sort()
t0 = 0
i = 0
ans = 0
for t in T:
    if i==0:
        t0 = t
        i = 1
        ans += 1
    elif t-t0>K:
        t0 = t
        i = 1
        ans += 1
    else:
        i += 1
    if i==C:
        i = 0
print(ans)

Measured memory_bytes: 80900
import heapq

X,Y,Z,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

que = []
heapq.heappush(que, [(A[0]+B[0]+C[0])*-1,0,0,0])
data = [[0,0,0]]
for i in range(K):
    tmp = heapq.heappop(que)
    print(tmp[0]*-1)
    if tmp[1]+1 < len(A) and [(A[tmp[1]+1]+B[tmp[2]]+C[tmp[3]])*-1,tmp[1]+1,tmp[2],tmp[3]] not in data:
        heapq.heappush(que, [(A[tmp[1]+1]+B[tmp[2]]+C[tmp[3]])*-1,tmp[1]+1,tmp[2],tmp[3]])
        data.append([(A[tmp[1]+1]+B[tmp[2]]+C[tmp[3]])*-1,tmp[1]+1,tmp[2],tmp[3]])
    if tmp[2]+1 < len(B) and [(A[tmp[1]]+B[tmp[2]+1]+C[tmp[3]])*-1,tmp[1],tmp[2]+1,tmp[3]] not in data:
        heapq.heappush(que, [(A[tmp[1]]+B[tmp[2]+1]+C[tmp[3]])*-1,tmp[1],tmp[2]+1,tmp[3]])
        data.append([(A[tmp[1]]+B[tmp[2]+1]+C[tmp[3]])*-1,tmp[1],tmp[2]+1,tmp[3]])
    if tmp[3]+1 < len(C) and [(A[tmp[1]]+B[tmp[2]]+C[tmp[3]+1])*-1,tmp[1],tmp[2],tmp[3]+1] not in data:
        heapq.heappush(que, [(A[tmp[1]]+B[tmp[2]]+C[tmp[3]+1])*-1,tmp[1],tmp[2],tmp[3]+1])
        data.append([(A[tmp[1]]+B[tmp[2]]+C[tmp[3]+1])*-1,tmp[1],tmp[2],tmp[3]+1])

Measured memory_bytes: 5100
package main

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

func main() {
	M := getInt()
	D := getInt()

	cnt := 0
	for m := 1; m <= M; m++ {
		for d := 1; d <= D; d++ {
			d1 := d % 10
			d10 := d / 10
			if (d1 < 2) || (d10 < 2) {
				continue
			}

			if m == d1*d10 {
				cnt++
			}
		}
	}

	fmt.Println(cnt)
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


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

int res[101];

void prime_factor(int n){
    res[0]=-1;
    for(int i=2; i*i<=n; i++){
        while(n%i==0){
            res[i]++;
            n/=i;
        }
    }
    if(n!=1) res[n]++;
    return;
}

int main(){
	int n,ans=0,hist[5];
	memset(res,0,sizeof(res));
	memset(hist,0,sizeof(hist));
	cin>>n;
	for(int i=n;i>=2;i--) prime_factor(i);
	for(int i=0;i<101;i++){
		if(res[i]>=2) hist[0]++;
		if(res[i]>=4) hist[1]++;
		if(res[i]>=14) hist[2]++;
		if(res[i]>=24) hist[3]++;
		if(res[i]>=74) hist[4]++;
	}
	ans += (hist[0]-1)*hist[3] + (hist[1]-1)*hist[2] + hist[4] + (hist[0]-2)*(hist[1])*(hist[1]-1)/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        ax: [i64; n]
    }

    let mut dp = vec![0; n+1];

    let mut axi: Vec<_> = ax.iter().enumerate().collect();
    axi.sort_by_key(|a| a.1);

    for i in 0..n {
        let (pos, &ai) = axi[i];
        let pos = pos as i64;
        for l in 0..n-i {
            let r = (l + i) as i64;
            let u = dp[l] + ai * (r - pos).abs();
            let v = dp[l+1] + ai * (l as i64 - pos).abs();
            dp[l] = std::cmp::max(u, v);
        }
    }

    println!("{}", dp[0]);
}


Measured memory_bytes: 2304
#include <climits>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(3 * N);
  rep(i, M) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    G[3 * u + 0].emplace_back(3 * v + 1);
    G[3 * u + 1].emplace_back(3 * v + 2);
    G[3 * u + 2].emplace_back(3 * v + 0);
  }

  int S, T;
  cin >> S >> T;
  --S;
  --T;
  vector<int> visit(3 * N, INT_MAX);
  visit[3 * S] = 0;
  queue<pair<int, int>> que;
  que.emplace(0, 3 * S);
  while (!que.empty()) {
    int step, u;
    tie(step, u) = que.front();
    que.pop();
    if (visit[u] < step) continue;
    int nstep = step + 1;
    for (auto v : G[u]) {
      if (visit[v] <= nstep) continue;
      visit[v] = nstep;
      que.emplace(nstep, v);
    }
  }
  if (visit[3 * T] == INT_MAX)
    cout << -1 << endl;
  else
    cout << visit[3 * T] / 3 << endl;
  return 0;
}


Measured memory_bytes: 20936
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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; }

ll MOD = 1000000007;
ll INF =1<<30;
ll dp[110][100100];
int main(){
    int ans = 0;
    string s,t;
    cin >> s>>t;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans ++;
    }
    cout << ans <<endl;
}


Measured memory_bytes: 3816
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 1e5 + 5;

int n, ans, id;
int a[maxn];
vector<pii> vec;

int main(){
	scanf("%d", &n);
	FOR(i, 0, n)
		scanf("%d", a + i);
	sort(a, a + n);
	id = lower_bound(a, a + n, 0) - a;
	if(id == n){
		FOR(i, 0, n - 1){
			vec.PB(MP(a[n - 1], a[i]));
			a[n - 1] -= a[i];
		}
		printf("%d\n", a[n - 1]);
		FOR(i, 0, vec.size())
			printf("%d %d\n", vec[i].fst, vec[i].snd);
		return 0;
	}
	id -= 1;
	if(id == -1)
		id = 0;
	FOR(i, id + 1, n - 1){
		vec.PB(MP(a[id], a[i]));
		a[id] -= a[i];
	}
	REP(i, 0, id){
		vec.PB(MP(a[n - 1], a[i]));
		a[n - 1] -= a[i];
	}
	printf("%d\n", a[n - 1]);
	FOR(i, 0, vec.size()) printf("%d %d\n", vec[i].fst, vec[i].snd);
	return 0;
}



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
/*bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;
}*/

ll countSum(ll x)
{
    ll res = 0;
    while (x != 0)
    {
        res += (x % 10);
        x /= 10;
    }
    return res;
}
int used[1111111];
int main()
{
    fast ;
ll a,b;
cin  >> a>>b;
if(a>9||b>9)
 cout <<-1<<endl;
else 
cout << a*b<<endl;
   }




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

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)
#define SP(i)			fixed << setprecision(i) 

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

ll n;
double arr[3005];
double dp[3005][3005];
bool vis[3005][3005];

double find(ll n,ll k){
	if (k>n)return 0;
	if (n==0 && k==0)return (double)1;
	if (k<0)return (double)0;
	if (vis[n][k])return dp[n][k];
	vis[n][k]=1;
	dp[n][k]=((double)find(n-1,k-1)*arr[n-1])+(double)(find(n-1,k)*(1-arr[n-1]));
	return dp[n][k];
}

void solve() {
    cin>>n;
    rep(i,0,n)cin>>arr[i];
    double ans=0;
    rep(i,n/2+1,n+1){
    	ans+=(double)find(n,i);
    	cout<<endl;
    }
    cout<<SP(10)<<ans<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 79232
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
    }
    a.sort();
    a.reverse();
    let ans = (0..n - 1).map(|k| a[(k + 1) / 2]).sum::<usize>();
    println!("{}", ans);
}


Measured memory_bytes: 6240
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int sx,sy,gx,gy;cin >> sx >> sy >> gx >> gy;
    string ans;
    rep(i,gy- sy){
        ans += 'U';
    }
    rep(i,gx-sx){
        ans += 'R';
    }
    rep(i,gy-sy){
        ans += 'D';
    }
    rep(i,gx-sx){
        ans += 'L';
    }
    ans += 'L';
    rep(i,gy-sy+1){
        ans += 'U';
    }
    rep(i,gx-sx+1){
        ans += 'R';
    }
    ans += 'D';
    ans += 'R';
    rep(i,gy- sy+1){
        ans += 'D';
    }
    rep(i,gx-sx+1){
        ans += 'L';
    }
    ans += 'U';
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;




int main()
{
	ios_base::sync_with_stdio(false);


	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int ans = 0;
	while (k--)
		ans += a[k];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3676
// #include<iostream>
// #include<cstdio>
// #include<algorithm>
// #include<cmath>
// #include<vector>
// #include<map>
// #include<set>
// #include<string>
// #include<queue>
// #include<stack>
// using namespace std;
// #define MOD 1000000007
// #define INF (1<<29)
// #define LINF (1LL<<60)
// #define EPS (1e-10)
// typedef long long Int;
// typedef pair<Int, Int> P;

// Int h, w, a[88][88], b[88][88];

// bool dp[88][88][25600];

// int main(){
//     cin >> h >> w;
//     for(int i = 0;i < h;i++){
//         for(int j = 0;j < w;j++){
//             cin >> a[i][j];
//         }
//     }
//     for(int i = 0;i < h;i++){
//         for(int j = 0;j < w;j++){
//             cin >> b[i][j];
//             a[i][j] -= b[i][j];
//         }
//     }
//     dp[0][0][a[0][0] + 12800] = true;
//     for(int i = 0;i < h;i++){
//         for(int j = 0;j < w;j++){
//             for(int k = 0;k < 25600;k++){
//                 if(!dp[i][j][k])continue;
//                 if(i+1 < h){
//                     dp[i+1][j][k+a[i+1][j]] = true;
//                     dp[i+1][j][k-a[i+1][j]] = true;
//                 }
//                 if(j+1 < w){
//                     dp[i][j+1][k+a[i][j+1]] = true;
//                     dp[i][j+1][k-a[i][j+1]] = true;
//                 }
//             }
//         }
//     }
//     int ans = 2560000;
//     for(int i = 0;i < 25600;i++){
//         if(dp[h-1][w-1][i]){
//             ans = min(ans, abs(i - 12800));
//         }
//     }
//     cout << ans << endl;

//     return 0;
// }

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MOD = 1000000007;
bitset<12805> X[80][80];
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<vector<int> > A(H, vector<int>(W));
    vector<vector<int> > B(H, vector<int>(W));
    int res = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> B[i][j];
        }
    }
    int C = 12805 / 2;
    X[0][0][C + A[0][0] - B[0][0]] = 1;
    X[0][0][C - A[0][0] + B[0][0]] = 1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int diff = abs(A[i][j] - B[i][j]);
            if (i > 0) {
                X[i][j] |= (X[i - 1][j] << diff);
                X[i][j] |= (X[i - 1][j] >> diff);
            }
            if (j > 0) {
                X[i][j] |= (X[i][j - 1] << diff);
                X[i][j] |= (X[i][j - 1] >> diff);
            }
        }
    }
    res = 12805;
    for (int i = 0; i < 12805; i++) {
        if (X[H - 1][W - 1][i]) {
            res = min(res, abs(i - C));
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 10368
#include<stdio.h>
int main(void){
  char s[4];
  int i;
  int ct=0;
  
  for(i=1;i<=3;i++){
    scanf("%c",&s[i]);
  }
  
  for(i=1;i<=3;i++){
    if(s[i]=='1')ct++;
  }
  
  printf("%d\n",ct);
    
  return 0;  
}

Measured memory_bytes: 1664
use std::cmp::max;
use std::error::Error;
use std::io;

fn main() {
    if let Err(_e) = run() {};
}

// it's 1.15 in atcoder, we can't use dyn
fn run() -> Result<(), Box<Error>> {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer)?;
    buffer.trim().parse::<usize>()?;

    buffer.clear();
    io::stdin().read_line(&mut buffer)?;

    let inputs = buffer.trim()
        .split_whitespace()
        .map(|a| a.trim().parse::<i64>())
        .fold(Vec::new(), |mut v, a| {
            v.push(a.unwrap());
            v
        });
    let mut dp = vec![vec![-1 as i64; inputs.len()]; inputs.len()];
    println!("{}", calculate(&inputs, &mut dp, 0, inputs.len() - 1));
    return Ok(());
}

fn calculate(inputs: &Vec<i64>, dp: &mut Vec<Vec<i64>>, from: usize, to: usize) -> i64 {
    if dp[from][to] != -1 {
        return dp[from][to];
    }

    if from == to {
        dp[from][to] = inputs[from];
        return inputs[from];
    }
    let first = inputs[from] - calculate(inputs, dp, from + 1, to);
    let last = inputs[to] - calculate(inputs, dp, from, to - 1);

    dp[from][to] = max(first, last);
    return dp[from][to];
}


Measured memory_bytes: 90492
from collections import Counter

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = sum(a)
    cum = [0]* (n+1)
    for i in range(n):
        cum[i+1] = cum[i] + a[i]
    print(min(abs(2 * i - s) for i in cum))

main()


Measured memory_bytes: 27652
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    S = input()

    weeks = ['SUN','MON','TUE','WED','THU','FRI','SAT']
    for i in range(len(weeks)):
        if weeks[i] == S:
            print(7-i)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 62068
#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 N, M; cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }

  int total = 0;
  for (int i = 0; i < M; i++) {
    total += A[i];
  }

  int result = N - total;

  cout << (result < 0 ? -1 : result) << endl;
  return 0;
}

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

const int MAX = 10001000;
bool IsPrime[MAX];
vector<int> Era(int n = MAX) {
    vector<int> res;
	IsPrime[0] = false; IsPrime[1] = false; 
	for (int i = 2; i < n; ++i) IsPrime[i] = true;
	for (int i = 2; i < n; ++i) {
		if (IsPrime[i]) {
            res.push_back(i);
			for (int j = i*2; j < n; j += i) IsPrime[j] = false;
		}
	}
    return res;
}

int main() {
  Era();
  long long N;
  while (cin >> N) {
	if (N == 0) break;
	int prev = N, next = N;
	while (!IsPrime[prev]) --prev;
	while (!IsPrime[next]) ++next;
	cout << next - prev << endl;
  }
}



Measured memory_bytes: 16556
s = input()

start,end = 0,0
for i in range(len(s)):
    if s[i] == 'A':
        start = i
        break
for i in range(1,len(s)):
    t = -i
    if s[t] == 'Z':
        end = t+1
        break

ans = len(s) + end - start
print(ans)

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

#define maxn 400005
#define mod 998244353

typedef pair<int, int> P;

int n;
string s;
int cnt = 0;

void dfs(int now, int t, int _max)
{
    if (now == t)
    {
        cout << s << endl;
        //cnt++;
        return;
    }
    for (int i = 0; i <= _max + 1; i++)
    {
        s.push_back('a' + i);
        dfs(now + 1, t, max(_max, i));
        s.pop_back();
    }
}

int main()
{
    cin >> n;
    s.push_back('a');
    dfs(1, n, 0);
    //cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1536
n = int(input())
a1 = list(int(i) for i in input().split())
a2 = list(int(i) for i in input().split())

m = 0
for i in range(1,n+1):
    c = 0
    for k in range(0,i):
        c += a1[k]
    for l in range(i-1,n):
        c  += a2[l]
    if c > m:
        m = c
print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int inf = (int) 1e18;
const int N = 22;

int dp[N][1111];
int c[N];
int p[N];

int solve(int i, int probs) {
  if (i == 0) {
    if (probs > p[0]) {
      return -inf;
    } else {
      return probs * 100 + c[i] * (probs == p[0]);
    }
  }
  int& res = dp[i][probs];
  if (res != -1) {
    return res;
  }
  res = -inf;
  for (int j = 0; j <= p[i]; ++j) {
    if (probs < j) {
      break;
    }
    res = max(res, solve(i - 1, probs - j) + j * 100 * (i + 1) + (j == p[i]) * c[i]);
  }
  return res;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, G;
  cin >> n >> G;
  int total = 0;
  for (int i = 0; i < n; ++i) {
    cin >> p[i] >> c[i];
    total += p[i];
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= total; ++i) {
    if (solve(n - 1, i) >= G) {
      cout << i << '\n';
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
#include<numeric>
#include<limits>
#include<type_traits>
using namespace std;

static const int MAX_N = 1010;
static const int MAX_NM = 1000010;
long long int grid[MAX_NM];//使ってないので無視してください。
long long int A[MAX_N], B[MAX_N];

int main(void){
  int N, M, cnt_a = 0, cnt_b = 0;
  long long int ans = 1;
  long long int MODP = 1000000007;
  cin >> N >> M;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  for(int i = 0; i < M; i++){
    cin >> B[i];
  }
  for(int i = 0; i < M*N; i++){
    grid[i] = 0;
  }
  sort(A, A + N, greater<long long int>());
  sort(B, B + M, greater<long long int>());
  for(int i = N*M; i > 0; i--){
    if(A[cnt_a] == i){
      if(B[cnt_b] == i){
        ans *= 1;
        cnt_a++;
        cnt_b++;
        ans %= MODP;
      }
      else{
        ans *= cnt_b;
        ans %= MODP;
        cnt_a++;
      }
    }
    else{
      if(B[cnt_b] == i){
        ans *= cnt_a;
        ans %= MODP;
        cnt_b++;
      }
      else{
        ans *= cnt_a * cnt_b - N*M + i;
        ans %= MODP;
      }
    }
    //cout << i << " " << cnt_a << " " << cnt_b << " " << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
    int N;
    cin >> N;
    bool A = false;
    for(int i = 1;i < 10;i++) {
        for(int j = 1;j < 10;j++) {
            if(i * j == N) {
                A = true;
            }
        }
    }
    if(A == true) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <queue>
using namespace std;

int main(void)
{
	int n;
	stack<int> in;
	queue<int> out;

	while(cin >> n)
	{
		if(n == 0)
		{
			out.push(in.top());
			in.pop();
		}
		else
			in.push(n);
	}

	while(!out.empty())
	{
		cout << out.front() << endl;
		out.pop(); 
	}

	return 0;
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, k;
	cin >> n >> k;

	ll res = 0;
	for (ll i = k; i <= n + 1; i++) {
		ll be = i * (i - 1) / 2;
		ll en = i * (2 * n - i + 1) / 2;
		res = (res + (en - be + 1)) % mod;
	}

	out(res);

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; cin >>N;
  vector<int> h(N); rep(i, N) cin >>h[i];
  vector<int> dp(N, inf);
  dp[0] = 0;
  for (int i=0; i<N; i++){
    if (i+1 < N) chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    if (i+2 < N) chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
  }
  int res = dp[N-1];
  cout <<res <<endl;
}


Measured memory_bytes: 1024
<?php
// Your code here!
$array = range('a', 'z');
// var_dump($array);

$line = trim(fgets(STDIN));
for ($i = 0; $i < count($array); $i++) {
    if ($line == $array[$i]) {
        echo $array[$i + 1];
        break;
    }
}
?>

Measured memory_bytes: 4728
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = list(s())
num = 0
for i in N:
    num = (num+int(i))%9
if num == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11564
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define MAXX 500005
#define PI 3.14159265358979323846264338327950
#define F first
#define S second
#define ll   int
#define mod  1000000007



int main()
{
	FAST;
	string s;
	cin >> s;
	ll x = 0;
	for(ll i = 0; i < s.size(); i ++){
		if(s[i] == 'x'){
			x ++;
		}
		
	}
	if(x >= 8){
		cout << "NO";
	}
	else{
		cout << "YES";
	}
}

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

using namespace std;

int main(){

int n, k;	 cin>>n>>k;
int arr[n];
for(int i=0; i<n; i++)cin>>arr[i];

sort(arr, arr+n);

int sum=0;

for(int i=0; i<k; i++)sum+=arr[i];

cout<<sum<<endl;

return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
int test[123][123];
signed main() {
	int ans = 0; double n, m, a, b; char s, t; cin >> n >> m;
	for (int h = 0; h < n; h++) {
		for (int i = 0; i < m; i++) {
			cin >> a; test[h][i] = a;
		}
	}
	for (int h = 0; h < n - 1; h++) {
		for (int i = h + 1; i < n; i++) {
			int c = 0; double d = 0;
			for (int j = 0; j < m; j++) {
				c += abs(test[h][j] - test[i][j]) * abs(test[h][j] - test[i][j]);
				d += abs(test[h][j] - test[i][j]) * abs(test[h][j] - test[i][j]);
			}
			c = sqrt(c); d = sqrt(d);
			if (c == d) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int (input ())
t2 = 0
x2 = 0
y2 = 0
ans = 'Yes'
for i in range (N):
    t,x,y = map(int, input().split())
    if abs(x+y-x2-y2) <= t-t2:
        if ((abs(x2+y2-x-y))-(t-t2)) % 2 == 1:
            ans = 'No'
            break
    else:
        ans = 'No'
        break
    t2 = t
    x2 = x
    y2 = y
print (ans)

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

string s, t;
int main() {
    while (cin >> s >> t) {
        bool ok = false;
        for (int i = 0; i < s.size(); ++i) {
            string ss = s.substr(1) + s[0];
            if (ss == t) ok = true;
            s = ss;
        }
        if (ok) puts("Yes");
        else puts("No");
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    static long mod = 1000000000+7;
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] A = new int[N];
        for(int i = 0; i < N; i++)
            A[i] = sc.nextInt();
        sc.close();

        long[][] cnt = new long[2][N];
        long[][] s = new long[2][N];
        for(int i = 0; i < N; i++){
            for(int j = i+1; j < N; j++){
                if(A[i] > A[j])
                    cnt[0][i]++;
            }
            for(int j = 0; j < N; j++){
                if(A[i] > A[j])
                    cnt[1][i]++;
            }
            if(i != 0){
                s[0][i] = s[0][i-1] + cnt[0][i];
                s[1][i] = s[1][i-1] + cnt[1][i];
            } else {
                s[0][i] = cnt[0][i];
                s[1][i] = cnt[1][i];
            }
        }

        long ans = 0;
        ans = (s[0][N-1]*K%mod + K*(K-1)/2%mod*s[1][N-1]%mod)%mod;
        System.out.println(ans);
   }
}

Measured memory_bytes: 26224
#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 <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define rep(i,N) for(int i=0;i<(int)N;++i)

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

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

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

    vector<int> c(N);
    vector<int> t(N);

    rep(i, N) cin >> c[i] >> t[i];

    int m = 1001;

    rep(i, N) {
        if (t[i] <= T) {
            if (c[i] <= m) { m = c[i]; }
        }
    }

    if (m == 1001) { cout << "TLE" << endl; }
    else { cout << m << endl; }

}

Measured memory_bytes: 256
#include<iostream>
using namespace std ;
#define ll long long int
#include<map>

int main()
{

ll n ; cin>> n ;
map<string ,  ll >  arr;

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

     string s ;
     cin>>s ;
     arr[s]++ ;
 }


cout<<"AC x "<<arr["AC" ] <<endl  ;
cout<<"WA x "<<arr["WA" ] <<endl  ;
cout<<"TLE x "<<arr["TLE" ] <<endl  ;

cout<<"RE x "<<arr["RE" ] <<endl  ;


}


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

using namespace std;

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

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

    sort(a.begin(), a.end(), greater<int>());

    int alice = 0;
    int bob = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0)
            alice += a[i];
        else
            bob += a[i];
    }

    cout << alice - bob << '\n';
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> p(n);
  for (int i=0; i<n; i++){
    cin >> p.at(i);
  }
  int counter1 = 0;
  int counter2 = 0;
  int counter3 = 0;
  for (int i=0; i<n; i++){
    if (p.at(i) < a+1){
      counter1++;
    }
    else if (p.at(i) > a && p.at(i) < b+1){
      counter2++;
    }
    else if (p.at(i) > b){
      counter3++;
    }
  }
  int minimum = min(counter1, counter2);
  int ans = min(minimum, counter3);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256