akhauriyash/Code-Regression huggingface dataset:
import numpy as np
import sys
sys.setrecursionlimit(200000)

def decide_col(colors, edges, node, org, excl_color,max_col):
    if len(edges[node]) > 1:
        i = 1
        for elem in edges[node]:
            next_node = elem[0]
            ind = elem[1]
            if next_node != org:
                while i == excl_color:
                    i = i%max_col + 1
                colors[ind] = i
                decide_col(colors, edges, next_node, node, i,max_col)
                i += 1
    

def det_color(N,edges,start,max_col):
    colors = [0]*(N-1)
    i=1
    for elem in edges[start]:
        node = elem[0]
        ind = elem[1]
        colors[ind] = i
        decide_col(colors, edges, node, start, i, max_col)
        i += 1
    return colors
        

N = int(input())
edges = {}
edge_list = []

for i in range(N):
    edges[i] = []
count = [0]*N

for i in range(N-1):
    A, B = map(int,input().split())
    edge_list.append([A-1,B-1])
    edges[A-1].append([B-1,i])
    edges[B-1].append([A-1,i])
    count[A-1] += 1
    count[B-1] += 1

max_col = max(count)
print(max_col)
start_ind = np.argmax(count)
if type(start_ind)==list:
    start = start_ind[0]
else:
    start = start_ind
colors = det_color(N,edges,start,max_col)

for i in range(N-1):
    print(colors[i])

Measured memory_bytes: 104656
x, y = map(int, input().split())
mod = 10**9+7 
def check(x, y):
  if (2*y-x)/3 < 0 or (2*x -y)/3 < 0:
    return False
  if (x+y)%3 != 0:
    return False
  return True

def comb(n, r, mod):
    r = min(r, n-r)
    x, y  = 1, 1
    for i in range(1, r+1):
      y =  y* i % mod
      x =  x* (n+1-i) % mod
    return x * pow(y, mod-2, mod) % mod
  
if check(x, y):
  print(comb((2*y-x)//3+(2*x -y)//3, (2*y-x)//3, mod))
else:
  print(0)

Measured memory_bytes: 3064
import queue
N = int(input())
alist = [[] for _ in range(N+1)]
d = {}
q = queue.Queue()

for _ in range(N-1):
    u, v, w = map(int, input().split())
    alist[u].append(v)
    alist[v].append(u)
    d[(u, v)] = w

q.put(1)
d[(1, 1)] = 0
seen = [False]*(N+1)
seen[1] = True

while not q.empty():
    s = q.get()
    for n in alist[s]:
        if not seen[n]:
            q.put(n)
            seen[n] = True
            d[(1, n)] = d[1, s]+d[tuple(sorted([s, n]))]

for i in range(1, N+1):
    print(d[(1, i)] % 2)


Measured memory_bytes: 105372
ia, ib = map(int, input().split())
sa = str(ia)
sb = str(ib)
sc = sa+sb
c = int(sc)
fc = float(c**0.50)
ic = int(c**0.50)
if abs(fc-ic)<0.0001:
    print('Yes')
else:
    print("No")

Measured memory_bytes: 38384
package main

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

func main() {
	N := nextInt()
	S := nextBytes()

	alpha := []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
	dict := map[byte]byte{}

	for i := 0; i < len(alpha); i++ {
		dict[alpha[i]] = alpha[(i+N)%26]
	}
	for i := 0; i < len(S); i++ {
		fmt.Printf("%c", dict[S[i]])
	}
	fmt.Println()
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 640
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

 */

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005


signed main(){
	fast
	int a, b;
	cin>>a>>b;
	int val = a+b;
	if(val%2==0){
		cout<<val/2<<endl;
	}else{
		cout<<"IMPOSSIBLE"<<endl;
	}

    return 0;
}
    



Measured memory_bytes: 256
#include<iostream>
#include<utility>

typedef long long ll;

using namespace std;

ll A, B, C, D;

ll gcd(ll a, ll b) {
	ll r;
	if (a < b) swap(a,b);
	r = a % b;
	while (r != 0) a = b, b = r, r = a % b;
	return b;
}
ll lcm(ll a, ll b) {
	return (a*b) / gcd(a, b);
}
	int main() {
		ll a,b;
		cin >> A >> B >> C >> D;
		A--;
		a = (A - (A / C) -( A / D) + (A / lcm(C, D)));
		b = (B - (B / C) - (B / D) + (B / lcm(C, D)));
		cout << b-a << endl;
		return 0;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r; i >= l; i--)
#define fw(i, l, r) for (int i = l; i <= r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5;
int n, a[N], dp[N], sum[N];
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 1, n) cin >> a[i];
	dp[0] = 1;
	fw (i, 1, n) {
		if (i == 1 || a[i] != a[i - 1]) add(sum[a[i]], dp[i - 1]);
		add(dp[i], sum[a[i]]);
	}
	cout << dp[n];
	return 0;
}

Measured memory_bytes: 2560
program multiple_of_9
  implicit none
  character(200000) :: s
  integer :: n = 0, i
  read(*,'(a)') s
  do i = 1, len_trim(s)
    n = n + ichar(s(i:i)) - 48
  end do
  write(*,'(a)') trim(merge('Yes', 'No ', mod(n, 9) == 0))
end program multiple_of_9

Measured memory_bytes: 3184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int[] arr = new int[3];
		arr[0] = Integer.parseInt(s[0]);
		arr[1] = Integer.parseInt(s[1]);
		arr[2] = Integer.parseInt(s[2]);
		arr = sorted(arr);
		for(int i = 0 ; i < arr.length; i++){
			System.out.print(arr[i]);
			if(i!= arr.length-1){
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static int[] sorted(int[] array){
		int[] ar = array;
		int temp = 0;
		for(int i = 0 ; i < array.length; i++){
			for(int j = i+1 ; j < array.length;j++){
				if(ar[i] > ar[j]){
					temp = ar[i];
					ar[i] = ar[j];
					ar[j] = temp;
				}
			}
		}
		return ar;
	}

}

Measured memory_bytes: 24348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] enter = new int[n + 1];
		for(int i = 1; i < n + 1; i++) {
			int num = sc.nextInt();
			enter[num] = i;
		}
		for(int i = 1; i < n + 1; i++) {
			System.out.print(enter[i] + " ");
		}
		System.out.println();
	}

}


Measured memory_bytes: 62536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
#define INF 1000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  int n;
  cin >> n;
  vector<ll> a(n+1);
  ll reqs = 0;
  for (int i = 0; i < n+1; i++) {
    cin >> a[i];
    reqs += a[i];
  }
  ll nodes = 1;
  ll ans = 0;
  for (int depth = 0; depth <= n; depth++) {
    if (nodes < a[depth]) {
      cout << -1 << endl;
      return 0;
    }
    ans += nodes;
    reqs -= a[depth];
    nodes -= a[depth];
    nodes = min(reqs, nodes * 2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3992
N,X,D=map(int,input().split())
f,c,r={},[0]*10**8,0
for x,y,z in sorted((((N-k)*j+~-k)*k//2+k*X//D,j,k*X%D)if D else(0,j,k*(X!=0))for k in range(N+1)for j in[0,2]):
 if c[z]+y<1:
  f[z]=x
 r+=(x-f[z]+1)*(c[z]<y)
 c[z]-=y-1
print(r)

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

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

    vector<int> A(3);
    REP(i, 3) cin >> A[i];

    sort(A.begin(), A.end());

    int d1 = A[2] - A[1];
    int d2 = A[2] - A[0];

    int ans = 0;
    if(d1 % 2 == d2 % 2){
        ans += d1 / 2;
        ans += d2 / 2;
        if(d1 % 2){
            ans++;
        }
    }else{
        ans++;
        if(d1 % 2) d1++;
        ans += d1 / 2;
        if(d2 % 2) d2++;
        ans += d2 / 2;
    }
    
    cout << ans << endl;    

    return 0;
}

Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.buffer.readline


N, K = map(int, input().split())
X = list(map(int, input().split()))

orient = bisect.bisect_left(X, 0)
X_posi = [float('inf')] * N
X_nega = [float('inf')] * N

for i in range(N-orient):
    X_posi[i] = X[orient+i]

for i in range(orient):
    X_nega[i] = -X[orient - i - 1]

ans = float('inf')
for i in range(K+1):
    if i == 0:
        ans = min(X_nega[K-i-1], ans)
    elif i == K:
        ans = min(X_posi[i-1], ans)
    else:
        ans = min(ans, X_posi[i-1] + X_nega[K-i-1] + min(X_posi[i-1], X_nega[K-i-1]))
print(ans)


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD =  1000000007;
const ll INF = 1LL << 60;


int main() {
    int a, b, c; cin >> a >> b >> c;
    int k; cin >> k;

    while(b <= a && 0 < k){
        b *= 2;
        k--;
    }
    while(c <= b && 0 < k){
        c *= 2;
        k--;
    }
    if(a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin >> s;
    ll n = SZ(s);
    ll c = 0;
    ll rec = 0;
    ll rpos = 0;
    vll ans(n, 0);
    rep(i, n){
        c++;
        if(i == n-1 || (i < n-1 && s[i] == 'L' && s[i+1] == 'R')){
            dump(c, i, rpos, rec);
            if(c & 1){
                if((rpos-rec) & 1){
                    ans[rpos] = c/2;
                    ans[rpos+1] = c/2+1;
                }else{
                    ans[rpos] = c/2+1;
                    ans[rpos+1] = c/2;
                }
            }else{
                ans[rpos] = c/2;
                ans[rpos+1] = c/2;
            }
            
            c = 0;
            rec = i+1;
        }
        if(i < n-1 && s[i] == 'R' && s[i+1] == 'L'){
            rpos = i;
        }
    }
    rep(i, n){
        cout << ans[i] << (i < n-1 ? " " : "\n");
    }
    return 0;
}

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

using ll=long long;

const int MAX_V=1000;
const ll INF=1e9+1;

int main(){
    int N,W;
    cin>>N>>W;
    vector<ll> w(N),v(N);
    for(int i=0;i<N;i++) cin>>w[i]>>v[i];

    vector<vector<ll>> dp(N+1,vector<ll>(MAX_V*N+1,INF));
    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=MAX_V*N;j++){
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            if(j+v[i]<=MAX_V*N) dp[i+1][j+v[i]]=min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
        }
    }
    int res=0;
    for(int i=0;i<=MAX_V*N;i++){
        if(dp[N][i]<=W) res=i;
    }
    cout<<res<<endl;
    
    return 0;
}

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


int main(){
	int n, m, x, low=0, high=0, a, c;

    cin >> n >> m >> x;

    for (int i = 0; i < m; i++){
        cin >> a;
        if(a < x) low++;
        else high++;
    }

    c = min(low, high);

    cout << c << endl;


    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<pair<ll,ll>> v(n);
    for(auto& i : v) cin >> i.first >> i.second;

    sort(all(v), [](auto a, auto b){return a.first + a.second < b.first + b.second;});

    int ans = 0;
    ll right = -INF;

    REP(i, n){
        if(right <= v[i].first - v[i].second){
            ans++;
            right = v[i].first + v[i].second;
        }
    }

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


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> Pi;
typedef map<ll,ll> mi;

template<class T> T nrem(T x,T y){return ((x%y)+y)%y;}

#define For(i,a,n) for(int i=a;i<n;++i)
#define For0(i,n) for(int i=0;i<n;++i)
#define For1(i,n) for(int i=1;i<=n;++i)
#define Forl0(i,n) for(ll i=0;i<n;++i)
#define Forl1(i,n) for(ll i=1;i<=n;++i)
#define fi freopen("input.txt","r",stdin);
#define fo freopen("output.txt","w",stdout);
#define pb push_back
#define mp make_pair
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cs 1000005
#define pi acos(-1)
#define INF (int)INFINITY
void in()
{
     #ifndef ONLINE_JUDGE
         freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
     #endif
}

int main()
{  in();
    
  ld a,b;
  
  cin>>a>>b;

  ll x=b;

  ld y=b-x;
  
  cout<<(ll)(a*x+a*y)<<endl;
  

}

Measured memory_bytes: 3724
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

void solve() {
  int k = 38;
  int n = k * (k - 1) + 1;
  vector< vector<int> > g(n);
  for (int i = 0; i < k; i++) {
    g[0].push_back(i);
  }
  for (int i = 1; i < k; i++) {
    g[i].push_back(0);
  }
  for (int i = 0; i < k - 1; i++) {
    for (int j = 0; j < k - 1; j++) {
      g[1 + i].push_back(k + i * (k - 1) + j);
      g[k + i * (k - 1) + j].push_back(1 + i);
      for (int l = 0; l < k - 1; l++) {
        g[k + i * (k - 1) + j].push_back(k + l * (k - 1) + (i * l + j) % (k - 1));
      }
    }
  }
  printf("%d %d\n", n, k);
  for (int i = 0; i < n; i++) {
    assert(sz(g[i]) == k);
    for (int j = 0; j < k; j++) {
      printf("%d ", g[i][j] + 1);
    }
    printf("\n");
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".out", "w", stdout));
#endif
  solve();
#ifdef DEBUG
  eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long n,a,b,r,ma,mi;
    cin>>n>>a>>b;
    ma=max(a,b);
    mi=min(a,b);

    a=mi;
    b=ma;
    if (((b-a)%2==0)or(a==1)or(b==n))
    {
        if ((b-a)%2==0)
            r=min(min(b-1,n-a),(b-a)/2);
        else
            r=min(min(b-1,n-a),(b-a)/2 +1);
    }
    else
    {
    long long dis;
    dis=min(a-1,n-b);
    r=min(b-1,n-a);
        if (a-1<=n-b)
        {
            a-=dis;
            b-=dis;
            r=min(r,dis+(b-a)/2 +1);
        }
        else
        {
            a+=dis;
            b+=dis;
            r=min(r,dis+(b-a)/2 +1);
        }

    }
    cout<<r;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int n;
    cin >> n;

    int g[n][n];
    int w;
    rep (i, n)
    {
        rep (j, n)
        {
            cin >> w;
            if (w < 0) w = 1e9;
            g[i][j] = w;
        }
    }

    u64 ans = 0;
    vs32 MST;
    vs32 remain(n - 1);
    rep (i, n - 1) remain[i] = i + 1;
    MST.push_back(0);
    while (MST.size() < n)
    {
        w = 1e9;
        int node;
        for (int u : MST)
        {
            rep (j, remain.size())
            {
                int v = remain[j];
                if (w > g[u][v])
                {
                    w = g[u][v];
                    node = j;
                }
            }
        }
        MST.push_back(remain[node]);
        swap(remain[node], remain.back());
        remain.pop_back();
        ans += w;
    }

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



Measured memory_bytes: 3176
use std::cmp::max;
use std::collections::BTreeSet;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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 solve(s: String, k: usize) {
    let mut substrs = BTreeSet::new();

    for p in 1..(k+1) {
        for i in 0..(max(s.len() as i32 - p as i32 + 1, 0) as usize) {
            substrs.insert(&s[i..i+p]);
        }
    }

    println!("{}", substrs.iter().nth(k-1).unwrap());
}

fn main() {
    input!{
        s: String,
        k: usize,
    }

    solve(s,k);
}



Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
    int R[MAX], n;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> R[i];
    }
    
    int maxv = -2000000000;
    int minv = R[0];

    for (int i = 1; i < n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int ct=  0;
    char last = '@';
    for (int i = 0; i < n; i++){
        char x;
        scanf(" %c",&x);
        if (x == last) continue;
        else{
            last = x;
            ct++;
        }
    }
    printf("%d",ct);
}


Measured memory_bytes: 256
# AtCoder
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for l in range(K+1):
    for r in range(K-l+1):
        if l+r > N:
            break
        d = K-(l+r)

        j = V[:l]+V[N-r:]
        j.sort()

        for i in range(d):
            if not j:
                break
            elif j[0] >= 0:
                break
            j.pop(0)

        ans = max(ans, sum(j))
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<cstdlib>

int H; // the number of elements

void P(){
  printf("\ntest\n");
}

void swap(int *a, int *b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

int parent(int i){
  if(i == 1) return 0;
  return i / 2;
}

int left(int i){
  if(i * 2 > H) return 0;
  return i * 2;
}

int right(int i){
  if(i * 2 + 1 > H) return 0;
  return i * 2 + 1;
}

void PrintAllElement(int *A){
  int i;
  for(i = 1; i < H + 1; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(parent(i)){
      printf("parent key = %d, ", A[parent(i)]);
    }
    if(left(i)){
      printf("left key = %d, ", A[left(i)]);
    }
    if(right(i)){
      printf("right key = %d, ", A[right(i)]);
    }
    printf("\n");
  }
}

void maxHeapify(int *A, int i){
  int l, r, largest;
  l = left(i);
  r = right(i);
  // choose the largest node from [i], [l] and [r]
  if(l != 0 && A[l] > A[i]){
    largest = l; 
  }else{
    largest = i;
  }
  if(r != 0 && A[r] > A[largest]){
    largest = r;
  }

  // when largest = r or l
  if(largest != i){
    swap(&A[i], &A[largest]);
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int *A){
  for(int i = H/2; i > 0; i--){
    maxHeapify(A, i);
  }
}

int main(){
  int i, *A;
  
  scanf("%d", &H);
  A = (int *)malloc(sizeof(int) * H + 1);
  for(i = 1; i < H + 1; i++){
    scanf("%d", &A[i]);
  }

  buildMaxHeap(A);

  for(i = 1; i < H + 1; i++){
    printf(" %d", A[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 4664
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

    ($next:expr, i321) => {
        read_value!($next, i32) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// # Examples
//
// # integers
// input! { n: i32, m: i32, ... }
//
// # array
// input! { n: i32, v: [i32; n], }
//
// # matrix
// input! { n: i32, m: i32, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: i32,
//     w: i32,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: i32, b: i32, c: i32,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
fn main() {
    // abc 072
    input! { x: i32, a: i32, b: i32 }
    if (a-x).abs() >= (b-x).abs() {
        println!("{}", "B");
    } else {
        println!("{}", "A");
    }
}

Measured memory_bytes: 4352
n = int(input())
a = list(map(int,input().split()))
o = []
e = []
for i in range(n):
  if i%2 == 0:e.append(a[i])
  else: o.append(a[i])

if n%2 == 0:
  b = list(reversed(o))+e
else:
  b = list(reversed(e))+o
print(*b)

Measured memory_bytes: 26016
#include <iostream>
#include <array>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long int;

void search(ll d, const vector<pair<ll, ll>>& v, ll t, ll m, ll *const pmr){
    if(t >= sqrt(m + 0.5)){
        //cerr << t << " " << to_string(t).size() << endl;
        *pmr = min(*pmr, (ll)to_string(t).size());
    }else if(d == v.size()){
        //cerr << t << " " << to_string(m / t).size() << endl;
        *pmr = min(*pmr, (ll)to_string(m / t).size());
    }else{
        for(ll i = 0; i <= v[d].second; ++i){
            search(d + 1, v, t, m, pmr);
            t *= v[d].first;
        }
    }
}

int main(){
    
    ll N;
    
    cin >> N;
    
    if(N == 1){ cout << '1' << endl; return 0; }
    
    map<ll, ll> fct;
    const ll M = N;
    
    for(ll i = 2; i <= sqrt(N + 0.5); ++i){
        if(N % i == 0){
            fct[i] += 1;
            N /= i;
            i -= 1;
        }
    }
    fct[N] += 1;
    
    vector<pair<ll, ll>> v;
    
    for(auto& a : fct){
        v.push_back(a);
    }
    
    ll mr = 1000000000000;
    search(0, v, 1, M, &mr);
    
    cout << mr << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int count = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];

int main(void){
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  if(S[K - 1] == 'A'){
    S[K - 1] = 'a';
  }else if(S[K - 1] == 'B'){
    S[K - 1] = 'b';
  }else if(S[K - 1] = 'C'){
    S[K - 1] = 'c';
  }
  cout << S << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
ll n, m, x[100100], y[100100], a[100100], b[100100], MOD = 1000000007;

int main() {
    int i;

    scanf("%lld%lld",&n,&m);
    for (i=0;i<n;i++) scanf("%lld",&x[i]);
    for (i=0;i<m;i++) scanf("%lld",&y[i]);
    for (i=1;i<n;i++) a[i] = x[i]-x[i-1];
    for (i=1;i<m;i++) b[i] = y[i]-y[i-1];
    ll sum1 = 0, sum2 = 0;
    for (i=1;i<n;i++) sum1 += (((a[i]*i)%MOD)*(n-i))%MOD;
    for (i=1;i<m;i++) sum2 += (((b[i]*i)%MOD)*(m-i))%MOD;
    printf("%lld\n",((sum1%MOD)*(sum2%MOD))%MOD);

    return 0;
}


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

long long a,b,c;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a%2==0||b%2==0||c%2==0)
	printf("0\n");
	else
	{
		long long ji=min(a*b,a*c);
		ji=min(ji,b*c);
		printf("%lld\n",ji);
	}
	return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;

vi pr(3333 , 0);
vi ra(3333 , 1);

int find_set( int v){
	return pr[v] == v ? v : pr[v] = find_set(pr[v]);
}

int union_sets(int a , int b){
	a = find_set(a);
	b = find_set(b);
	if(a != b){
		pr[b] = a;
		ra[a] += ra[b];
	}
}

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

	int n;
	cin >> n;
	
	int d[n][n] , d1[n][n];
	ll sum = 0;
	
	rep(i,n){
		pr[i] = i;
		rep(j,n){
			cin >> d[i][j];
			d1[i][j] = d[i][j];
		}
	}
	
	rep(i,n)
		rep(j,n)
			if(d[i][j] != d[j][i])dier(-1);
	
	rep(k,n)
		rep(i,n)
			rep(j,n)
				d[i][j] = min (d[i][j], d[i][k] + d[k][j]);
				
	bool ck = 1;
	
	rep(i,n)
		rep(j,n)
			ck &= d[i][j] == d1[i][j];
			
	
	rep(i,n){
		rep(j,n){
			bool flag = 0;
			rep(k,n){
				if(i == k or j == k)continue;
				if(d[i][k] + d[k][j] == d[i][j])flag = 1;
			}
			sum += (flag^1) * d[i][j];
		}
	}
	
	
	cout << (ck ? sum / 2 : -1ll);

	return 0;
}

Measured memory_bytes: 1024
A,B,K = map(int,input().split())
cont = 0
if A < B:
    for i in range(A,0,-1):
        if A % i == 0 and B % i == 0:
            cont += 1
        if cont == K:
            print(i)
            break
else:
    for i in range(B,0,-1):
        if A % i == 0 and B % i == 0:
            cont += 1
        if cont == K:
            print(i)
            break

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

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

    int ans=1e9;
    while(n--){
        int a; cin>>a;
        int count_2 = 0;
        while(a%2 == 0){
            count_2++;
            a /= 2;
        }
        ans = min(ans,count_2);
    }
    cout << ans << endl;

}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;


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

    int n,m;
    cin >> n >> m;
    int l,r;
    int maxL = 0;
    int minR = n;
    rep(i,m){
        cin >> l >> r;
        if(maxL < l && l <= n)
            maxL = l;
        if(minR > r )
            minR = r;
    }
    int ans = minR-maxL+1;
    if(ans <= 0)
        ans = 0;

    cout << ans <<'\n';

    return 0;
}

Measured memory_bytes: 256
using System;

namespace abc163_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);

            string[] day = Console.ReadLine().Split(' ');
            int[] a = new int[m];
            int goukei = 0;
            for(int i = 0; i<m; i++)
            {
                a[i] = Convert.ToInt32(day[i]);
                goukei += a[i];
            }

            if(n - goukei >= 0)
            {
                Console.WriteLine(n - goukei);
            }
            else
            {
                Console.WriteLine(-1);
            }
            Console.Read();
        }
    }
}


Measured memory_bytes: 28324
#include<bits/stdc++.h>
 using namespace std;
 int n,m,s,t,x,y,lt,lx,ly;
 int main()
 {
 	scanf("%d",&n);
 	for (int i=1;i<=n;i++)
 	{
 		scanf("%d %d %d",&t,&x,&y);
 		if ((t-lt<abs(lx-x)+abs(ly-y))||(((t-lt)-abs(lx-x)-abs(ly-y))%2==1))
 		{
 			printf("No\n");
 			return 0;
 		}
 		lt=t;
 		lx=x;
 		ly=y;
 	}
 	printf("Yes\n");
 	return 0;
 }


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

int main() {
 int N = 0;
 cin >> N;

 int H[N];
 int cnt = 0;
 int lCnt = 0;

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

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

	if(H[i] >= H[i+1]) {
		cnt++;
	} else {
		if(lCnt < cnt) {
			lCnt = cnt;
		}
		cnt = 0;
	}	
 }
 if(lCnt < cnt) {
	lCnt = cnt;
 }	

 cout << lCnt << endl;

}

Measured memory_bytes: 764
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: i32,
        b:i32,
        t:i32,
    }
    let ans=t/a * b;
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int r, ans = 0;
    cin >> r;
    ans = r * r;
    cout << ans << endl;
    return 0;
}


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

int main() {
    int c[3][3];
    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 3; ++j) cin >> c[i][j];
    }
    
    int a[3], b[3];
    bool info = false;
    for(int k = 0; k <= c[0][0]; ++k) {
        bool info2 = true;
        a[0] = k;
        b[0] = c[0][0] - a[0];
        b[1] = c[0][1] - a[0];
        b[2] = c[0][2] - a[0];
        a[1] = c[1][0] - b[0];
        a[2] = c[2][0] - b[0];
        for(int i = 0; i < 3; ++i) {
            for(int j = 0; j < 3; ++j) {
                if(a[i] + b[j] != c[i][j]) info2 = false;
            }
        }
        if(info2) info = true;
    }
    
    if(info) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

ruisekiA = [0]
ruisekiB = [0]
tmpA=0
tmpB=0
for i in range(len(A)):
    tmpA += A[i]
    ruisekiA.append(tmpA)
for i in range(len(B)):
    tmpB += B[i]
    ruisekiB.append(tmpB)
ans = 0
for i in range(len(ruisekiA)):
    #tmp = ruisekiA[i]
    l = -1
    r = len(ruisekiB)
    while r - l > 1:
        mid = (r + l)//2
        tmp = ruisekiA[i]+ruisekiB[mid]
        if tmp <= K:
            l = mid
        else:
            r = mid
    if l == -1:
        continue
    ans = max(ans, i+l)
print(ans)

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


def main():
    n = int(input())
    work_list = [tuple(map(int, input().split())) for i in range(n)]

    dp = [[0] * 3 for i in range(n + 1)]
    for i, work in enumerate(work_list):
        for i_now in range(3):
            for i_pre in range(3):
                if i_now == i_pre:
                    continue

                dp[i + 1][i_now] = max(dp[i + 1][i_now], dp[i][i_pre] + work[i_now])

    print(max(dp[-1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n; cin>>n;
    cout<<n*(n+1)/2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 10000
#define NIL -1

struct Node {int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
  if (u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right, d+1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if (T[u].left != NIL) h1 = setHeight(T[u].left) + 1;
  if (T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
  if (T[u].parent == NIL) return NIL;
  if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
  if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "sibling = " << getSibling(u) << ", ";
  int deg = 0;
  if (T[u].left != NIL) deg++;
  if (T[u].right != NIL) deg++;
  cout << "degree = " << deg << ", ";
  cout << "depth = " << D[u] << ", ";
  cout << "height = " << H[u] << ", ";
  if (T[u].parent == NIL) cout << "root" << endl;
  else if (T[u].left == NIL && T[u].right == NIL) cout << "leaf" << endl;
  else cout << "internal node" << endl;
}

int main() {
  int v, l, r, root = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) T[i].parent = NIL;

  for (int i = 0; i < n; ++i) {
    cin >> v >> l >> r;
    T[v].left = l;
    T[v].right = r;
    if (l != NIL) T[l].parent = v;
    if (r != NIL) T[r].parent = v;
  }

  for (int i = 0; i < n; ++i) if (T[i].parent == NIL) root = i;

  setDepth(root, 0);
  setHeight(root);

  for (int i = 0; i < n; i++) print(i);
  return 0;
}



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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



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

    int n;
    cin>>n;
    int s=0;
    int a[n],b[n];

    for(int i=0;i<n;i++)
    {
    	cin>>b[i];
    	s^=b[i];
    }

    for(int i=0;i<n;i++)
    {
    	a[i]=(s^b[i]);
    	cout<<a[i]<<" ";
    }

    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 5080
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

// int prime[1000001];
// vector<ll> primes;

// void soe() {
//     int i,j;
//     for(i=2;i<1000001;i++) prime[i] = 1;
//     for(i=2;i<=sqrt(1000001);i++) {
//         if(prime[i] == 1) {
//             for(j=i*i;j<1000001;j+=i) {
//                 prime[j] = 0;
//             }
//         }
//     }
//     for(i=2;i<1000001;i++) {
//         if(prime[i]) primes.pb(i);
//     }
// }

ll p(ll x, ll n) {
    ll res = 1;
    while(n) {
        if(n&1) res = (res*x);
        x = (x*x);
        n /= 2;
    }
    return res;
}

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

    ll n,NrP2=0,NrP5=0,DrP2=0,DrP5=0,i;
    cin >> n;
    ll m = (n/2);
    i=1;
    while(1) {
        ll expn = (m/p(2,i));
        if(expn) DrP2 += expn;
        else break;
        i++;
    }
    DrP2 += (n/2);
    i=1;
    while(1) {
        ll expn = (m/p(5,i));
        if(expn) DrP5 += expn;
        else break;
        i++;
    }
    i=1;
    while(1) {
        ll expn = (n/p(2,i));
        if(expn) NrP2 += expn;
        else break;
        i++;
    }
    i=1;
    while(1) {
        ll expn = (n/p(2,i));
        if(expn) NrP5 += expn;
        else break;
        i++;
    }
    if(n&1) {
        NrP2 -= DrP2;
        NrP5 -= DrP5;
        cout << min(NrP2,NrP5);
    } else {
        cout << min(DrP2,DrP5);
    }
    cout << "\n";
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 3010
const int p=1e9+7;
const int inv2=500000004;
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,Q,ans,pw=1,a[maxn],p1[maxn],p2[maxn],f[maxn][maxn];
int add(int x,int y)
{
	x+=y;
	return x>=p? x-p:x;
}
void Add(int &x,int y)
{
	x+=y;
	if(x>=p)
		x-=p;
}
int mul(int x,int y)
{
	return 1ll*x*y%p;
}
int main()
{
	read(n,Q);
	for(int i=1;i<=n;i++)
		read(a[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			f[i][j]=a[i]>a[j];
	for(int i=1;i<=Q;i++)
		read(p1[i],p2[i]);
	for(int i=1;i<=Q;i++)
	{
		static int g[maxn][maxn];
		for(int x=1;x<=n;x++)
			if(x!=p1[i]&&x!=p2[i])
			{
				g[x][p1[i]]=mul(inv2,add(f[x][p1[i]],f[x][p2[i]]));
				g[p1[i]][x]=mul(inv2,add(f[p1[i]][x],f[p2[i]][x]));
				g[x][p2[i]]=mul(inv2,add(f[x][p2[i]],f[x][p1[i]]));
				g[p2[i]][x]=mul(inv2,add(f[p2[i]][x],f[p1[i]][x]));
			}
		for(int x=1;x<=n;x++)
			if(x!=p1[i]&&x!=p2[i])
			{
				f[x][p1[i]]=g[x][p1[i]];
				f[p1[i]][x]=g[p1[i]][x];
				f[x][p2[i]]=g[x][p2[i]];
				f[p2[i]][x]=g[p2[i]][x];
			}
		f[p1[i]][p2[i]]=f[p2[i]][p1[i]]=mul(inv2,add(f[p1[i]][p2[i]],f[p2[i]][p1[i]]));
		pw=add(pw,pw);
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			Add(ans,f[i][j]);
	printf("%d\n",mul(ans,pw));
    return 0;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	ll a, b; cin >> a >> b;
	if (a < b)swap(a, b);
	ll r = a % b, x = a * b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	cout << x / b;
}

Measured memory_bytes: 256
import Data.Vector.Unboxed (Vector)
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  vec <- V.fromList . map ((\p -> (1 + p) / 2.0) . read) . words <$> getLine :: IO (Vector Double)
  let first = V.sum $ V.slice 0 k vec
  print $ solve n k vec 0 k first first

solve :: Int -> Int -> Vector Double -> Int -> Int -> Double -> Double -> Double
solve n k vec start end now maxim
  | end >= V.length vec = maxim
  | otherwise = let next = now - (vec V.! start) + (vec V.! end)
                in if maxim <= next
                   then solve n k vec (start+1) (end+1) next next
                   else solve n k vec (start+1) (end+1) next maxim


Measured memory_bytes: 36220
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

deque <llong> deq;
vector <llong> v;

llong n, a[mxn], k, dp[3001][3001], sum2, sum1;
bool ok = 0;

int main (){
    cin >> n;
    for (int i = 1; i <= n; i ++){
        cin >> a[i];
    }for (int i = 1; i <= n; i ++){
        for (int j = 1; j + i - 1 <= n; j ++){
            dp[i][j] = max(a[j] - dp[i - 1][j + 1], a[j + i - 1] - dp[i - 1][j]);
            ///cout << dp[i][j] << ' ';
        }///cout << endl;
    }cout << dp[n][1];
    return 0;
}


Measured memory_bytes: 70016
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	
	int n, k;
	cin>>n>>k;
	vi a(n);
	for (int i =0;i < n;++i) {
		cin>>a[i];
	}

	sort(all(a));
	int ans = accumulate(a.begin(), a.begin() + k, 0);
	cout<<ans<<endl;
	return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

bool check(const string& a, const string& b, int64_t offset) {
    if (offset < 0) {
        return check(b, a, -offset);
    }

    for (auto i : irange(0uL, b.size())) {
        if (offset + i >= a.size()) {
            return true;
        }

        if (a[offset + i] != '?' && b[i] != '?' && a[offset + i] != b[i]) {
            return false;
        }
    }

    return true;
}

void calc(const string& a, const string& b, unordered_set<int64_t>& idxs) {
    for (auto i : irange(-4000L, 4001L)) {
        if (check(a, b, i)) {
            idxs.insert(i);
        }
    }
}

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    unordered_set<int64_t> ab, ac, bc;
    calc(a, b, ab);
    calc(a, c, ac);
    calc(b, c, bc);

    int64_t ans = 6000;
    for (auto i : ab) {
        for (auto j : bc) {
            if (-(i + j) >= (int64_t)c.size() || i + j >= (int64_t)a.size() ||
                ac.count(i + j)) {
                int64_t s = min({0L, i, i + j});
                int64_t e = max({(int64_t)a.size(), i + (int64_t)b.size(),
                                 i + j + (int64_t)c.size()});
                ans = min(ans, e - s);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408