akhauriyash/Code-Regression huggingface dataset:
;; F - Playing Tag on Tree

(defun main ()
  (let* ((N (read))  ; 頂点数
         (u (read))  ; 高橋君の位置
         (v (read))  ; 青木君(鬼)の位置
         (tree (read-tree N)))
    (princ (solve N (1- u) (1- v) tree))
    (fresh-line)))

(defun solve (N u v tree)
  (let* ((distance (distances-from v tree)) ; vから各頂点までの距離
         (dist-v-u (aref distance u)) ; vからuまでの距離
         (margin (floor (1- dist-v-u) 2)) ; 捕まらずにvまで近づける距離
         (max-dist (max-distance u margin tree distance)))
    (1- max-dist))) ; 最大距離-1 の頂点で捕まる

(defun max-distance (u margin tree distance)
  "distanceがmargin以下の頂点を通らずに,
   uから到達可能な頂点のdistanceの最大値"
  (let* ((max (aref distance u))) ; 現時点の最大値
    (dfs u tree
         #'(lambda (v _) (when (< max (aref distance v))
                               (setf max (aref distance v))))
         #'(lambda (v) (> (aref distance v) margin)))
    max))

(defun distances-from (v tree)
  "頂点vから各頂点までの距離を表す配列を返す"
  (let* ((N (array-dimension tree 0)) ; 頂点数
         (distance (make-array N))) ; 各頂点までの距離
    (dfs v tree
         #'(lambda (u dist) (setf (aref distance u) dist))
         #'(lambda (u) t))
    distance))

(defun dfs (start tree operation next-cond)
  "treeに対して深さ優先探索を行い, 各頂点にoperationを適用.
   隣接頂点のうちnext-condを満たすもののみ選択される."
  (let* ((N (array-dimension tree 0)) ; 頂点数
         (visited (make-array N :initial-element nil))) ; 訪問済?
    (labels ((dfs-body (stack)
               (when stack
                 (let* ((payload (pop stack))
                        (v (car payload))
                        (dist (cdr payload)))
                   (unless (aref visited v)
                     (setf (aref visited v) t)
                     (funcall operation v dist)
                     (loop for next in (aref tree v) ; vの隣接頂点
                       when (funcall next-cond next)
                         do (push (cons next (1+ dist)) stack)))
                   ; stack overflowを避けるため末尾再帰に
                   (dfs-body stack)))))
      (dfs-body (list (cons start 0))))))

(defun read-tree (N)
  "N頂点の木をreadして作る. 頂点番号は0〜N-1"
  (let ((tree (make-array N))) ; 隣接リスト
    (loop for i below N do (setf (aref tree i) nil))
    (loop repeat (1- N)
      do (let ((a (read))
               (b (read)))
           (push (1- b) (aref tree (1- a)))
           (push (1- a) (aref tree (1- b)))))
    tree))

(main)


Measured memory_bytes: 73064
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
 
vvi g;
int n;
vi par,vis; 
vii r,b;
 
int augment(int v)
{
    if(vis[v])
        return 0;
    vis[v] = 1;
    for(int u : g[v])
        if(par[u] == -1 || augment(par[u]))
        {
            par[u] = v;
            return 1;
        }
    return 0;
}
 
int mcbm(int left) 
{
    int ans = 0;
    par = vi(2*n, -1);
    for(int i = 0; i < left; i++)
    {
        vis = vi(left, 0);
        ans += augment(i);
    }
    return ans;
}
 
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    while(cin >> n)
    {
        r = vii(n);
        for(int i = 0; i < n; i++)
            cin >> r[i].first >> r[i].second;
        b = vii(n);
        for(int i = 0; i < n; i++)
            cin >> b[i].first >> b[i].second;
        g = vvi(2*n);
        for(int i = 0; i < (int)r.size(); i++)
            for(int j = 0; j < (int)b.size(); j++)
                if(r[i].first < b[j].first && r[i].second < b[j].second)
                    g[i].push_back(j+n);
        cout << mcbm(n) << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
q=abs;s=lambda t,i:0--t//3**i;m=lambda a,b,c,d:max([i for i in range(30)if s(a,i)==s(c,i)and s(a,i)%3==2and 1<q(s(b,i)-s(d,i))]+[-1])+1
for _ in[0]*int(input()):
  a,b,c,d=map(int,input().split());h=m(a,b,c,d);w=m(b,a,d,c)
  if h==w==0:print(q(b-d)+q(a-c));continue
  if h<w:h,a,b,c,d=w,b,a,d,c
  i=3**h//3;x=2*i+1;g=a-(a-1)%(3*i)-1;a-=g;c-=g;print(q(b-d)+min(q(i-a)+q(i-c),q(x-a)+q(x-c)))

Measured memory_bytes: 3316
from heapq import heappush,heappop
class Dijk:
    def __init__(self,n):
        self.table=[[] for i in range(n)]
        self.n=n
    
    def add(self,x,y,f):
        self.table[x].append((y,f))
        
    def di(self,s):
        inf=10**20
        self.val=[inf]*self.n
        self.val[s]=0
        h=[]
        heappush(h,(0,s))
        while h:
            q,i=heappop(h)
            if self.val[i]<q:
                continue
            for x,c in self.table[i]:
                if self.val[x]>self.val[i]+c:
                    self.val[x]=self.val[i]+c
                    heappush(h,(self.val[x],x))
                    
    def dist(self,s,t):
        return self.val[t]

K=int(input())
d=Dijk(K)
for i in range(1,K):
    d.add(i,(i+1)%K,1)
    d.add(i,(10*i)%K,0)
d.di(1)
print(d.dist(1,0)+1)

Measured memory_bytes: 38276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int A,B;cin >> A >> B;
  cout << max(0,A-2*B) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
 
#define MOD 1000000007
 
int main(void){
    // Your code here!
    long long n, k, count = 0, output = 0;
    long long x[100000] = {};
    
    cin >> n >> k;
    for(long long i = 0; i < n; i++){
        cin >> x[i];
    }
    
    long long most_bit = 40;
    
    for(long long i = most_bit; 0 <= i; i--){
        long long count_1 = 0;
        for(long long j = 0; j < n; j++){
            if((x[j] >> i) % 2 == 1)
                count_1++;
        }
        if(count_1 <= n / 2)
            if(count + ((long long)1 << i) <= k)
                count += ((long long)1 << i);
            
    }
    
    for(long long i = 0; i < n; i++)
        output += x[i] ^ count;
    
    cout << output << endl;
    
    return 0;
}

Measured memory_bytes: 1152
$debug = false

n = gets.to_i
as = [0]
as += gets.split.map(&:to_i)
as << 0
p as if $debug

max_fare = 0
current = 0
as.each do |point|
  max_fare += (point - current).abs
  current = point
end
puts "max_fare: #{max_fare}" if $debug

as.each_with_index do |a, i|
  if i == 0 || i == n + 1
    next
  else
    puts max_fare - (as[i] - as[i -1]).abs - (as[i + 1] - as[i]).abs + (as[i+1] - as[i-1]).abs
  end
end


Measured memory_bytes: 11788
#include <stdio.h>

int main (void){


int a,b,c,d;


scanf("%d %d %d",&a,&b,&c);


if(a>c)


{


d=a;


a=c;


c=d;


}


if(a>b)


{


d=a;


a=b;


b=d;





}


if(b>c)


{


d=b;


b=c;


c=d;


}


printf("%d %d %d\n",a,b,c);


return 0;


}

Measured memory_bytes: 596
from copy import deepcopy as dp
from operator import itemgetter as ig
n,m = map(int,input().split())
#[input番号,県番号,年,県における順番]
list1 = []
for i in range(m):
    list1.append([i] + list(map(int,input().split())))

list2 = dp(list1)
list2.sort(key=ig(1,2))
city_number = 0
list2[0].append(city_number)
for i in range(1,m):
    if list2[i][1] == list2[i-1][1]:
        city_number += 1
        list2[i].append(city_number)
    else:
        city_number = 0
        list2[i].append(city_number)
list2.sort(key=ig(0))
for i in range(m):
    print("{0:06d}".format(list2[i][1])+"{0:06d}".format(list2[i][3]+1))

Measured memory_bytes: 127220
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c) <= d || abs(a-b) <= d && abs(b-c) <= d){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//いちほ

#include "bits/stdc++.h"
using namespace std;

long long int mod=1e9+7;
int n;
vector<int> a(100010);
vector<int> bit(100010);

int sum(int i){
  int s=0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}

void add(int i,int x){
  while(i<=n){
    bit[i]+=x;
    i+=i&-i;
  }
}

int main(){
  int a,b;
  cin>>a>>b;
  cout<<a-b+1<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=1e6;
ll d[mm];
int main()
{
	ll n,m,i,j,k,kk,a,b,t;
    cin>>m>>n;
    for(i=0;i<n;i++)
    {
    	cin>>a;
    	m-=a;
	}
	if(m>=0)
	cout<<m<<endl;
	else
	cout<<-1<<endl;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int main()
{   
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a>b)
        swap(a,b);
    if(a>c)
        swap(a,c);
    if(b>c)
        swap(b,c);
    printf("%d %d %d\n",a,b,c);
    return 0;
}


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

  int main()
  {
  
   int x1 , y1 , x2 ,y2;   
   scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
   
   int x = x2 - x1;
   int y = y2 - y1;
   printf("%d %d %d %d",x2 - y,  y2+ x,  x1 - y, y1 + x );


    return 0;
  }
  



Measured memory_bytes: 128
#include <stdio.h>

void bubblesor(int *arr, int n);

int main(){
	int n,k,i,ans=0;
	scanf("%d %d", &n, &k);
	int arr[n];

	for(int z=0;z<n;z++){
		scanf("%d", &arr[z]);
	}

	bubblesort(arr, n);

	for(i=0;i<k;i++){
		ans = ans+ arr[i];
	}

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



}

void bubblesort(int *arr, int n){
	int i,j,temp;
	for(i=0;i<n-1;i++){
		for(j=0;j<n-1;j++){
			if(arr[j] > arr[j+1]){
				temp = arr[j];
				arr[j] = arr[j+1];
				arr[j+1] = temp;
			}
		}
	}
}

Measured memory_bytes: 1696
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
typedef long long ll;
using namespace std;

int main() {
    ll n; cin >> n;
    ll k; cin >> k;
    vector<ll> h;
    for (int i = 0; i < n; i++) {
        ll _h; cin >> _h;
        h.push_back(_h);
    }
    sort(h.begin(), h.end());
    ll ans = 1000000000;
    ll len = n - k + 1;
    for (int i = 0; i < len; i++) {
        ll diff = h[i+k-1] - h[i];
        ans = min(ans, diff);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,g=0;
    cin >> a >> b >> c;
    for(int x=a; x<=b; x++){
        if(c%x==0){
            g++;
        }
    }
    cout << g << endl;
}



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

int main(){
	int n,m;
	cin >> n >> m;
	vector<pair<int,int>> c[100005];
	REP(i,m){
		int p,y;
		cin >> p >> y;
		c[p].emplace_back(y, i);
	}
	vector<string> ans(m+1);
	REP(i,n){
		sort(c[i].begin(),c[i].end());
		rep(j, c[i].size()){
			int id = c[i][j].second;
			string s = to_string(i);
			string t = to_string(j+1);
			rep(k,6-s.size()){
				ans[id] += '0';
			}
			ans[id] += s;
			rep(k,6-t.size()){
				ans[id] += '0';
			}
			ans[id] += t;
		}
	}
	REP(i,m){
		cout << ans[i] << endl;
	}
    return 0;
}



Measured memory_bytes: 12416
#include<stdio.h>
char str[1024];
int var[20];
int cur=0;
int form(){
    if(str[cur]=='T'){cur++;return 1;}
    if(str[cur]=='F'){cur++;return 0;}
    if(str[cur]>='a'&&str[cur]<='z'){cur++;return var[str[cur-1]-'a'];}
    
    if(str[cur]=='-'){
        cur++;
        int tmp=form();
        return !tmp;
    }
    if(str[cur]=='('){
        cur++;
        int L=form();
        int R;
        if(str[cur]=='+'){
            cur++;
            R=form();
            cur++;
            return L||R;
        }else if(str[cur]=='*'){
            cur++;R=form();
            cur++;
            return L&&R;
        }else{
            cur+=2;R=form();
            cur++;
            return (!L)||(L&&R);
        }
    }
    return 0;
}
int main(){
    while(1){
        scanf("%s",str);
        if(str[0]=='#')return 0;
        int ok=1;
        for(int i=0;i<(1<<11);i++){
            cur=0;
            for(int j=0;j<11;j++){
                if(i&(1<<j))var[j]=1;
                else var[j]=0;
            }
            int L=form();
            cur++;
            int R=form();
            if(L!=R){ok=0;break;}
        }
        if(ok)printf("YES\n");
        else printf("NO\n");
    }
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

ll RepeatSquaring(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2);
        return t*t;
    }
    return N * RepeatSquaring(N, P-1);
}

int main(){
    ll N,P;
    cin >> N >> P;
    if(N==1){
        cout << P << endl;
        return 0;
    }
    if(N>=40){
        cout << 1 << endl;
        return 0;
    }
    ll ans = 1;
    for(ll i=2;i*i<=P;i++){
        //i^Nで割り切れるかcheck
        ll iN = RepeatSquaring(i,N);
        if(iN>P) break;
        if(P%iN==0){
            ans = max(ans,i);
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	string t;
	cin >> t;
	int cntl = 0, cntr = 0;
	for (int i = 0; i < n; i++) {
		int l1 = min(s[i].length(), t.length());
		bool flag = false;
		for (int j = 0; j < l1; j++) {
			if (s[i][j] == '?') {
				if (t[j] == 'a' || t[j] == 'z') continue;
				flag = true;
				break;
			}
			if (s[i][j] == t[j]) continue;
			else if (s[i][j] < t[j]) cntl++;
			else cntr++;
			flag = true;
			break;
		}
		if (flag) continue;
		if (s[i].length() == t.length()) continue;
		else if (t.length() > l1) cntl++;
		else cntr++;
	}

	for (int i = cntl + 1; i <= n + 1 - cntr; i++) {
		cout << i << (i + cntr == n + 1 ? "\n" : " ");
	}
	return 0;
}

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

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

    let mut count = 0;

    for b in 1..=n {
        if b > k {
            let d = n / b;
            let r = n % b;
 
            count += (b - k) * d;
            if r >= k {
                count += r - k;
                if k != 0 {
                    count += 1;
                }
            }
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2120
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  n = n % 10;
  if (n == 3)
    cout << "bon" << endl;
  else if (n == 0 || n == 1 || n ==6 || n == 8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N + 100);
  for (int i = 0; i< N; i++) cin >> A.at(i);
  
  int count = 0;
  bool exit_odd = false;
  while (true) {
    //bool exit_odd = false;
    for (int i = 0; i < N; i++) {
      if (A.at(i) % 2 != 0) exit_odd = true;
    }
    
    if (exit_odd) break;
    
    for (int i = 0; i < N; i++) A.at(i) /= 2;
    count++;
  }
   
  cout << count << endl;
}

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

def gcd(a, b):
  if b > a:
    a, b = b, a
  if b == 0:
    return a
  red = a % b
  if red == 0:
    return b
  else:
    return gcd(red, b)

L = [0]
for i in range(0, N):
  L.append(gcd(A[i], L[-1]))
  
R = [0]
for i in range(N-1, -1, -1):
  R.append(gcd(A[i], R[-1]))
R = list(reversed(R))
#print(L)
#print(R)

result = 0
for i in range(N):
  #print(L[i], R[i+2], i, i+2)
  g = gcd(L[i], R[i+1])
  #print(g)
  result = max([g, result])
  
print(result)

Measured memory_bytes: 14584
#include <stdio.h>

int main(void) {
  int a, b, c, i, cnt;

  scanf("%d %d %d", &a, &b, &c);

  for (i = a; i <= b; i++){
    if(c % i == 0){
        cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 2120
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main() {

	int N;
	cin>>N;
	for(int i=0;7*i<=N;i++){
		if((N-7*i)%4==0){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;

	return 0;
}


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

int main() {
  int N,sum,A;
  cin>>N;
  sum=0;
  A=0;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  for(int i=0;i<N;i++){
    sum+=vec.at(i);
  }
  vector<int> weight(N);
  for(int T=0;T<N;T++){
    for(int i=0;i<T;i++){
      A+=vec.at(i);
    }
    weight.at(T)=A;
    A=0;
  }
  vector<int> answer(N);
  for(int i=0;i<N;i++){
    answer.at(i)=abs(sum-weight.at(i)*2);
  }
  sort(answer.begin(),answer.end());
  cout<<answer.at(0)<<endl;
}

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

using namespace std;

class Solution {
public:
	void solve() {
		int n, m;
		cin >> n >> m;
		for (int i = 0; i < m; i++) {
			int a;
			cin >> a;
			n -= a;
		}
		if (n < 0) n = -1;
		cout << n << "\n";

		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する

bool largest(ll a, ll b, ll c, ll d) {
    return a >= b && a >= c && a >= d;
}

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

    int N;
    cin >> N;

    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];

    sort(all(A));
    if (N <= 2) {
        cout << abs(A[1] - A[0]) << endl;
        return 0;
    }
    if (N <= 3) {
        sort(all(A));
        ll kouho1 = abs(A[2] - A[0]) + abs(A[1] - A[0]);
        ll kouho2 = abs(A[0] - A[2]) + abs(A[1] - A[2]);
        cout << max(kouho1,kouho2) << endl;
        return 0;
    }


    ll C = A[0];
    vector<ll> L, R;

    L.push_back(A[N - 1]);
    R.push_back(A[N - 2]);

    int lpt = 1;
    int rpt = N - 3;

    while (lpt <= rpt) {
        ll val1 = abs(L.back() - A[lpt]);
        ll val2 = abs(L.back() - A[rpt]);
        ll val3 = abs(R.back() - A[lpt]);
        ll val4 = abs(R.back() - A[rpt]);

        if (largest(val1, val2, val3, val4)) {
            L.push_back(A[lpt]);
            lpt++;
        } else if (largest(val2, val1, val3, val4)) {
            L.push_back(A[rpt]);
            rpt--;
        } else if (largest(val3, val1, val2, val4)) {
            R.push_back(A[lpt]);
            lpt++;
        } else if (largest(val4, val1, val2, val3)) {
            R.push_back(A[rpt]);
            rpt--;
        } else {
            return -1;
        }
    }

    vector<ll> arr;
    for (int i = L.size() - 1; i >= 0; --i) {
        arr.push_back(L[i]);
    }
    arr.push_back(C);
    for (int i = 0; i < R.size(); ++i) {
        arr.push_back(R[i]);
    }

    ll ans = 0ll;
    for (int i = 0; i < arr.size() - 1; ++i) {
        ans += abs(arr[i + 1] - arr[i]);
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()
int dp[1100][1100];

int main() {
	ll n,ans;
	while (cin >> n) {
		ans = 0;
		REPO(i, (600 - n) / n) ans += i * n* i* n * n;
		cout << ans << endl;
	}
}


Measured memory_bytes: 3008
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    #a.insert(0,0)
    s=[0]*(2*n+1)
    sign=1
    for i in range(2*n):
        j=i%n
        s[i+1]=s[i]+sign*a[j]
        sign=sign*(-1)

    ans=[]
    sign=1
    for i in range(n):
        ans.append( sign*(s[n+i]-s[i]) )
        sign=sign*(-1)
    return ans

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(' '.join(map(str,ans)))


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

int main()
{
  cin >> s;

  int n = s.length();

  rep(i, n)
  {
    if (s[i] == '?')
    {
      s[i] = 'D';
    }
  }

  cout << s << endl;
}


Measured memory_bytes: 3752
#include <iostream>
#include <cstdio>
#define INF 0x7f7f7f7f

using namespace std;

int n;
int a[100];
int sign=0;
int s=0;
int mi;
int ans=0;
int ma=0;

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(ma<a[i])
            ma=a[i];
        s+=a[i];
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]!=a[i+1])
        {
            sign++;
            break;
        }
    }
    if(sign==0)
    {
        printf("0\n");
        return 0;
    }
    mi=INF;
    for(int i=s/n;i<=ma;i++)
    {
        ans=0;
        for(int j=0;j<n;j++)
        {
           ans+=(i-a[j])*(i-a[j]);
        }
        mi=min(mi,ans);
    }
    printf("%d\n",mi);
    return 0;
}


Measured memory_bytes: 256
#数学的に解く
w,h,n = map(int,input().split())
cnt = 0
X = 0
Y = 0
while(cnt < n):
    x,y,a = map(int,input().split())
    
    if(a == 1):
        X = max(X,x)
    elif(a == 2):
        w = min(w,x)
    elif(a == 3):
        Y = max(Y,y)
    elif(a == 4):
        h = min(h,y)
    #print(w,h,X,Y)
    cnt += 1
print(max(w-X,0)*max(h-Y,0))

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;
const int   mod = 998244353;

void add(int&a,int b)   {   a += b; if (a >= mod)   a -= mod;   }
void sub(int&a,int b)   {   a -= b; if (a <  0)     a += mod;   }

int mul(int a,int b)    {   return  1ll * a * b % mod;  }
int Pow(int a,int b)    {
    int ans = 1;
    while  (b)  {
        if (b & 1)  ans = mul(ans,a);
        a = mul(a,a);   b >>= 1;
    }
    return  ans;
}

typedef pair<int,int>   ii;
typedef pair<ii ,int>   pii;

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

    int n;  cin >> n;

    vector<ii>  P(n);
    
    for(ii &A : P)
        cin >> A.X,
        cin >> A.Y;
    
    vector<pii> Line;

    for(ii  A : P)
    for(ii  B : P)  {
        if (A == B) break;

        int dx = A.Y - B.Y;
        int dy = B.X - A.X;

        int g = __gcd(abs(dx),abs(dy));

        dx /= g;
        dy /= g;

        if (dx < 0)     dx = -dx, dy = -dy;
        if (dx == 0 &&  dy < 0)   dy = -dy;

        Line.pb(ii(dx,dy),dx * A.X + dy * A.Y);
    }
    sort(all(Line));
    Line.erase(unique(all(Line)),Line.end());

    int ans = Pow(2,n);
    sub(ans,n + 1);

    for(pii d : Line)   {
        int a = d.X.X;
        int b = d.X.Y;

        int cnt = 0;

        for(ii  A : P)  cnt += (a * A.X + b * A.Y == d.Y);

        sub(ans,Pow(2,cnt));
        add(ans,cnt + 1);
    }
    cout << ans << endl;
}

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

int main() {
  int N;

  std::cin >> N;

  std::vector<int> X(N);
  std::vector<int> C(N);

  for (int i=0; i<N; i++)
    std::cin >> X[i];

  for (int i=0; i<N; i++)
    std::cin >> C[i];

  int ans = 0;
  for (int i=0; i<N; i++) {
    if (X[i] - C[i] > 0)
      ans += X[i] - C[i];
  }

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

  return 0;
}


Measured memory_bytes: 384
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

// #define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

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

  double ans = 0.;
  for (int i = 0; i < n; ++i) {
    ans += 1. / static_cast<double>(a[i]);
  }
  ans = 1. / ans;
  cout << ans << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
B = [tuple(map(int, input().split())) for _ in range(M)]
B.sort()
r = 0
res = 0
for a, b in B:
    if a >= r:
        res += 1
        r = b
    else:
        r = min(r, b)
print(res)


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

int main() {
    int input[10];
    for(int i=0; i<10; ++i) {
        cin >> input[i];
    }
    sort(begin(input), end(input));
    cout << input[9] << "\n" << input[8] << "\n" << input[7] << endl;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  ll a, b;
  cin >> a >> b;
  if(a * b % 2 == 0)
  cout << "No" << endl;
  else
    cout << "Yes" << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=998244353;
vector<lint> zeta(vector<lint> const& array){
    int n=array.size();
    vector<lint> res(array);
    vector<bool> memo(n,true);
    for(int i=2;i<n;++i){
        if(!memo[i])continue;
        for(int j=(n-1)/i;j>0;--j){
            memo[i*j]=false;
            res[j]+=res[i*j];
            res[j]%=MOD;
        }
    }
    return res;
}
vector<lint> mebius(vector<lint> const& array){
    int n=array.size();
    vector<lint> res(array);
    vector<bool> memo(n,true);
    for(int i=2;i<n;++i){
        if(!memo[i])continue;
        for(int j=1;i*j<n;++j){
            memo[i*j]=false;
            res[j]+=MOD-res[i*j];
            res[j]%=MOD;
        }
    }
    return res;
}
long long modinv(long long a, long long m) {
        long long b = m, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }

signed main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int num=2000005;
  vector<lint> array(num,0);
  rep(i,n){
      array[a[i]]+=a[i];
      array[a[i]]%=MOD;
  }
  vector<lint> z=zeta(array);
  rep(i,0){
      z[i]%=MOD;
  }
  vector<lint> z2(z);
  vector<lint> C(num);
  rep(i,num){
      C[i]=z[i]*z2[i];
  }
  vector<lint> c=mebius(C);
  lint res=0;
  rep1(i,num-1){
      res+=c[i]*modinv(i,MOD);
      res%=MOD;
  }
  rep(i,n){
      res+=MOD-a[i];
      res%=MOD;
  }
  res*=modinv(2,MOD);
  res%=MOD;
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 82388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> V;
const long long MOD=1000000007LL;
const long long INFL=1LL << 60;
const int INF=1<<29;


int main() {
    int N,Q;
    string S;
    cin >>N>>Q;
    cin >>S;
    V ruiseki(N+1,0);
    for(int i=1;i<=N;i++){
        ruiseki.at(i)=ruiseki.at(i-1);
        if(S[i-1]=='A'&&S[i]=='C')ruiseki.at(i)++;
    }
    for(int i=0;i<Q;i++){
        int l,r;
        cin >>l>>r;
        l--;r--;
        cout << ruiseki[r]-ruiseki[l]<<endl;
    }

    return 0;

}

Measured memory_bytes: 1408
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
	LL kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
LL k,n,a[1000222];
int main()
{
	k=read();n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	LL ma=a[1]+k-a[n];
	for(int i=2;i<=n;++i)ma=max(ma,a[i]-a[i-1]);
	printf("%lld\n",k-ma);
}

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

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define LOG 19
#define off 2

#define mod 1000000007LL

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less< i64 >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 200005

i64 dp1[maxn] , dp2[maxn] ;

vector < pair<int,int> > vp ;
vector < pair<int,int> > zero ;

bool comp( pair<int,int> a , pair<int,int> b )
{
    return 1LL*a.xx*(b.yy+1) > 1LL*b.xx*(a.yy+1) ;
}

int main()
{
    int n , T ;

    scanf("%d %d",&n,&T) ;

    for(int i=1 ; i<=n ; i++)
    {
        int a , b ;
        scanf("%d %d",&a,&b) ;
        if(a!=0) vp.pb( mp( a , b ) ) ;
        else zero.pb(mp(a,b)) ;
    }

    sort( vp.begin() , vp.end() , comp ) ;
    sort( zero.begin() , zero.end() ) ;

    int mx1 = 35 ;

    for(int i=0 ; i<=mx1+2 ; i++) dp1[i] = T+1 ;

    dp1[0] = 0 ;

    for(int i=0 ; i<vp.size() ; i++)
    {
        for(int j=mx1 ; j>=1 ; j--)
        {
            if( 1LL*(dp1[j-1]+1)*vp[i].xx + vp[i].yy + dp1[j-1] + 1 < dp1[j] )
            {
                dp1[j] = 1LL*(dp1[j-1]+1)*vp[i].xx + vp[i].yy + dp1[j-1] + 1 ;
            }
        }
    }

    for(int i=0 ; i<zero.size() ; i++)
    {
        dp2[i+1] = dp2[i] + zero[i].yy+1 ;
    }

    int ans = 0 ;

    for(int i=0 ; dp1[i] <= T ; i++)
    {
        for(int j=0 ; j<= (int)zero.size() ; j++)
        {
            if( dp1[i] + dp2[j] <= T ) ans = max(ans,i+j) ;
        }
    }

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

    return 0 ;
}


Measured memory_bytes: 3440
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
A.sort()

def power(a, b):
	if b == 0:
		return 1
	elif b == 1:
		return a % 1000000007
	elif b % 2 == 0:
		return (power(a, b//2) ** 2) % 1000000007
	else:
		return (power(a, b//2) ** 2 * a) % 1000000007
 
def divide(a, b):
	return (a * power(b, 1000000005)) % 1000000007


#階乗の逆元を求める
fac_lim = 100000
fac = [None]*(fac_lim+1)
fac[0] = 1
for i in range(fac_lim):
    fac[i+1] = fac[i] * (i+1)
    fac[i+1] = fac[i + 1] % 1000000007

fac_inv = [None]*(fac_lim+1)
fac_inv[fac_lim] = power(fac[fac_lim], 1000000005)
for i in range(fac_lim, 0, -1):
    fac_inv[i-1] = (fac_inv[i] * i)  % 1000000007

def conv(a, b):
    return (fac[a] * fac_inv[a-b] * fac_inv[b]) % 1000000007

MOD = 10**9 + 7
ans = 0
if K > 1:
	for i in range(N):
		if i >= K-1:
			ma = conv(i, K-1) * A[i]
		else:
			ma = 0
		if N - i - 1 >= K-1:
			mi = conv(N-i-1, K-1) * A[i]
		else:
			mi = 0
		ans += ma-mi
		ans %= MOD
print(ans)

Measured memory_bytes: 69288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    ll a[n];
    rep(i, 0, n){
        cin >> a[i];
    }

    ll l = 0, r = 0;
    ll sum = 0;
    ll ans = 0;

    while(r < n){
        if((sum & a[r]) == 0){
            sum += a[r];
            r++;
            ans += r - l;
        }else if(r == l){
            r++;
            l++;
        }else{
            sum -= a[l];
            l++;
        }
    }

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


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<int> l(n);
  vector<int> target{a, b, c};
  for(int i = 0; i < n; ++i)
  {
    cin >> l[i];
  }

  sort(l.begin(), l.end());
  sort(target.begin(), target.end());

  int ans = 1 << 30;
  do
  {
    do
    {
      int ti = 0;
      int cost = 0;
      int now_len = 0;
      for(int li = 0; li < n; ++li)
      {
        if(ti >= 3) continue;
        now_len += l[li];
        int guchoku_cost = abs(now_len - target[ti]);
        int gattai_cost = (li + 1 < n) ? abs(now_len + l[li + 1] - target[ti]) + 10 : 1000000;

        if (guchoku_cost < gattai_cost)
        {
          cost += guchoku_cost;
          now_len = 0;
          ti++;
        }
        else
        {
          cost += 10;
        }
      }
      if (ti >= 3)
      {
        ans = min(ans, cost);
      }
    } while(next_permutation(l.begin(), l.end()));
  } while(next_permutation(target.begin(), target.end()));
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3616
x, y, z, k = map(int, input().split())

dx = list(map(int, input().strip().split()))
dy = list(map(int, input().strip().split()))
dz = list(map(int, input().strip().split()))

dx.sort(reverse=True)
dy.sort(reverse=True)
dz.sort(reverse=True)

# print(dx, dy, dz)
xyz = []
for i in range(x):
    if i + 1  > k:
        break
    for j in range(y):
        if (i + 1) * ( j+ 1) > k:
            break
        for t in range(z):
            if (i + 1) * (j + 1) * (t + 1) > k:
                break
            xyz.append(dx[i] + dy[j] + dz[t])

xyz.sort(reverse=True)
# print(len(xyz))

for e in xyz[:k]:
    print(e)

Measured memory_bytes: 8732
#include<bits/stdc++.h>
using namespace std;
bool b[100005];
int f[100005];
int main(){
	int m,n;
	cin>>m>>n;
	for(int i=1,k;i<=n;i++)
	 {cin>>k;
	  b[k]=1;
	 }
	if(!b[1])f[1]=1;
	if(!b[2])f[2]=f[1]+1;
	for(int i=3;i<=m;i++)
	 {if(b[i])continue;
	  f[i]=(f[i-1]+f[i-2])%1000000007;
	 }
	cout<<f[m]<<endl;
}

Measured memory_bytes: 768
//20190915
//Naru
#include<iostream>
using namespace std;

int main() {
  string S;
  cin >> S;
  for(int i=0; i<S.size(); i++) {
    if((i+1)%2 == 0) {
      if(S[i] != 'L' && S[i] != 'U' && S[i] != 'D') {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if(S[i] != 'R' && S[i] != 'U' && S[i] != 'D') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

const ll N = 12;
const ll M = 1000 + 4;
ll dp[(1 << N) + 10];

ll p[M], q[M];

int main(){
  fastio

  ll n, m;
  cin >> n >> m;



  for(int i = 1; i <= m; i++){
    ll a, b;
    cin >> a >> b;
    ll mask = 0;
    for(int j = 1; j <= b; j++){
      ll k;
      cin >> k;
      k--;
      mask ^= (1 << k);
    }
    p[i] = mask;
    q[i] = a;
  }

  ll need = (1 << n) - 1;

  fill(dp, dp + (1 << N) + 10, INF);
  dp[0] = 0;


  for(ll i = 0; i <= need; i++){
    for(ll j = 1; j <= m; j++){
      dp[i | p[j]] = min(dp[i | p[j]], dp[i] + q[j]);
    }
  }

  cout << (dp[need] == INF ? -1 : dp[need]) << '\n';


  ktj();
}


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

signed main() {
	int n, k, s;
	cin >> n >> k >> s;
	for (int i = 0; i < k; ++i) {
		cout << s << " ";
	}
	if (s > n - k) {
		for (int i = 0; i < n - k; ++i) {
			cout << 1 << " ";
		}
	}
	else {
		for (int i = 0; i < n - k; ++i) {
			cout << (int)1e9 << " ";
		}
	}
	cout << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <string>
using namespace std;

int main() {

    int n;
    cin >> n;

    vector<string> mus_name;
    vector<unsigned int> mus_time;

    for (int i = 0; i < n; i++) {
        string n_s;
        cin >> n_s;
        mus_name.push_back(n_s);
        int t_i;
        cin >> t_i;
        mus_time.push_back(t_i);
    }

    string sleep_man;
    cin >> sleep_man;

    bool isnotsleep = false;
    int cnt = 0;
    for (int k = 0; k < n; k++) {
        if (isnotsleep)
            cnt += mus_time.at(k);
        if (  mus_name.at(k) == sleep_man) {
            isnotsleep = true;
        }
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

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

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1 << 29; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

void dfs(vector<vector<int>>& g, vector<int>& order, vector<bool>& used, int v) {
	if (used[v]) return;
	else {
		used[v] = true;
		for (auto w : g[v]) dfs(g, order, used, w);
		order.push_back(v);
	}
}

void rdfs(vector<vector<int>>& g, vector<int>& comp, vector<bool>& used, int v, int n) {
	if (used[v]) return;
	else {
		used[v] = true;
		for (auto w : g[v]) rdfs(g, comp, used, w, n);
		comp[v] = n;
	}
}

void scc(vector<vector<int>>& graph) {
	vector<bool> used(graph.size(), false);
	vector<int> order;

	rep(s, graph.size()) dfs(graph, order, used, s);
	reverse(order.begin(), order.end());

	vector<vector<int>> rgraph(graph.size());
	rep(s, graph.size()) {
		for (int t : graph[s]) rgraph[t].push_back(s);
	}

	rep(i,used.size()) used[i] = false;

	int n = 0;
	vector<int> comp(graph.size(),-1);
	for (int s : order) {
	  //debug(comp);
		if (!used[s]) n++; 
		rdfs(rgraph, comp, used, s, n);
	}
  cout << n << endl;
	//debug(comp);
}

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

	vector<vector<int>> graph(n, vector<int>());
	rep(i,m) { 
	  int x, y, z;
		cin >> x >> y >> z;
	  graph[x-1].push_back(y-1);
		graph[y-1].push_back(x-1);
	}

	scc(graph);
}


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

using namespace std;
#define inf 1e18
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 402;

ll dp[maxn][maxn];

ll a[maxn];
ll pref[maxn];

ll price(int depan, int belakang) {
	if(depan > belakang){return 0;}
	return pref[belakang] - pref[depan-1];
}

ll solve(int depan, int belakang) {
	// printf("depan: %d belakang: %d\n",depan, belakang);
	if(depan >= belakang) {
		// printf("sekarang depan: %d belakang: %d\n",depan, belakang);	
		return 0;
	}
	if(dp[depan][belakang] != -1){return dp[depan][belakang];}
	int i,j;
	ll ans = inf;
	for(i=depan;i<belakang;i++){
		// ll ans1 = solve(depan, i-1) + solve(i+1, belakang) + price(depan, belakang);
		ll ans2 = solve(depan, i) + solve(i+1, belakang) + price(depan, i) + price(i+1, belakang);
		ans = min(ans, ans2);
	}
	// for(i=depan+1;i<=belakang;i++){
	// 	// ll ans1 = solve(depan, i-1) + solve(i+1, belakang) + price(depan, belakang);
	// 	ll ans2 = solve(depan, i-1) + solve(i, belakang) + price(depan, i-1) + price(i, belakang);
	// 	ans = min(ans, ans2);
	// }
	return dp[depan][belakang] = ans;
}

void min_self(ll &a, ll b){
	a = min(a,b);
}

int main(){
	int n,i,j;
	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		pref[i] = a[i];
		pref[i] += pref[i-1];
	}
	memset(dp, -1, sizeof dp);
	// for(i=1;i<=n;i++){
	// 	for(j=1;j<=n-i;j++){
	// 		int depan = j, belakang = j+i;
	// 		dp[depan][belakang] = inf;
	// 		for(int k=depan;k<belakang;k++){
	// 			min_self(dp[depan][belakang], price(depan, k) + price(k+1, belakang) + dp[depan][k] + dp[k+1][belakang]);
	// 			// printf("sekarang k: %d dp[%d][%d]: %lld, price: %lld %lld\n",k, depan, belakang, dp[depan][belakang], price(depan, k), price(k+1, belakang));	
	// 		}
	// 		// printf("dp[%d][%d]: %lld\n",depan, belakang, dp[depan][belakang]);
	// 	}
	// }
	printf("%lld\n",solve(1,n));
	return 0;
};

Measured memory_bytes: 1536
# coding: utf-8
def get_ln_inputs():
    return input().split()


def main():
    _ = get_ln_inputs()
    S = get_ln_inputs()[0]

    level = 0
    index = 0
    while index < len(S):
        if S[index] == "(":
            index += 1
            level += 1
            continue
        if S[index] == ")":
            if level > 0:
                index += 1
                level -= 1
                continue
            S = "(" + S
            index += 2
    print(S + (")" * level))


main()

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

#define INF64 1LL << 60;
#define INF32 1 << 29;

using namespace std;

void execute()
{
	int N, A, B;
	int judge = 0;
	int ans = 0;
	cin >> N >> A >> B;

	for (int i = 1; i <= N; i++)
	{
		judge++;

		if (i % 10000 == 0)
			judge -= 9 * 4;
		else if (i % 1000 == 0)
			judge -= 9 * 3;
		else if (i % 100 == 0)
			judge -= 9 * 2;
		else if (i % 10 == 0)
			judge -= 9;

		if (A <= judge && judge <= B)
			ans += i;
	}

	cout << ans << endl;

	return;
}

int main()
{
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
//Volume2-0208
import java.util.Scanner;

class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int    n;
		char[] ch;
		String ans;
		String[] map   = {"0","1","2","3","5","7","8","9"};

		while((n = sc.nextInt())!=0){
			ans = "";
			ch = Integer.toOctalString(n).toCharArray();
			for(int i=0;i<ch.length;i++){
				ans += map[Character.digit(ch[i], 10)];
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 61152
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem A

if __name__ == '__main__':
    X, Y = list(map(str, input().split()))
    HEX = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}

    X_value = HEX[X]
    Y_value = HEX[Y]

    if X_value > Y_value:
        print('>')
    elif X_value < Y_value:
        print('<')
    else:
        print('=')


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, q;
	string S;
	cin >> n >> q >> S;
	int l, r;
	vector<int> rem(100000, 0);
	for (int i = 1; i < n; ++i) {
		rem[i] = rem[i - 1];
		if (S[i] == 'C' && S[i - 1] == 'A') {
			rem[i]++;
		}
	}
	rep(i, q) {
		cin >> l >> r;
		cout << rem[r - 1] - rem[l - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1488
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		Deque<Long> deq = new ArrayDeque<>();
		for(long i = 1; i <= 9; i++)
			deq.offer(i);
		for(int i = 0; i < K-1; i++) {
			long x = deq.poll();
			if(x % 10 != 0)
				deq.offer(10*x+x%10-1);
			deq.offer(10*x+x%10);
			if(x % 10 != 9)
				deq.offer(10*x+x%10+1);
		}
		System.out.println(deq.poll());
	}

}


Measured memory_bytes: 30036
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)  for( ll i = (a); i < (b); i++ )
#define REP(i,n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >  cp3;
#define fi first
#define se second
#define sec se.fi
#define thr se.se
const ll mod = 1000000007;
//              123456789

int main(){
	
	int a, b;
	
	REP(i,7){
		cin >> a >> b;
		
		cout << a-b << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3088