akhauriyash/Code-Regression huggingface dataset:
N, A, B = map(int, input().split())
X = list(map(int, input().split()))

sum_cost = 0
for n in range(1, N):
	cost = (X[n] - X[n - 1]) * A
	if B < cost:
		sum_cost += B
	else:
		sum_cost += cost
	#print(sum_cost)
print(sum_cost)


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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.end()
#define inf 1e9
#define Puts(x) puts(x? "YES":"NO")
const int mod = 1e9 + 7;

typedef pair<int, int> pi;
typedef long long i64;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

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

  int n, m;
  cin >> n >> m;
  if(n == 1) return cout << m << endl, 0;

  int l = m / n;
  int ans = 1;
  rep(i, 2, l + 1) {
    int a = i;
    int b = m - a * (n - 1);
    if(b % a == 0) ans = max(ans, min(a, b));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,z,x,zx,a[100001],b[100001],c[100001];
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    b[1]=a[(n/2)+1], z=1;
    for(int i=1; i<=n/2; i++)
    {
        z++;
        b[z]=a[(n-i)+1];
        z++;
        b[z]=a[i];
    }
    c[1]=a[(n/2)+1], z=1;
    for(int i=1; i<=n/2; i++)
    {
        z++;
        c[z]=a[i];
        z++;
        c[z]=a[(n-i)+1];
    }
    for(int i=1; i<n; i++)
        x+=abs(b[i]-b[i+1]);
    for(int i=1; i<n; i++)
        zx+=abs(c[i]-c[i+1]);
    cout<<max(x,zx)<<endl;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>

#include <stdio.h>

using ll = long long;
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    vector<int> dp(20005, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= h; j++) {
            if (j < a[i]) {
                dp[j] = min(dp[j], b[i]);
            } else {
                dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
            }
        }
    }
    cout << dp[h] << endl;

    return 0;
}


Measured memory_bytes: 3280
// Sooke bless me.
// LJC00118 bless me.
#include<bits/stdc++.h>

#define INF 2147483647
#define ll long long

int Inp(){
	char c = getchar();
	int Neg = 1;
	while(c < '0' || c > '9'){
		if(c == '-')
			Neg = -1;
		c = getchar();
	}
	int Sum = 0;
	while(c >= '0' && c <= '9'){
		Sum = ((Sum << 3) + (Sum << 1)) + c - '0';
		c = getchar();
	}
	return Neg * Sum;
}

int main(){
	char s[100];
	scanf("%s", s + 1);
	int l = strlen(s + 1);
	for(int i = 1; i <= l - 8; i++)
		putchar(s[i]);
}


Measured memory_bytes: 256
fun main (args:Array<String>){
    val palindRome = readLine()!!
    val palindRomeLen = palindRome.length
    val left = palindRome.take((palindRomeLen-1)/2)
    val right = palindRome.takeLast((palindRomeLen-1)/2)
    if(left == right) print("Yes")
    else print("No")
}

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

dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(N-1, -1, -1):
    for j in range(N-1, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0

ans = 0
for i in range(N):
    for j in range(N):
        ans = max(ans, min(dp[i][j], j-i))
print(ans)

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



int main() {
  string s;
  cin >> s;
  if(s=="Sunny")cout << "Cloudy" << endl;
  if(s=="Cloudy")cout << "Rainy" << endl;
  if(s=="Rainy")cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int A,B;
  cin>>A>>B;

  int ans=max(A+B,A-B);
  ans=max(ans,A*B);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
lst = [tuple(map(int, input().split())) for _ in range(N)]
lst.sort()
ans = 0
h = 0
for shop in lst:
    if h + shop[1] < M:
        ans += shop[0] * shop[1]
        h += shop[1]
    else:
        ans += shop[0] * (M - h)
        break
print(ans)

Measured memory_bytes: 16988
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

int main(){
    ll n,k;cin>>n>>k;
    vi v(n+1);
    v[0]=0;
    rep(i,n)cin>>v[i+1];
    n++;
    vvvi dp(n,vvi(n,vi(k+1,inf)));
    //dp[0][0][0]=v[0];
    rep(i,n){
        rep(j,i+1){
            rep(l,k+1){
                if(i==j){
                    if(j<=k&&l==j)chmin(dp[i][j][l],v[j]);
                    //if(i)chmin(dp[i][j][l],dp[i-1][j-1][l]+max((ll)(0),v[i]-v[j-1]));
                    rep(from,j)if(l>=i-from-1)chmin(dp[i][j][l],dp[from][from][l-(i-from-1)]+max((ll)(0),v[i]-v[from]));
                }
                else if(l&&i)chmin(dp[i][j][l],dp[i-1][j][l-1]);
            }
        }
    }
    /*rep(i,n){
        outvvi(dp[i]);
        cout<<endl;
    }*/
    ll ans=inf;
    rep(j,n)rep(l,k+1)chmin(ans,dp[n-1][j][l]);
    cout<<ans<<endl;
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
typedef pair<ll, ll> P;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e14;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

struct Book {
    int value;
    vector<int> skills;
};

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

    vector<Book> books(n);
    rep(i, n) {

        int value;
        cin >> value;

        books[i].value = value;
        books[i].skills = vector<int>(m);

        rep(j, m) {
            cin >> books[i].skills[j];
        }

    }
    ll ans = INF;
    rep(i, 1 << n) {
        vector<int> tmp(m);
        ll sum = 0;
        rep(j, n) {
            if (!((i >> j) & 1))continue;
            Book b = books[j];
            sum += b.value;

            rep(k, m) tmp[k] += b.skills[k];
        }
        ll mi = *min_element(tmp.begin(), tmp.end());
        if (mi < x) continue;
        cmin(ans, sum);
    }
    if (ans == INF) {
        cout << -1 << endl;
        ret();
    }
    cout << ans << endl;
}





Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define X first
#define Y second
//#define INF 1e12

void test_case()
{
	int r;cin>>r;
	double cir = (2.0*M_PI)*r;
	//cout<<2.0*M_PI<<endl;
	cout<<cir<<endl;
	return;
}
 
int main() {
	/*while(T--) {
		test_case();
	}*/
	test_case();
	return 0;
}

Measured memory_bytes: 3776
n=int(input())
s=input()

lr=set([])
lg=set([])
lb=set([])
for i in range(n):
    if s[i]=="R":
        lr.add(i)
    elif s[i]=="G":
        lg.add(i)
    else:
        lb.add(i)

m=0
for i in lr:
    for j in lg:
        if i+(i-j) in lb:
            m+=1
        if j-(i-j) in lb:
            m+=1
        if (i+j)/2 in lb:
            m+=1
print(len(lr)*len(lg)*len(lb)-m)


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    for (int i=0; i<n; i++) {
        cin>>a[i];
    }
    for (int i=0; i<n; i++) {
        cin>>b[i];
    }
    for (int i=0; i<n-1; i++) {
        cin>>c[i];
    }
    int sum=0;
    for (int i=0; i<n; i++) {
        for (int j=1; j<=n; j++) {
            if(a[i]==j)sum += b[i];
            if (a[i]==j && a[i+1]==j+1) sum += c[j-1];
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
t=input()
n=len(t)
pos=[]
sum=0
for i in range(n):
  if t[i]=="1":
    sum+=1
  else:
    pos.append(sum)
x=(sum+1)//2*((sum+2)//2)
sz=len(pos)
cnt=0
res=[]
for i in range(sz):
  if ((pos[i]&1)^(cnt&1)):
    sum+=1
    cnt+=1
    x+=(sum+1)//2
  else:
    res.append(i)
res=res[::-1]
odd=0
even=0
for i in range(len(res)):
  sum+=1
  if i&1:
    odd = sz - res[i] - even
    x+=(sum+1)//2-odd
  else:
    even=sz-res[i]-odd
    x+=(sum+1)//2-even
print(x)

Measured memory_bytes: 84872
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int n;
	long int flg;
	char str[100];
	
	scanf("%ld%s", &n, str);
	
	if( strlen(str) % 2 != 0) {
		printf("No\n");
		return 0;
	}
	
	for(i = 0; i < strlen(str) / 2; i++) {
		if(str[i] != str[i + strlen(str) / 2]) {
			printf("No\n");
			return 0;
		}
	}
	
	printf("Yes\n");
	
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(){
	int a,b,c;
	int rect=0,rhomb=0;
	
	while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		if(a*a+b*b == c*c){
			rect++;
		}
		
		if(a==b){
			rhomb++;
		}
		
	}
	
	printf("%d\n%d\n",rect,rhomb);
	
	return 0;
}

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

using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;

  string ans[100];
  for(int i = 0; i < 50; i++) {
    for(int j = 0; j < 100; j++) {
      ans[i] += '.';
      ans[i + 50] += '#';
    }
  }

  int count = 1;
  for(int i = 0; i < 49; i += 2) {
    int tmp = i % 2;
    for(int j = 0 + tmp; j < 100; j += 2) {
      if(b == count) {
	break;
      }
      ans[i][j] = '#';
      count++;
    }
  }

  count = 1;
  for(int i = 51; i < 100; i += 2) {
    int tmp = i % 2;
    for(int j = 0 + tmp; j < 100; j += 2) {
      if(a == count) {
	break;
      }
      ans[i][j] = '.';
      count++;
    }
  }

  cout << "100 100" << endl;
  
  for(int i = 0; i < 100; i++) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        s: chars,
        t: chars,
    }
    println!("{}", {
        let mut r = String::new();
        for i in 0usize..n {
            r.push(s[i]);
            r.push(t[i]);
        }
        r
    });
}


Measured memory_bytes: 4352
(let ((l (concatenate 'list (read-line))))

  (defun f (lst &optional (acc 0))
    (if (null lst)
      acc
      (if (char= (car lst) #\+)
        (f (cdr lst) (1+ acc))
        (f (cdr lst) (1- acc)))))

  (format t "~A~%"
          (f l)))


Measured memory_bytes: 24324
def main():
    flag=False
    N,M=map(int,input().split())
    if N==1 and M==0:
        return 0
    
    L=[None]*N
    for i in range(M):
        s,c=map(int,input().split())
        if L[s-1]!=None and L[s-1]!=c:
            flag=True
        L[s-1]=c
        
    if flag:
        return -1

    if L[0]==None:
        L[0]=1
        
    for j in range(len(L)):
        if L[j]==None:
            L[j]=0
    
    output=int(''.join(map(str,L)))
    if N==1:
        return output
    if output and len(str(output))==N:
        return output
    else:
        return -1
    
print(main())



Measured memory_bytes: 3188
import java.util.Scanner;

class Point {
	int x;
	int y;
	
	Point(int x, int y) {
		this.x = x;
		this.y = y;
	}
}

class Main {
    public static void main(String[] args) {
    	Scanner scan = new Scanner(System.in);
    	
    	int countQues = 1;
    	while (scan.hasNextInt()) {
    		int numVertices = scan.nextInt();
    		if(numVertices == 0) break;
        	Point[] point = new Point[numVertices];

        	for(int i = 0; i < numVertices; i++) {
        		point[i] = new Point(scan.nextInt(), scan.nextInt());
        	}
    		
    		double area = 0;
        	
        	for(int i = 0; i < numVertices; i++) {
        		if(i == numVertices-1) {
        			int tmp_area = (point[i].x*point[0].y - point[0].x*point[i].y);
            		//if (tmp_area < 0) tmp_area *= -1;
            		area += tmp_area;
        			area /= 2;
        			if(area <0) area *= -1;
        			break;
        		}
        		int tmp_area = (point[i].x*point[i+1].y - point[i+1].x*point[i].y);
        		//if (tmp_area < 0) tmp_area *= -1;
        		area += tmp_area;
        	}
        	System.out.println(countQues + " " + area);
        	countQues++;
    	}
    }
}

Measured memory_bytes: 21004
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);



int main(){
	string s;
	ll t,f;
	char c;
	ll q;
	cin>>s;
	cin>>q;
	string init;
	string endd;
	ll rev=0;
	string tmp;
	while(q--){
		cin>>t;
		if(t==1){
			rev=rev^1;
		}
		else{
			cin>>f>>c;
			if(f==1){
				if(rev) endd=endd+c;
				else init=init+c;

			}
			else{
				if(rev) init=init+c;
				else endd=endd+c;
			}

		}
	}
    if(rev){
    	reverse(all(endd));
    	reverse(all(s));
    	endd=endd+s+init;
    	cout<<endd<<endl;

    }
    else{
    	reverse(all(init));
    	init=init+s+endd;
        cout<<init<<endl;
    }
    
}

Measured memory_bytes: 1620
import sys
input = sys.stdin.buffer.readline
from itertools import accumulate
from bisect import bisect_left

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))

Acum = [0] + list(accumulate(A))
answer = INF

for i in range(2, N - 1):
  bpq = bisect_left(Acum,  (Acum[i] - Acum[0]) // 2)
  brs = bisect_left(Acum,  (Acum[N] - Acum[i]) // 2 + Acum[i])
  
  P1, Q1 = Acum[bpq] - Acum[0], Acum[i] - Acum[bpq]
  P2, Q2 = Acum[bpq - 1] - Acum[0], Acum[i] - Acum[bpq - 1]
  R1, S1 = Acum[brs] - Acum[i], Acum[N] - Acum[brs]
  R2, S2 = Acum[brs - 1] - Acum[i], Acum[N] - Acum[brs - 1]  
  
  tmp = INF
  tmp = min(tmp, max(P1, Q1, R1, S1) - min(P1, Q1, R1, S1))
  tmp = min(tmp, max(P1, Q1, R2, S2) - min(P1, Q1, R2, S2))
  tmp = min(tmp, max(P2, Q2, R1, S1) - min(P2, Q2, R1, S1))
  tmp = min(tmp, max(P2, Q2, R2, S2) - min(P2, Q2, R2, S2))
  
  answer = min(answer, tmp)
  
print(answer)

Measured memory_bytes: 22116
import sys
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        numer = N * h * n
        denom = 4 * h * n - N * n - N * h
        if denom > 0 and numer % denom == 0:
            print(h, n, numer // denom)
            sys.exit()


Measured memory_bytes: 40428
#include <iostream>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
  if ((a<=b)&&(b<=c)){
   cout << a <<' '<<b<<' '<<c <<endl;
  }
  else if ((a<=c)&&(c<=b)){
   cout << a <<' '<<c<<' '<<b <<endl;
  }
  else if ((c<=b)&&(b<=a)){
   cout << c <<' '<<b <<' '<<a <<endl;
  }
  else if ((b<=a)&&(a<=c)){
   cout << b<<' '<<a<<' '<<c <<endl;
  }
  else if ((b<=c)&&(c<=a)){
   cout <<b<<' '<<c<<' '<<a<<endl;
  }
  else if ((c<=a)&&(a<=b)){
   cout <<c<<' '<<a<<' '<<b<<endl;
  }
}


Measured memory_bytes: 3032
#include <iostream>
using namespace std;
int main()
{
	int a, b, c = 0;
	cin >> a >> b >> c;
	if ((a < b)&&(b<c))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#include <stack>
#include <queue>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cmath>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <chrono>
#include <numeric>

#define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count())

#define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__)
#define rc(...) char __VA_ARGS__; rx(__VA_ARGS__)
#define rs(...) string __VA_ARGS__; rx(__VA_ARGS__)
#define rvi(x, n) vi x(n); cin >> x
#define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__)
#else
#define dbg(...) ;;
#endif

#define fa(i, v) for (auto &i : v)
#define fi(i, n) for (i32 i = 0; i < n; i++)
#define fp(i, n) for (i32 i = 1; i < n; i++)
#define fr(i, n) for (i32 i = n - 1; i >= 0; i--)
#define fu(i) ri(_i); fi(i, _i)

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

typedef uint32_t u32;
typedef int32_t i32;
typedef uint64_t u64;
typedef int64_t i64;
#ifdef __SIZEOF_INT128__
typedef __uint128_t u128;
typedef __int128_t i128;
#endif
typedef vector<i64> vi;
typedef vector<vi> vvi;

template<typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
    fa(x, v) in >> x;
    return in;
}

template<typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
    fa(x, v) out << x << ' ';
    return out;
}

template<typename T>
inline void rx(T &x) {
    cin >> x;
}

template<typename T, typename... R>
inline void rx(T &x, R &... l) {
    cin >> x;
    rx(l...);
}

template<typename T>
inline void dbg_log(const T &x) {
    cerr << x << '\n';
}

template<typename T, typename... R>
inline void dbg_log(const T &x, const R &... l) {
    cerr << x << ", ";
    dbg_log(l...);
}

template<typename T>
inline void wl(const T &x) {
    cout << x << '\n';
}

template<typename T, typename... R>
inline void wl(const T &x, const R &... l) {
    cout << x << ' ';
    wl<R...>(l...);
}

int main() {
    fio;

    ri(n);
    u64 res = 0;
    fp(i, n + 1) {
        u64 cnt = n / i;
        res += i * (cnt * (1 + cnt) / 2);
    }
    wl(res);

    return 0;
}


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

int find(vector<int> &V, int x){
  if(V[x]==x) return x;
  else{
    int ret = find(V,V[x]);
    V[x] = ret;
    return ret;
  }
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> V(N);
  for(int i=0;i<N;i++) V[i] = i;
  
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    a--;b--;
    int x = find(V,a), y = find(V,b);
    V[y] = x;
  }
  
  vector<int> W(N);
  for(int i=0;i<N;i++) W[find(V,V[i])]++;
  int ans=0;
  for(int i=0;i<N;i++) ans = max(ans,W[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4940
k = int(input())

neighbors = {'0': ['0', '1'], '1': ['0', '1', '2'], '2': ['1', '2', '3'], 
             '3': ['2', '3', '4'], '4': ['3', '4', '5'], '5': ['4', '5', '6'], 
             '6': ['5', '6', '7'], '7': ['6', '7', '8'], '8': ['7', '8', '9'], 
             '9': ['8', '9']}
queue = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
count = 0
#print(neighbors)
while True:
  num = queue.pop(0)
  count += 1
  if count == k:
    print(int(num))
    break
  else:
    num_last = num[-1]
    lst = neighbors[num_last]
    for ele in lst:
      num_add = num + ele
      queue.append(num_add)

Measured memory_bytes: 22380
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

ll gcd_stein(int u, int v) {
	ll k, t;

	/* u, vどちらかが奇数になるまで2で割り続ける */
	k = 0;
	while ((0 == (u & 1)) && (0 == (v & 1))) {
		k++;
		u /= 2;
		v /= 2;
	}

	if ((u & 1) == 0) {
		t = u / 2;
	}
	else {
		t = -v;
	}

	do {
		/* tが偶数である限り、2で割り続ける */
		while ((t & 1) == 0) t /= 2;

		if (t > 0) {
			u = t;
		}
		else {
			v = -t;
		}

		t = u - v;
	} while (0 != t);
	return u * (1 << k);
}

int main() {
	ll n, xx,q,ans;
	vector<ll> x0,x1;
	cin >> n >> xx;
	for (int i = 0; i < n; i++)
	{
		cin >> q;
		x0.push_back(q);
	}
	x0.push_back(xx);
	sort(x0.begin(), x0.end());

	ans = x0[1] - x0[0];
	for (int i = 2; i <= n; i++)
	{
		ans = gcd_stein(ans, x0[i] - x0[i - 1]);
	}


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
from math import ceil
A, B = map(int, input().split(' '))
x0 = ceil(A / 0.08)
x1 = ceil((A+1) / 0.08)
y0 = ceil(B / 0.1)
y1 = ceil((B+1) / 0.1)
if x1 <= y0 or y1 <= x0:
  print(-1)
else:
  print(min(max(x0, y0), min(x1, y1)))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define pir pair<int,int>
#define pb push_back
using namespace std;

const int N=200010;
int n,m,cnt[N][2],tp[N];
vector<int> G[N];
queue<int> Q;
bool vis[N];
char s[N];

bool check(int u) {
	return cnt[u][0]&&cnt[u][1];
}

int main() {
	int u,v;
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) {
		tp[i]=s[i]-'A';
	}
	for(int i=1;i<=m;i++) {
		scanf("%d%d",&u,&v);
		G[u].pb(v);cnt[v][tp[u]]++;
		G[v].pb(u);cnt[u][tp[v]]++;
	}
	for(int i=1;i<=n;i++) {
		G[0].pb(i);G[i].pb(0);cnt[0][tp[i]]++;
		if(!check(i)) Q.push(i),vis[i]=1;
	}
	if(!check(0)) return puts("No"),0;
	while(!Q.empty()) {
		int u=Q.front();Q.pop();
		for(int v:G[u]) {
			if(vis[v]) continue;
			cnt[v][tp[u]]--;
			if(!check(v)) Q.push(v),vis[v]=1;
		}
	}
	puts(vis[0]?"No":"Yes");
	return 0;
}

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

int main() {
  long long a,v,b,w, num;
  bool chk = false;

  cin >> a >> v >> b >> w >> num;

  if(a == b){
      cout << "YES";
      return 0;
  }
  if(a <= b){
      // 左に移動
      for(int i = 0; i < num; i++){
          a = a + v;
          b = b + w;
         if(a >= b){
              chk = true;
              break;
          }
      }
   }else{
       //右に移動
       for(int i = 0; i < num; i++){
           a = a - v;
           b = b - w;
           
           if(a <= b){
               chk = true;
               break;
           }
       }
}

  if(chk) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))

syozi = 1000
kabu = 0

for i in range(N-1):
  if A[i] < A[i+1]:
    kabu += syozi // A[i] 
    syozi -= (syozi // A[i]) * A[i]
  elif A[i] > A[i+1]:
    syozi += A[i] * kabu
    kabu = 0
  else:
    pass

syozi += A[-1] * kabu

print(syozi)

Measured memory_bytes: 9208
if __name__ == '__main__':
    A, B, C, D = map(int, input().split())

    if B <= C or D <= A:
        print(0)
    else:
        if A < C:
            if B < D:
                print(B-C)
            else:
                print(D-C)
        elif A > C:
            if B < D:
                print(B-A)
            else:
                print(D-A)
        else:
            if B < D:
                print(B-A)
            else:
                print(D-A)

Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


void solve(long long S, long long W){
	if(W>=S){
		cout << "unsafe" << endl;
	}
	else{
		cout << "safe" << endl;
	}

}

int main(){
    long long S;
    scanf("%lld",&S);
    long long W;
    scanf("%lld",&W);
    solve(S, W);
    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int a=A*B,b=C*D;
  if (a>b){
    cout << a << endl;
  }
  else {
    cout << b << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int uchiha=1e5+5;
int arr[uchiha];
int main()
{
long long n,m;
cin>>n>>m;
m=m/2;

if(n<=m){
    cout<<n+((m-n)/2);
}
else
    cout<<m;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
    int n,m;
    int i,j,k;
    LL a,b,c;
    cin>>a>>b>>c;
    a=abs(a);
    if(a/c<b || a-b*c<0){
        b-=a/c;
        a%=c;
        if(b%2==1)a=c-a;
    }else a-=b*c;
    cout<<a<<endl;
}

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

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

int count(int num) {
	int res = 0;
	while (num > 0) {
		num /= 10;
		res++;
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (count(i) % 2 == 1) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>    
#define pb push_back

#define FOR(x,to) for(int x=0;x<(to);x++)
#define F0R(x,in,to) for(int x=(in);x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))

typedef long long ll;
using namespace std;
ll MOD = 1e9 + 7;

typedef pair<int,int> ii;
typedef struct {int a,b,c;}iii;
typedef vector<int> vi;

void mosA(vector<int> a){
	for(int i=0; i<a.size(); i++) printf("%d ",a[i]);
	printf("\n");
}
void mosP(vector<ii> a){
	for(int i=0; i<a.size(); i++) printf("%d %d\n",a[i].first,a[i].second);
	printf("\n");
}

ll min_especial(ll a, ll b){
  if(a!=-1 && b!=-1) return min(a,b);
  else return max(a,b);
}
/*
bool ord(ii a, ii b){
	if(a.first == b.first){
		return a.second < b.second;
	}
	return a.first < b.first;
}*/

bool ord(ll a, ll b){
	return a>b;
}

ll ans = 0;
int a,n,w,t,k,m,z,q,l,r,x,b,c,y;
char S[300005];
vi G[300005];
ii A[300005];
ii B[300005];

vector<iii> v;

int main(){
	int n,a,b,c,d;
	scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,S);

	bool sePuede = false;

	for(int i=b-1; i<d; i++){
		if(S[i]=='#' && S[i+1]=='#') return !printf("No\n");
		if(S[i]=='.' && S[i+1]=='.' && S[i-1] == '.') sePuede=1;
	}

	if(c>d && !sePuede) return !printf("No\n");

	for(int i=a; i<c; i++) if(S[i]=='#' && S[i+1]=='#') return !printf("No\n");


	return !printf("Yes\n");

}




// REVISATE ESTO:
// - memset(A,-1,SIZEOF()*n)
// - (x-y+MOD)%MOD
// - int o ll?

Measured memory_bytes: 8064
#include <stdio.h>

int main(void)
{
	int x, i;
	for ( x = 1; x <= 9 ; x ++){
		for(i = 1; i <= 9 ; i ++){
			printf("%dx%d=%d\n",x,i,x*i);
		}
	}
	return 0;
}

Measured memory_bytes: 520
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string a, b;
    cin >> a >> b;

    string s = a + b;
    int N = atoi(s.c_str());

    int i = 1;
    while (i * i <= N){
        i++;
    }
    if ((i-1)* (i-1) == N){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int n, m;
vector<int> v[100000];
map<int, int> z;

int f(int x)
{
	debug(x);
	cout.flush();
	if(z[x]) return z[x];
	int ans = 0;
	for(int i=0;i<v[x].size();i++)
	{
		ans = max(ans, 1 + f(v[x][i]));
	}
	z[x] = ans;
	return ans;
}

int main()
{
	cin >> n >> m;
	for(int i=0;i<m;i++)
	{
		int x, y;
		cin >> x >> y;
		v[x-1].pb(y-1);
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		ans = max(ans, f(i));
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 13824
import           Control.Exception (assert)
import           Control.Monad     (replicateM)
import           Data.List         (foldl1', intersect)

main :: IO ()
main = do
  [n, _m] <- map read . words <$> getLine
  ass <- replicateM n $ do
    kn : as <- map read . words <$> getLine
    assert (length as == kn) $ pure as
  print $ solve ass

solve :: [[Int]] -> Int
solve = length . foldl1' intersect


Measured memory_bytes: 1148
s=input()

d={'0':'1','1':'0'}

s1='1'
s2='0'
cnt1=0
cnt2=0
for a in s:
	if s1!=a:cnt1+=1
	if s2!=a:cnt2+=1
	s1=d[s1]
	s2=d[s2]
print(min(cnt1,cnt2))

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
  int count = 0;
  int ans = 0;
  int n;
  cin >> n;
  int a;
  for(int i=0;i<n;i++){
    cin >> a;
    if(a==0){
      ans = max(ans,count);
      count = 0;
    }
    else if(a==1){
      count++;
    }
    if(i==n-1){
      ans = max(ans,count);
    }
  }
  cout << ans+1 << endl;
}



Measured memory_bytes: 3108
using System;
using System.Linq;
class Test{
  public static void Main(){
    var num = Console.ReadLine().Split(" ").Select(n => int.Parse(n)).ToList();
    int Thp = num[0];
    int Tatk = num[1];
    int Ahp = num[2];
    int Aatk = num[3];
    while(Thp>0 && Ahp>0){
      Ahp-=Tatk;
      Thp-=Aatk;
    }
    if(Ahp<=0){
     Console.Write("Yes"); 
    }else{
     Console.Write("No");
    }
  }
}

Measured memory_bytes: 28324
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#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) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// 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;
using namespace __gnu_pbds;
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
    ll a, b, k;
    cin>>a>>b>>k;
    ll cur = MIN2(a, k);
    a -= cur;
    k -= cur;
    cur = MIN2(b, k);
    b -= cur;
    k -= cur;
    cout<<a<<" "<<b<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String [] args){
    Scanner sc=new Scanner(System.in);
    int count2=1;
    for(int count=1; count==count2; count++){
      int x=sc.nextInt(), y=sc.nextInt();
      int max=x, min=x;
      if((x==0)&&(y==0)){
        break;
      }
      else{
        if(y<min){
          min=y;
        }
        else{
          max=y;
        }
      }
      System.out.println(min+" "+max);
      count2++;
    }
  }
}


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

using namespace std;

int main()
{
	string s[3];

	while (cin >> s[0], s[0] != "0")
	{
		cin >> s[1] >> s[2];
	
		if (s[0][0] == s[0][1] && s[0][1] == s[0][2] && s[0][0] != '+')
		{
			cout << s[0][0] << endl;
		}
		else if (s[1][0] == s[1][1] && s[1][1] == s[1][2] && s[1][0] != '+')
		{
			cout << s[1][0] << endl;
		}
		else if (s[2][0] == s[2][1] && s[2][1] == s[2][2] && s[2][0] != '+')
		{
			cout << s[2][0] << endl;
		}
		else if (s[0][0] == s[1][0] && s[1][0] == s[2][0] && s[0][0] != '+')
		{
			cout << s[0][0] << endl;
		}
		else if (s[0][1] == s[1][1] && s[1][1] == s[2][1] && s[0][1] != '+')
		{
			cout << s[0][1] << endl;
		}
		else if (s[0][2] == s[1][2] && s[1][2] == s[2][2] && s[0][2] != '+')
		{
			cout << s[0][2] << endl;
		}
		else if (s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[0][0] != '+')
		{
			cout << s[0][0] << endl;
		}
		else if (s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[0][2] != '+')
		{
			cout << s[0][2] << endl;
		}
		else
		{
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 1180
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var team=[];
   for(var i=0;i<n;i++){
      var arr=(Arr.shift()).split(" ").map(Number);
      var a=(arr[1]*60)+arr[2];
      var b=(arr[3]*60)+arr[4];
      var c=(arr[5]*60)+arr[6];
      var d=(arr[7]*60)+arr[8];
      team.push([arr[0],a+b+c+d]);
   }
   team.sort(function(a,b){
      a=a[1];
      b=b[1];
      return a-b;
   });
   console.log(team[0][0]);
   console.log(team[1][0]);
   console.log(team[team.length-2][0]);
}

Measured memory_bytes: 14396
import collections
n=int(input())
Words = [input() for t in range(n)]

Words2=[]
for i in Words:
        i=''.join(sorted(i))
        Words2.append(i)

c = collections.Counter(Words2)

values, counts = zip(*c.most_common())

ans=0
for j in counts:
        ans+=j*(j-1)//2
print(ans)

Measured memory_bytes: 38756
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int D = scanner.nextInt();
        int T = scanner.nextInt();
        int S = scanner.nextInt();
       

        scanner.close();

        if(T*S >= D){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }


    }
}


Measured memory_bytes: 35736
def solve():
    N = int(input())
    a = 0
    b = 0
    ab = 0
    ans = 0
    for _ in range(N):
        s = input()
        if s[-1] == 'A' and s[0] == 'B':
            ab += 1
        elif s[-1] == 'A':
            a += 1
        elif s[0] == 'B':
            b += 1
        ans += s.count('AB')
        
    if ab == 0:
        ans += min(a, b)
    else:
        if a == 0 and b == 0:
            ans += ab - 1
        else:
            ans += ab + min(a, b)
            
    return ans
    
print(solve())

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

using namespace std;

int main(void) {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<long long> s(A), t(B), x(Q);
    for (int i = 0; i < A; i++) {
        cin >> s[i];
    }
    sort(begin(s), end(s));
    for (int i = 0; i < B; i++) {
        cin >> t[i];
    }
    sort(begin(t), end(t));
    for (int i = 0; i < Q; i++) {
        cin >> x[i];
    }

    for (auto start: x) {
        auto s_l = lower_bound(begin(s), end(s), start);
        auto s_r = upper_bound(begin(s), end(s), start);
        auto t_l = lower_bound(begin(t), end(t), start);
        auto t_r = upper_bound(begin(t), end(t), start);

        if (s_l != begin(s)) s_l--;
        if (t_l != begin(t)) t_l--;
        if(s_l == end(s)) s_l--;
        if(t_l == end(t)) t_l--;
        if (t_r == end(t)) t_r--;
        if (s_r == end(s)) s_r--;

        // cerr<<*s_l<<endl;
        // cerr<<*s_r<<endl;
        // cerr<<*t_l<<endl;
        // cerr<<*t_r<<endl;

        long long ans = (long long)1e18;
        for (auto cur_s: {*s_l, *s_r}) {
            for (auto cur_t: {*t_l, *t_r}) {
                auto foo1 = upper_bound(begin(t), end(t), cur_s);
                auto foo2 = upper_bound(begin(s), end(s), cur_t);
                auto foo3 = lower_bound(begin(t), end(t), cur_s);
                auto foo4 = upper_bound(begin(s), end(s), cur_t);
                if (foo3 != begin(t)) foo3--;
                if (foo4 != begin(s)) foo4--;
                if (foo1 == end(t)) foo1--;
                if (foo2 == end(s)) foo2--;
                if (foo3 == end(t)) foo3--;
                if (foo4 == end(s)) foo4--;
                ans = min(
                    ans,
                    min(
                        abs(start - cur_s) + min({abs(cur_s - *lower_bound(begin(t), end(t), cur_s)), abs(cur_s - *foo1), abs(cur_s - *t_l), abs(cur_s - *t_r)}),
                        abs(start - cur_t) + min({abs(cur_t - *lower_bound(begin(s), end(s), cur_t)), abs(cur_t - *foo2), abs(cur_t - *s_l), abs(cur_t - *s_r)})
                    )
                );
            }
        }
        cout << ans << endl;
    }
}


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

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    string S;
    cin >> S;
    cout << ((S[5]=='1' || S[6]>'4') ? "TBD" : "Heisei") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vi H(N);
	REP(i, N)cin >> H[i];
	so(H);
	int ans = 1000000001;
	REP(i, N) {
		if (i + K - 1 >= N)break;
		ans = min(ans, H[i + K - 1] - H[i]);
	}
	cout << ans << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int s = S.size();
  REP(i, s) cout << "x";
  cout << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int M = sc.nextInt();
    int C = sc.nextInt();
    int Nums[]=new int[M];
    int sum=0;
    int AB=0;
    int count=0;
     int Source[][]=new int[A][M];
    for(int i=0;i<M;i++){
    	Nums[i]=sc.nextInt();
    }
     for(int i=0;i<A;i++){
       for(int j=0;j<M;j++)
    	Source[i][j]=sc.nextInt();
    }
    for(int i=0;i<A;i++){
      sum=0;
       for(int j=0;j<M;j++){
    	AB=Source[i][j]*Nums[j];
         sum+=AB;
   	 }
      sum+=C;
      if(sum>0){
      count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23892
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

int main() {
  //
  int p,q,r;
  cin>>p>>q>>r;
  vi l(3);
  l[0] = p+q; l[1]=q+r; l[2]=r+p;
  sort(ALL(l));
  cout << l[0] << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define D(i,n) for (int i=(n); i-->0;)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream& operator<<(ostream& os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i]; return os;}
const bool debug = 0;
const int INF = 1e9;

struct seg{int l,r;};

struct segtree {
    typedef int T;
    const T DEF = INF;
    T f(T a, T b) {return min(a,b);}
    
    int n=1; V<T> t;
    void calc(int i) {t[i] = f(t[2*i], t[2*i+1]);}
    segtree(int _n) {
        while (n < _n) n*=2;
        t = V<T>(2*n, DEF);
        for (int i=n; i-->1;) calc(i);
    }
    void modify(int i, T val) {
        i+=n;
        t[i] = min(t[i], val);
        for (; i/=2;) calc(i);
    }
    int query(int l, int r) {
        T accL = DEF, accR = DEF;
        for (l+=n, r+=n; l<r; l/=2, r/=2) {
            if (l&1) accL = f(accL, t[l++]);
            if (r&1) accR = f(t[--r], accR);
        }
        return f(accL, accR);
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    V<int> b(n);
    F(i,n) cin>>b[i];
    V<int> pref[2];
    F(k,2) {
        pref[k].resize(n+1);
        pref[k][0] = 0;
        F(i,n) pref[k][i+1] = pref[k][i] + (b[i] == k);
    }
    
    int nq; cin>>nq;
    V<seg> ss(nq);
    F(i,nq) {
        cin>>ss[i].l>>ss[i].r;
        ss[i].l--;
    }
    sort(ALL(ss), [](seg aa, seg bb) {return aa.l < bb.l;});
    segtree ch[]{{n+1}, {n+1}};
    ch[1].modify(0,0);
    for (seg s : ss) {
        int cost = min(ch[0].query(s.l,s.r+1) + pref[0][s.l],
            ch[1].query(0, s.l+1) + pref[1][s.l]);
        int costR = cost + pref[0][s.r] - pref[0][s.l];
        H(costR)
        ch[0].modify(s.r, costR - pref[0][s.r]);
        ch[1].modify(s.r, costR - pref[1][s.r]);
    }
    int best = ch[1].query(0,n+1) + pref[1][n];
    cout<<best<<"\n";
}

Measured memory_bytes: 16256
#include <algorithm>
#include <vector>
#include <iostream>
#define int long long

using namespace std;

int Sad(int b, vector<int>A){
    int sad = 0;
    for(int i = 0; i < A.size(); ++i){
        sad += abs(A[i] - b);
    }
    return sad;
}

signed main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        A[i] -= (i+1);
    }
    
    sort(A.begin(), A.end());
   
    int b = A[N / 2];
    
    int num = min(Sad(b - 1, A), min(Sad(b + 1, A), Sad(b, A)));
    
    
    cout << num << endl;
}

Measured memory_bytes: 6528
import sys
from _collections import deque
N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(len(A)):
    A[i] = A[i]-1
used = [0]*N
m = 0
c = 0
used[m] = 1

while(True):
    m = A[m]
    c += 1
    if c == K:
        print(m+1)
        sys.exit()
    if used[m] == 1:
        break
    else:
        used[m] = 1

loop = m
h = K-c
ans = deque([loop])
c = 0
p = loop
while(True):
    p = A[p]
    c += 1
    if p == loop:
        break
    ans.append(p)

print(ans[h%c]+1)

Measured memory_bytes: 92336
K = int(raw_input())
L = []

def dfs(n, m, s):
    if n <= s and s <= m:
        L.append(s)

    if s == 0 or s > m:
        return

    ld = s % 10
    s0 = s*10 + ld-1
    s1 = s*10 + ld
    s2 = s*10 + ld+1

    if ld == 0:
        dfs(n, m, s1)
        dfs(n, m, s2)
    elif ld == 9:
        dfs(n, m, s0)
        dfs(n, m, s1)
    else:
        dfs(n, m, s0)
        dfs(n, m, s1)
        dfs(n, m, s2)

for i in range(10):
    dfs(0, 10**10, i)

A = sorted(L)
print A[K]

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

const int maxn = 1000;
int a[maxn];
int main(){
    // freopen("input.txt","r",stdin);
    int n,x;
    cin >> n >> x;
    for(int i=0; i<n; i++)  cin >> a[i];
    sort(a, a+n);
    int ans = 0;
    int i;
    for(i=0; i<n; i++){
        if(x<a[i])
            break;
        x-=a[i];
        ans++;
    }
    if(x != 0&&i==n) ans--;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384