akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long int N, M, K, H, W, L, R;
 
int a[50], b[50], c[50], d[50];
 void Search(vector<int>&v) {  
	if (v.size() == N) {
		long long int ans = 0;
		for (int i = 0; i < K; i++) {
			if (v[b[i]] - v[a[i]] == c[i])ans += d[i];
		}
		L = max(L, ans);
		return;
	}
	int st = 1;
	if (v.size())st = v.back();
	for (int i = st; i <= M; i++) {
		v.push_back(i);
		Search(v);
		v.pop_back();
	}
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N >> M >> K;
	for (int i = 0; i < K; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--, b[i]--;
	}
	vector<int>v;
	Search(v);
	cout << L << endl;
}

Measured memory_bytes: 3672
def solve(N, K):
    # N <= 10^5
    if K == 0:
        return N * N
    cnt = 0
    for b in range(K, N+1):
        q, r = divmod(N, b)
        cnt += max(0, b-K) * q + max(0, r - K + 1)
    return cnt

assert solve(5, 2) == 7
assert solve(10, 0) == 100
N, K = map(int, input().split())
print(solve(N, K))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<math.h>


using namespace std;


int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

	double dp[n + 1][n + 1];
	for (long long int i = 0; i < n + 1; i++)
		dp[0][i] = 0;
	dp[0][0] = 1;
	for (long long int i = 1; i < n + 1; i++)
	{
		dp[i][0] = dp[i - 1][0] * (1 - arr[i - 1]);
	}

	for (long long int i = 1; i < n + 1; i++)
	{
		for (long long int j = 1; j < n + 1; j++)
		{
			dp[i][j] = dp[i - 1][j - 1] * arr[i - 1] + dp[i - 1][j] * (1 - arr[i - 1]);
		}
	}
	double ans;
	for (int i = (n + 1) / 2; i <= n; i += 1)
		ans += dp[n][i];

	cout << setprecision(11) << ans << endl;

	return 0;


}

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

#define REP(i, a) for(int i=0;i<(int)a;++i)
#define MIN(v) *std::min_element(v.begin(),v.end())
#define MAX(v) *std::max_element(v.begin(),v.end())
#define SUM(v) std::accumulate(v.begin(),v.end(),0)
#define INF 1145141919;
typedef long long ll;
typedef long double ld;
using namespace std;

int n;
int tmp;
int Min = INF;
int Max = -INF;
ll sum = 0;
vector<ll> a;

void solver() {
    cin >> n;
    REP(i, n) {
        cin >> tmp;
        if (Min > tmp)Min = tmp;
        if (Max < tmp)Max = tmp;
        sum += tmp;
    }
    cout << Min << " " << Max << " " << sum << endl;
}

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

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

int main(){
    string s;
    cin>>s;
    ll n = s.size();
    ll x,y;
    for(ll i=0;i<n;++i){
        if(s[i]=='A'){
            x = i+1;
            break;
        }
    }
    for(ll i=0;i<n;++i){
        if(s[n-i-1]=='Z'){
            y = i+1;
            break;
        }
    }
    cout<<n-x-y+2<<endl;
}

Measured memory_bytes: 640
n, T = map(int, input().split())
t = list(map(int, input().split()))
ans = 0

for i in range(n - 1):
	if t[i + 1] - t[i] < T:
		ans += t[i + 1] - t[i]
	else:
		ans += T

ans += T

print(ans)

Measured memory_bytes: 26836
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  double xa,ya,ra,xb,yb,rb,d;
  int n;
  cin >> n;
  while(n--){
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    d = sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
    if(d + rb < ra) cout << "2" << endl;
    else if(d + ra < rb) cout << "-2" << endl;
    else if(d > ra + rb) cout << "0" << endl;
    else cout << "1" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
int main(){
    for(;;){
        int ai,bi,as=0,bs=0,n;
        scanf("%d",&n);
        if(n==0) break;
        for(int i=0;i<n;i++){
            scanf("%d%d",&ai,&bi);
            if(ai>bi) as+=ai+bi;
            else if(ai<bi) bs+=ai+bi;
            else{
                as+=ai;
                bs+=bi;
            }
        }
        printf("%d %d\n",as,bs);
    }
}

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

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  string s, t;
  cin >> s >> t;
  int len = s.length();

  int res = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] != t[i]) {
      res++;
    }
  }

  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 3792
n = gets.to_i
h = gets.split.map(&:to_i)

cnt = 0
ans = 0
(n-1).times do |i|
    if h[i] >= h[i+1]
        cnt += 1
        # p [i,?d]
    else
        ans = cnt if ans < cnt
        cnt = 0
        # p [i, ?a]
    end
end
ans = cnt if ans < cnt

puts ans

Measured memory_bytes: 8580
#include<iostream>

using namespace std;

bool isPrime (int x) {
    for(int i=2; i*i<=x; i++) {
        if(x%i==0) return false;
    }
    return true;
}

int N;
int main () {
    cin >> N;
    long long int ans = 1;
    int mod = 1000000007;
    for(int i=2; i<=N; i++) {
        if(isPrime(i)) {
            int ret = 1;
            for(int j=N; j/=i; ret+=j);
            ans = ans * ret  % mod;

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


Measured memory_bytes: 256
S = input()
T = input()
ST = {}
TS = {}
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s in ST:
        if ST[s] != t:
            print("No")
            break
    else:
        ST[s] = t
    if t in TS:
        if TS[t] != s:
            print("No")
            break
    else:
        TS[t] = s
else:
    print("Yes")


Measured memory_bytes: 3632
A,B,M = map(int,input().split())
a = input().split()
b = input().split()
L = []
for i in range(M):
    l = input().split()
    L.insert(i,l)
sum_min = int(min(a)) + int(min(b))  

P = []
for i in range(M):
    p = int(a[int(L[i][0])-1]) + int(b[int(L[i][1])-1]) - int(L[i][2])
    P.append(p)
pmin = min(P)
    
if pmin < sum_min:
        ans = pmin
else:
    ans = sum_min
print(ans)

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

namespace ConsoleApp15
{
    class Class233
    {
        static void Main()
        {
            string S = Console.ReadLine();
            int ans = -1;
            for(int  i = 0; i < (1<<S.Length-1); i++)
            {
                long sum = long.Parse(S[0].ToString());
                for(int j = 0; j < S.Length - 1; j++)
                {
                    long r = long.Parse(S[j+1].ToString());
                    if ((i & (1 << j)) > 0)
                    {
                        sum += r;
                    }
                    else
                    {
                        sum -= r;
                    }
                }
                
                if (sum == 7)
                {
                    ans = i;
                    break;
                }
            }

            if (ans == -1)
            {
                Console.WriteLine("-1");
            }
            else
            {
                string res = "";
                for(int i = 0; i < S.Length - 1; i++)
                {
                    res += S[i];
                    if ((ans & (1 << i)) > 0) res += "+";
                    else res += "-";
                }
                res += S.Last().ToString() + "=7";
                Console.WriteLine(res);
            }
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<algorithm>
using namespace std;
long long n, x[1 << 20], t, p = 1;
int main() {
	cin >> n >> t;
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}
	sort(x, x + n);
	for (int i = 0; i < n; i++)
	{
		long long s = 0;
		for (int j = i; j >= 0; j--)
		{
			if (x[i] - x[j] > t) { break; }
			s++;
		}
		p *= s;
		p %= 1000000007;
	}
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 1956
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  uli a,b,c,d,n;
  cin>>a>>b>>c>>d>>n;
  c=min(c,b+b);
  c=min(c,a+a+a+a);
  if(c+c<=d)cout<<c*n<<endl;
  else{
    cout<<(n/2)*d+(n%2)*c<<endl;
  }
  return 0;
}


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

int main(){
  int N, K, l;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    
    if (x > K - x)
      l += 2 * (K - x);
    else
      l += 2 * x;
  }
  cout << l << endl;
}


Measured memory_bytes: 256
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n,a = map(int,ipt().split())
    x = [int(i) for i in ipt().split()]

    dpp = [0]*2501
    dpm = [0]*2501
    zeros = 0
    dpp[0] = 1
    dpm[0] = 1
    for i in x:
        if a > i:
            d = a-i
            for j in range(2500,d-1,-1):
                dpp[j] += dpp[j-d]
        elif a < i:
            d = i-a
            for j in range(2500,d-1,-1):
                dpm[j] += dpm[j-d]
        else:
            zeros += 1
    ans = 0
    for i in range(2501):
        ans += dpp[i]*dpm[i]
    ans *= 2**zeros
    print(ans-1)
    return None

if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  vector<tuple<string,int,int>> a;
  
  for(int i = 1; i <= n; i++) {
  	string s;
  	int p;
  	cin >> s >> p;
    p = -p;
  	a.push_back(tie(s,p,i));
  	}
  
  sort(a.begin(),a.end());
  
  for(int i = 0; i < n; i++) {
  	cout << get<2>(a.at(i)) << endl;
  }
}


Measured memory_bytes: 256
s = int(input())
flag = [0] * 1000001
flag[s] = 1
for i in range(1, 1000001):
    if s % 2:
        s = 3 * s + 1
    else:
        s = s // 2
    if flag[s]:
        print(i+1)
        break
    flag[s] = 1

Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int fib(int a){
    int b=0;
    if(a==1){
        return 1;
    }
  else if(a==2){
    return 2;
  }
    else{
        b=+(fib(a-1)+fib(a-2));
        return b;
    }
}
int main(){
  ll n,l;
  cin>>n>>l;
  if(l>=0)cout<<(n-1)*l+n*(n-1)/2<<endl;
  else {
    if(-l>=n)cout<<(n-1)*l+n*(n-1)/2-n+1<<endl;
    else cout<<(n-1)*l+n*(n-1)/2+l<<endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void)
{
  double r;
  double area, length;
  
  scanf("%lf", &r);
  
  area = 3.141592653589 * r * r;
  length = 2 * 3.141592653589 * r;
  
  printf("%f %f\n", area, length);
  
  

  
  return 0;
}


Measured memory_bytes: 2068
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n;
    cin >> n;
    if (n<1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
    
    //cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

bool check(int e, int b , int c){
	return e+b > c && e+c > b && b+c > e && e != b && b !=c && c != e;
}

int32_t main(){
	IOS;
	int n;
	cin >> n;
	int a[n+1];
	for(auto i =0; i<n; ++i){
		cin >> a[i];
	}
	int cnt =0;
	for(int i =0; i<n-2; ++i){
		for(int j = i+1; j<n-1; ++j){
			for(int k = j+1; k<n; ++k){
				if(check(a[i] , a[j] , a[k])){
						cnt++;
				}
			}
		}
	}
	cout << cnt;
	return 0;
}



Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n, x, t;
    cin >> n >> x >> t;
    cout << ((n - 1 + x) / x) * t << endl;
    return 0;
}


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


int32_t main(){
	int n;
	vector<int> v(4);
	for(int i = 0 ; i < 4 ; i ++) cin>>v[i];
	sort(v.begin() , v.end());
	if(v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;	
}

Measured memory_bytes: 764
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

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

using namespace std;

void solution()
{
    int n;
    cin >> n;
    int count = 0;
    rep(i,n){
        int d1, d2;
        cin >> d1 >> d2;
        count = d1 != d2 ? 0 : count + 1;
        if(count == 3){
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const int  MOD = 1000000007;
int main(){
    long long n,k; cin >> n >> k;
    long long ans=0;
    for(long long j=k;j<=n+1;++j){
        ans += (-j*j + (n+1)*j +1)%MOD;
        ans%=MOD;
    }
    cout << ans%MOD << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

typedef long long ll;

template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  x = 1; y = 0;
  T g = 1, e = 0;
  while (b != 0) {
    T q = a/b, r = a%b;
    T m = x-q*e, n = y-q*g;
    a = b; b = r;
    x = e; e = m;
    y = g; g = n;
  }
  return g;
}

int main() {
  int a, b, x, y;

  cin >> a >> b;

  extgcd(a, b, x, y); 

  cout << x << " " << y << endl;

  return 0;
}


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

const int m = 1000005;

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  vector<int> can(m);
  for(int x : a){
    if(can[x] != 0){
      can[x] = 2;
      continue;
    }
    for(int i = x; i < m; i += x) can[i] ++;
  }
  int cnt = 0;
  for(int x : a){
    if(can[x] == 1) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 8012
#include<stdio.h>

// This function behave as Outpuetter.
void trace(int A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(void){
  int len, i, j;
  scanf("%d", &len);
  int a[len];

  // input data.
  for (i=0;i<len;i++) scanf("%d", &a[i]);

  int tmp;
  for(i=0;i<len;i++){
    tmp = a[i];
    j = i;
    while(j>0 && a[j-1]>tmp){
      a[j] = a[j-1];
      j--;
    }
    a[j] = tmp;
    trace(a, len);
  }
  return 0;
}



Measured memory_bytes: 2052
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p2=sorted(p,reverse=True)
q2=sorted(q,reverse=True)
r2=sorted(r,reverse=True)

d=[]
for i in range(x):
    d.append(p2[i])
for i in range(y):
    d.append(q2[i])
for i in r2:
    d.append(i)
e=sorted(d,reverse=True)
f=0
for i in range(x+y):
    f+=e[i]
print(f)

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

int a[7],c[7];
int e=0;

void move(char i){
int b[7];
for(int n=1;n<7;n++){b[n]=a[n];}

if(i=='W'){
a[6]=b[4];
a[4]=b[1];
a[1]=b[3];
a[3]=b[6];
}

if(i=='N'){
a[6]=b[5];
a[5]=b[1];
a[1]=b[2];
a[2]=b[6];
}

if(i=='E'){
a[6]=b[3];
a[3]=b[1];
a[1]=b[4];
a[4]=b[6];
}

if(i=='S'){
a[6]=b[2];
a[2]=b[1];
a[1]=b[5];
a[5]=b[6];
}

if(i=='R'){
a[3]=b[2];
a[2]=b[4];
a[4]=b[5];
a[5]=b[3];
}}



void move2(int r){
if(r==2){move('N');}
if(r==3){move('W');}
if(r==4){move('E');}
if(r==5){move('S');}
if(r==6){move('N'); move('N');}
}



void right(){
for(int l=1;l<7;l++){
if(l==6 && a[l]==c[l]){e=1;}
if(a[l]==c[l]){continue;}
break;
}}




int main(){
int da[7];
for(int h=1;h<7;h++){cin>>a[h]; da[h]=a[h];}
for(int h=1;h<7;h++){cin>>c[h];}

for(int g=1;g<=7;g++){
for(int n=0;n<=4;n++){

right();

if(e==1){break;}
move('R');
}
if(e==1){break;}
for(int h=1;h<7;h++){a[h]=da[h];}
move2(g);
}

if(e==1){cout<<"Yes"<<endl;}
if(e==0){cout<<"No"<<endl;}

return 0;
}


Measured memory_bytes: 3096
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <cmath>
#include <set>

#define rep(i,n) for (int i = 0; i < n; ++i)
#define repr(i,n) for (int i = n; i > 0; --i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MAX = 100;
const int INF = (1<<12);

int main() {
  int D, T, S;
  cin >> D >> T >> S;
  string ans = D <= T*S ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}

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

void solve() {
	int n, x, t; cin >> n >> x >> t;
	int cnt = n / x + (n % x != 0);
	cout << cnt*t;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 3652
S = input()
n = len(S)

left = [0]*(n+1)
right = [0]*(n+1)

for i in range(n):
    if S[i] == '<':
        left[i+1] = left[i] + 1
for i in range(n):
    if S[n-i-1] == '>':
        right[n-i-1] = right[n-i] + 1

answer = 0
for l, r in zip(left, right):
    answer += max(l, r)

print(answer)


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

using namespace std;

int main(){
	int N, K;
	while(cin >> N >> K){
		vector<int> A(N);
		for(int i=0;i<N;i++){
			cin >> A[i];
		}
		cout << (N-1+(K-2))/(K-1) << endl;
	}
}

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

namespace MyProgram
{
    public class Program
    {	
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            bool ok = true;
            
            List<string> list = new List<string>();
            string s1 = Console.ReadLine();
            list.Add(s1);
            string s2 = "";
            for(int i = 1; i < n ; i++)
            {
                s2 = Console.ReadLine();
                if(s1[s1.Length-1] != s2[0]) ok = false;
                if(list.Contains(s2)) ok = false;
                list.Add(s2);
                s1 = s2;
            }
            
            if(ok) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13024
#include<iostream>
#include<cstdio>
using namespace std;
int n,i,f;
int main()
{
	cin>>n;
	for(i=1;i<=n;i*=2)
	  if(i==n)  {f=1;break;}
	if(!f)
	  cout<<i/2<<endl;
	else  cout<<i<<endl;
	return 0;
}

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

int main() {
	int sub[7];
	int a, b;
	
	for(int i = 0; i < 7; i++){
		cin >> a >> b;
		sub[i] = a - b;
	}
	
	for(int i = 0; i < 7; i++){
		cout << sub[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, t;
    cin >> n >> t;
    vpair f(n);
    rep(i, n) cin >> f[i].fi >> f[i].se;
    sort(all(f));

    int ans = 0;
    vvint dp(n+1, vint(t, 0));
    rep(i, n) {
        rep(j, t) {
            dp[i+1][j] = dp[i][j];
            ans = max(ans, dp[i+1][j] + f[i].se);
            if (j-f[i].fi < 0) continue; 
            dp[i+1][j] = max(dp[i][j], dp[i][j-f[i].fi] + f[i].se);
        }
    }

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

Measured memory_bytes: 35584
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

ll f(ll x){
  if(x%4==0) return x;
  if(x%4==2) return x+1;
  if(x%4==1) return 1;
  if(x%4==3) return 0;
}

int main(){
  ll a,b; cin >> a >> b;
  ll ans=f(a-1)^f(b);
  cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

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

    let mut map: HashMap<usize, Vec<(usize, usize)>> = HashMap::new();
    
    for (i, py) in py_vec.into_iter().enumerate() {
        map.entry(py.0).or_insert(vec![]).push((py.1, i));
    }

    let mut ans_vec: Vec<String> = vec!["".to_string(); m];

    for (k, v) in map.into_iter() {
        let num_1 = format!("{:06}", k);
        let mut mv = v;
        mv.sort_by_key(|x| x.0);
        for (i, vv) in mv.iter().enumerate() {
            let num_2 = format!("{:06}", i+1);
            ans_vec[vv.1] = format!("{}{}", num_1, num_2);
        }
    }
    println!("{}", ans_vec.iter().join("\n"))
}


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

int main() {
    long long N;
    cin >> N;
    string res;
    while (N > 0) {
        N -= 1;
        res += char(N % 26 + 'a');
        N /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>

using namespace std;

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

  int a=(S[0]-'0')*10+(S[1]-'0'),b=(S[2]-'0')*10+(S[3]-'0');

  if((a<13&&a>0)&&(b<13&&b>0)) cout<<"AMBIGUOUS"<<endl;
  else if(a<13&&a>0) cout<<"MMYY"<<endl;
  else if(b<13&&b>0) cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
  return 0;
} 


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
const double pi = acos(-1) ;
signed main(){
    fastio
    int n ;
    cin >> n ;
    vector<int> ans(n) ;
    for(int i = 1; i < n; i++){
        int x ;
        cin >> x ;
        x--;
        ans[x]++ ;
    }
    for(int &c : ans){
        cout << c << endl;
    }
    return 0; 
}

Measured memory_bytes: 4780
#include <stdio.h>

int main(void){

  char inputs[6], tmp[51];
  int inputs_shuffle[51][2], inputs_nr[2], stack[52];
  int loop1, loop2, loop3;

  while(1){
    inputs_nr[0] = '\0';
    inputs_nr[1] = '\0';
    
    for(loop1 = 0; loop1 < 51; loop1++){
      inputs_shuffle[loop1][0] = '\0';
      inputs_shuffle[loop1][1] = '\0';
    }
    for(loop1 = 0; loop1 < 52; loop1++){
      stack[loop1] = '\0';
    }


    while((inputs_nr[0] == '\0') || (inputs_nr[1] == '\0')){ // get <n r>
      //      printf("input 'n r'\n");
      scanf("%d %d", &loop1, &loop2);
      
      inputs_nr[0] = loop1;
      inputs_nr[1] = loop2;
      
    if((inputs_nr[0] == 0) && (inputs_nr[1] == 0)) break;    
      
      if((inputs_nr[0] < 1) || (inputs_nr[0] > 50)){
	//	printf("<n> must be more than 1 and less than 50.\n");
	inputs_nr[0] = '\0';      // 1 <= n <= 50
	inputs_nr[1] = '\0';
      }
      
      if((inputs_nr[1] < 1) || (inputs_nr[1] > 50)){
	//	printf("<r> must be more than 1 and less than 50.\n");
	inputs_nr[1] = '\0';      // 1 <= r <= 50
	inputs_nr[0] = '\0';
      }


    }
    
    if((inputs_nr[0] == 0) && (inputs_nr[1] == 0)) break;    
    
    
    for(loop1 = 0; loop1 < inputs_nr[1]; loop1++){  // get <p c>
      
      //      printf("input 'p c'[%d]\n", loop1 + 1);
      scanf("%d %d", &loop2, &loop3);
      
      inputs_shuffle[loop1][0] = loop2;
      inputs_shuffle[loop1][1] = loop3;
      
      
      if((inputs_shuffle[loop1][0] + inputs_shuffle[loop1][1]) > (inputs_nr[0] + 1)){
	//	printf("(p + c) must be less than (%d + 1)\n", inputs_nr[0]);
	loop1--;   //  (p + c) must be less than (n + 1).
      }
      else if((inputs_shuffle[loop1][0] == 0) && (inputs_shuffle[loop1][1] == 0)){
	break;     //  if ((p == 0) && (c == 0)), escape this loop.
      }
    }
    loop1--;
    if((inputs_shuffle[loop1][0] == 0) && (inputs_shuffle[loop1][1] == 0)){
      break;     //  if ((p == 0) && (c == 0)), escape this loop.
    }

    for(loop1 = 0; loop1 < 52; loop1++){  // make the stack
      if(inputs_nr[0] != 0){
	stack[loop1] = inputs_nr[0];
	inputs_nr[0]--;
      }
      else       stack[loop1] = '\0';
    }
    // stack[0], stack[1], stack[2], .......
    //       n ,      n-1,      n-2, .......
    
    loop1 = 0;
    
    while(((inputs_shuffle[loop1][0] != 0) && (inputs_shuffle[loop1][1] != 0)) && loop1 != 51){
      
      for(loop2 = 0; loop2 < (inputs_shuffle[loop1][0] - 1); loop2++){ //
	tmp[loop2] = stack[loop2];
      }
      
      for(loop3 = 0; loop3 < inputs_shuffle[loop1][1]; loop3++, loop2++){
	stack[loop3] = stack[loop2];
      }
      
      for(loop2 = 0; loop2 < (inputs_shuffle[loop1][0] - 1); loop2++, loop3++){
	stack[loop3] = tmp[loop2];
      }
      
      for(loop2 = 0; loop2 < 52; loop2++){
	tmp[loop2] = '\0';
      }
      
      loop1++;
    }
    
    printf("%d\n", stack[0]);
    
  }
  return 0;
  
}

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


int main() {
    int N, D;
    cin >> N >> D;
    long pD;
    pD = pow(D, 2);
    vector<int> x(N);
    vector<int> y(N);
    for (int i = 0; i < N; i++) {
        cin >> x.at(i) >> y.at(i);
    }

    int res = 0;
    long lx, ly;
    for (int i = 0; i < N; i++) {
        lx = pow(x.at(i), 2);
        ly = pow(y.at(i), 2);
        if (lx + ly <= pD) {
            res++;
        }
    }

    cout << res << endl;

}


Measured memory_bytes: 4840
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#include <queue>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    std::string s;
    std::cin >> s;
    std::string ss="";
    rep(i,s.size()){
        if(s[i]=='B'&&ss.size()!=0){
            ss.pop_back();
        }else if(s[i]=='B'){
            continue;
        }else{
            ss.push_back(s[i]);
        }
    }
    std::cout << ss << "\n";
    return 0;
}

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

int main() {
  int N, A[200], flag = 0, count = 0;
  cin >> N;

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

  for(int j = 0; ; ++j) {
    for(int i = 0; i < N; ++i) { 
      flag = 0;
      if( A[i] % 2 == 1 ) {
        break;
      } else {
        A[i] /= 2;
      }
      flag = 1;
    }
    if (flag == 1) {
      count++;
    } else {
      break;
    }
  }
  
  cout << count << endl;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

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

const ll mod = 1000000007;

int main(void)
{
	int n;
	cin >> n;
	vector<vector<P>> g(n);
	rep(i, n) {
		vector<P> v;
		int a;
		cin >> a;
		rep(j, a) {
			int x, y;
			cin >> x >> y;
			x--;
			v.emplace_back(x, y);
		}
		g[i] = v;
	}
	int m = 0;
	for (ll i = 0; i < 1 << n; i++) {
		bool ok = true;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				for (auto e : g[j]) {
					auto f = (i & (1 << e.first)) != 0 ? 1 : 0;
					if (f != e.second) {
						ok = false;
					}
					if (!ok) break;
				}
			}
			if (!ok) break;
		}
		if (ok) {
			int c = 0;
			ll ii = i;
			while (ii != 0) {
				if (ii & 1) c++;
				ii = ii >> 1;
			}
			m = max(m, c);
		}
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int N = in.nextInt();

            boolean include9 = false;
            for (int i = 0; i < 2; i++) {
                include9 |= N % 10 == 9;
                N /= 10;
            }

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

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

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

int main(){
    ll a; string b; cin >> a >> b;
    ll c = (b[0] - '0')*100 + (b[2] - '0')*10 + (b[3] - '0');
    cout << a * c / 100 << endl;
    return 0;
}

Measured memory_bytes: 3616
N, X = map(int, input().split())
ms = [int(input()) for _ in range(N)]
ms.sort()

doughnuts = 0
for d in ms:
  if X >= d:
  	X -= d
  	doughnuts += 1
  else: break
while X >= ms[0]:	  
  X -= ms[0]
  doughnuts += 1

print(doughnuts)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<cctype>


int main(void)
{
	char s[20+2];

	while(scanf("%[A-Za-z]\n", s)==1)
	{
		int ans=1;
		int l=strlen(s);
		int cc=0;

		if(s[0]!='A') ans=0;
		if(isupper(s[1])) ans=0;
		if(isupper(s[l-1])) ans=0;
		for(int i=2;i<l-1;i++)
		{
			if(isupper(s[i]))
			{
				if(s[i]=='C') cc++;
				else ans=0;
			}
		}
		if(cc!=1) ans=0;
		printf("%s\n", ans?"AC":"WA");
	}

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int r;
    cin>>r;
    cout<<3*r*r;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

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

int main(void){
    vector<int> S;
    string _S; cin >> _S;
    for(const auto& s: _S) S.push_back(s - '0');

    int ans1 = 0;
    int ans2 = 0;
    {
        int expected = 0;
        for(int i = 0; i < (int)S.size(); i++){
            if(S[i] != expected) ans1++;
            expected = (expected + 1) % 2;

        }
    }

    {
        int expected = 1;
        for(int i = 0; i < (int)S.size(); i++){
            if(S[i] != expected) ans2++;
            expected = (expected + 1) % 2;
        }
    }
    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 1020
package main

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

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt int

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	m := make(map[string]int)
	for i := 0; i < N; i++ {
		t := read()
		arr := make([]string, len(t))
		for j := 0; j < len(t); j++ {
			arr[j] = string(t[j])
		}
		sort.Sort(sort.StringSlice(arr))
		m[strings.Join(arr, "")]++
	}
	for _, value := range m {
		ans += value * (value - 1) / 2
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []uint64

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 11776
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt() - (i + 1));
        }

        sc.close();

        Collections.sort(list);

        long sum = 0;
        int b = list.get(list.size() / 2);

        for (int i = 0; i < n; i++) {
            sum += Math.abs(list.get(i) - b);
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 92732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 100001;
struct Segment{
  int n;
  vector<ll> tree;
  Segment(int _n){
    n = _n;
    tree.resize(n * 4);
  }

  void update(int in, ll v){
    update(1, 0, n - 1, in, v);
  }
  void update(int in, int l, int r, int i, ll v){
    if(l > i || r < i)return;
    if(l == r){
      tree[in] = v;
      return;
    }
    int m = (l + r) / 2;
    update(2 * in, l, m, i, v);
    update(2 * in + 1, m + 1, r, i, v);
    tree[in] = max(tree[2 * in], tree[2 * in + 1]);
  }
  ll query(int l, int r){
    return query(1, 0, n - 1, l, r);
  }
  ll query(int in, int l, int r, int s, int e){
    if(l > e || r < s)
      return -1;
    if(l >= s && r <= e)
      return tree[in];
    int m = (l + r) / 2;
    return max(query(2 * in, l, m, s, e), query(2 * in + 1, m + 1, r, s, e));
  }
};
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  int h[n + 1];
  int b[n + 1];
  h[0] = 0;
  b[0] = 0;
  for(int i = 1;i <= n;i++)
    cin >> h[i];
  for(int i = 1;i <= n;i++)
    cin >> b[i];
  ll dp[n + 1];
  dp[0] = 0;
  Segment tree(n + 1);
  for(int i = 1;i <= n;i++){
    dp[i] = tree.query(0, h[i]) + b[i];
    tree.update(h[i], dp[i]);
  }
  ll res = 0;
  for(int i = 1;i <= n;i++)
    res = max(res, dp[i]);
  cout << res;
  return 0;
}


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

int main() {
long long n;
cin >> n;
 long long  ans =10e17;
 for(long long i =1;i*i<=n;i++){
    if(n%i!=0)continue;
    long long j = n/i;
    ans = min(ans,i+j-2);
 }
 cout << ans<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
  int64_t n, m;
  cin >> n >> m;
  
  vector<int64_t> a(n);
  for (auto&& aa : a) {
    cin >> aa;
  }

  int64_t loop = 0;
  vector<int64_t> e(m + 1);
  int64_t prev = a[0];
  for (auto i : irange(1L, n)) {
    auto aa = a[i];
    if (a[i] < prev) {
      ++loop;
      e[aa] += a[i] + m - prev;
    } else {
      e[aa] += a[i] - prev;
    }
    prev = aa;
  }
  
  int64_t c = 0;
  int64_t p = 0;
  int64_t l = numeric_limits<int64_t>::min(), l_i = 0;
  for (auto i : irange(1L, m + 1)) {
    if ((a.front() < i && i <= a.back())) {
      p += loop + 1;
    } else if ((a.front() < a.back()) || (a.back() <= a.front() && a.front() < i) || (i <= a.back() && a.back() <= a.front())) {
      p += loop;
    } else {
      p += loop - 1;
    }
    if (p > l) {
      l = p;
      l_i = i;
    }
    p -= e[i];
  }
  
  cerr << l_i << endl;
  
  prev = a[0];
  int64_t ans = 0;
  for (auto i : irange(1L, n)) {
    auto aa = a[i];
    if (prev <= aa) {
      if (prev < l_i && l_i <= aa) {
        ans += 1 + aa - l_i;
      } else {
        ans += aa - prev;
      }
    } else {
      if (prev < l_i) {
        ans += 1 + (aa + m - l_i);
      } else if (l_i <= aa) {
        ans += 1 + (aa - l_i);
      } else {
        ans += aa + m - prev;
      }
    }
    prev = aa;    
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

    int N,K;
    cin>>N>>K;
    COMinit();
    rep(i,K){
        int ans=(COM(N-K+1,i+1)*COM(K-1,i))%MOD;
        cout << ans << endl;
        
    }



}


Measured memory_bytes: 12160
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

if A[0] > B[0]:
    ans += B[0]
    B[0] = 0
else:
    ans += A[0]
    B[0] = B[0] - A[0]

for i in range(1, N):
    if A[i] <= B[i - 1]:
        ans += A[i]
    elif A[i] - B[i - 1] - B[i] >= 0:
        ans += B[i - 1] + B[i]
        B[i] = 0
    elif A[i] - B[i - 1] - B[i] < 0:
        ans += A[i]
        B[i] -= A[i] - B[i - 1]

if A[N] > B[N - 1]:
    ans += B[N - 1]
else:
    ans += A[N]

print(ans)

Measured memory_bytes: 19004
import java.util.*
import kotlin.*

import java.io.InputStream
import java.lang.NumberFormatException
import java.lang.StringBuilder


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = FastScanner()
        val n = sc.nextInt()
        val a = sc.nextLong()
        val b = sc.nextLong()
        val x = Array(n) { sc.nextInt() }
        
        var ans = 0L

        for (i in 0 until n - 1) {
            ans += Math.min(b, (x[i + 1] - x[i]) * a)
        }

        println(ans)
    }
}


class FastScanner {
    companion object {
        val input: InputStream = System.`in`
        val buffer = ByteArray(1024) { 0 }
        fun isPrintableChar(c: Int): Boolean = c in 33..126
    }

    var ptr = 0
    var buflen = 0
    private fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = input.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }

    private fun readByte(): Int = if (hasNextByte()) buffer[ptr++].toInt() else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b)
            b = readByte()
        }
        return sb.toString()
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextDouble(): Double = next().toDouble()
}


Measured memory_bytes: 33568
import math

N = int(input())

# n = p * q → p or q <= n**(1/2)
# because p and q > n**(1/2) → p * q > n

divisor = []
for i in range(1 , math.floor(N**(1/2))+1):
    if N % i == 0:
        divisor.append(i)

distance = []
for j in range(int(len(divisor))):
    M = (N / int(divisor[j])) + int(divisor[j])
    distance.append(M)

if int(len(divisor)) == 1:
    print(N-1)
else:
    print(math.floor(min(distance))-2)

Measured memory_bytes: 3188