akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int t = n % 10;
    if (t == 2 || t == 4 || t == 5 || t == 7 || t == 9)
    {
        cout << "hon";
    }
    else if (t == 0 || t == 1 || t == 6 || t == 8)
        cout << "pon";
    else
    {
        cout << "bon";
    }
    return 0;
}

Measured memory_bytes: 3640
//c.......

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(){
    int n;
    scanf("%d",&n);
    int max = 0;
    if(n==1) printf("1");
    else{
        int i = 1;
        for(;i<=n;i=i*2){
            max = i*2;
        }
        printf("%d",max/2);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n,a,max,min;
	cin >> n >> max;
	min = max;
	for(int i = 0; i < n-1; i++){
		cin >> a;
		if(a > max) max = a;
		if(a < min) min = a;
	}
	cout << max - min << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int t=N, sum=0;
  while(t>0) {
    sum += t%10;
    t /= 10;
  }
  if (N%sum == 0) {
	cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int n,A[50];

int solve(int i,int m)
{
	if(m==0)return 1;
	if(i>=n)return 0;
	int res =solve(i+1,m)||solve(i+1,m-A[i]);
	return res;
}

int main()
{
	int q,M,i;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++)
	{
		scanf("%d",&M);
		if(solve(0,M))printf("yes\n");
		else printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2080
import java.util.Scanner;

public class Main {

	char[] l = "qwertasdfgzxcvb".toCharArray();

	void run() {

		Scanner sc = new Scanner(System.in);

		while (true) {
			char[] c = sc.next().toCharArray();

			if (c[0] == '#') {
				break;
			}

			int cnt = 0;

			for (int i = 0; i < c.length - 1; i++) {
				if (isLeft(c[i]) != isLeft(c[i + 1])) {
					cnt++;
				}
			}

			System.out.println(cnt);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public boolean isLeft(char c) {

		for (int i = 0; i < l.length; i++) {
			if (c == l[i]) {
				return true;
			}
		}

		return false;
	}

}

Measured memory_bytes: 19920
// Original: https://github.com/tanakh/competitive-rs
#[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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(n: usize, uvw: [(usize1, usize1, usize); n - 1]);

    let mut graph = vec![vec![]; n];
    for &(u, v, w) in uvw.iter() {
        graph[u].push((v, w));
        graph[v].push((u, w));
    }

    // 適当に0番目のノードを根とする
    let mut color = vec![0usize; n];
    color[0] = 0;
    dfs(&graph, &mut color, 0, 0, 0);

    for &c in color.iter() {
        println!("{}", c);
    }
}

fn dfs(
    graph: &Vec<Vec<(usize, usize)>>,
    color: &mut Vec<usize>,
    cur_node: usize,
    par: usize,
    depth: usize,
) {
    // 根から頂点iへの距離をdiと置く
    // 任意の2頂点u,vについて、その最小共通祖先をxとすると、uとvの距離は du + dv - 2dx と書ける
    // 今回はu-v間の距離のパリティ（偶奇）だけ見ればいいので、偶数である -2dx は無視できる
    // よって、根からの距離のパリティが一致するかどうかだけ判定すれば良い
    color[cur_node] = depth % 2;
    for &(next, w) in graph[cur_node].iter() {
        if next == par {
            continue;
        }
        let next_depth = w + depth;
        dfs(graph, color, next, cur_node, next_depth);
    }
}


Measured memory_bytes: 21884
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

int n, l , r , ans=0;


int main(){
cin >> n;
rep(i, 0, n-1){
cin >> l >> r;
ans += r-l+1;
}
cout << ans << endl;


return 0;}


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

using namespace std;

const long vs[9] = {2,5,5,4,5,6,3,7,6};

int compare(string const &s1, string const &s2)
{
	long l1 = s1.size(), l2 = s2.size();
	if (l1 != l2)
	{
		if (l1 < l2) return 1;
		else return -1;
	}
	for (int i = 0; i < l1; i++)
	{
		if (s1[i] == s2[i]) continue;
		else if (s1[i] < s2[i]) return 1;
		else return -1;
	}
	return 0;
}

void solve()
{
	int s, t;
	cin >> s >> t;
	vector<long> ds(t);
	vector<string> dp(s+1);
	vector<int> vst(s+1);
	vst[0] = 1;
	for (int i = 0; i < t; i++)
	{
		cin >> ds[i];
	}
	for (int i = 0; i < s; i++)
	{
		if (!vst[i]) continue;
		for (int j = 0; j < t; j++)
		{
			long d = ds[j];
			if (i+vs[d-1] <= s && (!vst[i+vs[d-1]] || (compare(dp[i+vs[d-1]], dp[i]+(to_string(d))) > 0)))
			{
				dp[i+vs[d-1]] = dp[i] + to_string(d);
				vst[i+vs[d-1]] = 1;
			}
		}
	}
	cout << dp[s] << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector <int> a(m+1,0);
    
    int k,k2;
    rep(i,n){
        cin >> k;
        rep(j,k){
            cin >> k2;
            ++a[k2];
        }
    }

    int ans=0;
    rep(i,m+1){
        if(a[i]==n){
            ++ans;
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3564
#include<stdio.h>

int main()

{
    int x,y;
    char operator;


    while(scanf("%d %c %d", &x, &operator, &y)!=EOF)
    {
        if(operator=='?')
        {
            break;
        }

        switch(operator)
       {
        case'+':
        printf("%d\n", x+y);
        break;

        case'-':
        printf("%d\n", x-y);
        break;

        case'*':
        printf("%d\n", x*y);
        break;

        case'/':
        printf("%d\n", x/y);
        break;

    }
}

    return 0;



}


Measured memory_bytes: 2100
from math import floor,ceil
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

for i in range(0,K):
    mmax,mmin = jmax,jmin
    if mmin % A[i] != 0:
        if (mmin + (A[i] - (mmin % A[i]))) > mmax:
            print(-1)
            exit()

    jmin = ceil(jmin / A[i]) * A[i]
    jmax = floor(jmax / A[i]) * A[i] + A[i] -1

print(jmin, jmax)

#計算量はO(3K)すなわちO(K)

Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
  int n, k;
  cin >> n >> k;
  vector<ll> cnt(k);
  for (int i = 1; i <= n; ++i) {
    cnt[i % k]++;
  }
  ll ans = 0;
  rep(a, k) {
    int b = k - a;
    int c = k - a;
    if((a + b) % k == 0 && (b + c) % k == 0) {
      ans += cnt[a] * cnt[b % k] * cnt[c % k];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::pair<int, int>> requests(m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    std::cin >> a >> b;
    requests[i] = std::make_pair(a, b);
  }
  std::sort(requests.begin(), requests.end(), [](const std::pair<int, int>& x, const std::pair<int, int>& y) {
    return std::get<1>(x) < std::get<1>(y);
  });
  int result = 0;
  int prev_b = 0;
  for (const std::pair<int, int>& request : requests) {
    if (prev_b <= std::get<0>(request)) {
      prev_b = std::get<1>(request);
      result++;
    }
  }
  std::cout << result << std::endl;
  return 0;
}

Measured memory_bytes: 1152
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define INTINF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;

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

Node *root, *NIL;


void insert(int num){
  Node *y = NIL;
  Node *x = root; //start
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = num;
  z->left = NIL;
  z->right = NIL;

  while ( x!=NIL ) {
    y=x; //おや
    if ( z->key < x->key ) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y==NIL) { //最初
    root = z;
  }else{
    if( z->key < y->key ){  //親より小さければ左につく
      y->left = z;
    }else{
      y->right = z;
    }
  }
}

void find(int num){
  Node *x = root;

  while ( x!=NIL ) {
    if (num < x->key) {
      x=x->left;
    } else if (num > x->key) {
      x=x->right;
    } else {
      std::cout << "yes" << '\n';
      return;
    }
  }
  std::cout << "no" << '\n';
  return;
}

Node *treeMinimum(Node *x){
  while (x->left != NIL) {
    x=x->left;
  }
  return x;
}


Node *treeSuccessor(Node *x){
  if (x->right!=NIL) {
    return treeMinimum(x->right);
  }
  Node *y = x->parent;
  while (y!=NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}


void treeDelete(int num){
  Node *y = root;
  while ( y!=NIL ) {
    if (num < y->key) {
      y=y->left;
    } else if (num > y->key) {
      y=y->right;
    } else if(num==y->key){
      break;
    }
  }
    Node *Deletee;
    Node *cldOfDeletee;

    if ( y->left==NIL || y->right==NIL ) Deletee = y;
    else Deletee = treeSuccessor(y);

    if (Deletee->left != NIL) {
      cldOfDeletee = Deletee->left;
    } else {
      cldOfDeletee = Deletee->right;
    }

    if (cldOfDeletee != NIL) {
      cldOfDeletee->parent = Deletee->parent;
    }

    if (Deletee->parent == NIL) {
      root = cldOfDeletee;
    }else{
      if (Deletee==Deletee->parent->left) {
        Deletee->parent->left = cldOfDeletee;
      }else{
        Deletee->parent->right = cldOfDeletee;
      }
    }

    if (Deletee!=y) {
      y->key = Deletee->key;
    }
    free(Deletee);
  

}


void print_in(Node *u){
  if(u==NIL) return;
  print_in(u->left);
  std::cout << " " << u->key;
  print_in(u->right);
}


void print_pre(Node *u){
  if(u==NIL) return;
  std::cout << " " << u->key;
  print_pre(u->left);
  print_pre(u->right);
}


int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, num; std::cin >> k;
  string command;
  for (size_t i = 0; i < k; i++) {
    std::cin >> command;
    if (command=="insert") {
      std::cin >> num;
      insert(num);
    } else if (command=="print"){
      print_in(root);
      std::cout << '\n';
      print_pre(root);
      std::cout << '\n';
    } else if (command=="find"){
      std::cin >> num;
      find(num);
    } else if (command=="delete"){
      std::cin >> num;
      treeDelete(num);
    }
  }

  return 0;
}



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

using namespace std;

int main()
{
    using pii = pair<int, int>;
    int x1, y1, x2, y2;
    int N;
    cin >> x1 >> y1 >> x2 >> y2 >> N;

    int sx = min(x1, x2), tx = max(x1, x2);
    int sy = min(y1, y2), ty = max(y1, y2);
    
    vector<pii> v;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
        if (sx <= X[i] && X[i] <= tx && sy <= Y[i] && Y[i] <= ty) {
            v.emplace_back(X[i], Y[i]);
        }
    }

    int n = v.size();
    if (x1 > x2) {
        swap(x1, x2);
        for (int i = 0; i < n; i++) {
            v[i].first *= -1;
        }
    }

    if (y1 > y2) {
        swap(y1, y2);
        for (int i = 0; i < n; i++) {
            v[i].second *= -1;
        }
    }
    sort(v.begin(), v.end());

    constexpr int INF = 1145141919;

    vector<int> dp(n, INF);
    for (int i = 0; i < n; i++) {
        int c = v[i].second;
        *lower_bound(dp.begin(), dp.end(), c) = c;
    }

    constexpr double PI = acos(-1);
    int m = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    double ans = (tx - sx + ty - sy) * 100.0 - (20.0 - 5.0 * PI) * m;
    if (min(tx - sx, ty - sy) + 1 == m) {
        ans += 5 * PI;
    }
    printf("%.15f\n", ans);    
    return 0;
}


Measured memory_bytes: 4208
import random

# n = 10
# A = [random.randint(1, 100) for i in range(20)]
n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0

def insertion_sort(list, step):
    n = len(list)
    for i in range(step, n):
        temp = list[i]
        j = i
        while j >= step and list[j - step] > temp:
            list[j] = list[j - step]
            j -= step
            global cnt
            cnt += 1
        list[j] = temp
    return list

def shell_sort(list):
    n = len(list)
    
    G = []
    step = 1
    while step <= n:
        G.append(step)
        step = 3*step + 1
    print(len(G))
    for g in sorted(G, reverse=True):
        print(g, end=' ')
    print('\n', end='')

    for i in sorted(range(len(G)), reverse=True):
        list = insertion_sort(list, G[i])
    return list

shell_sort(A)
print(cnt)

for i in A:
    print(i, end='\n')

Measured memory_bytes: 51172
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  int next=1;
  
  int ans=0;
  
  
  for(int i=0;i<N&&next!=2;i++){
    next=A[next-1];
    ans++;
  }
  
  if(next!=2){
    ans=-1;
  }
  
  
  cout<<ans<<endl;
}

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

const ll INF = 1e18;

ll left (const vector<ll> &v, ll key) {
  return v[upper_bound(v.begin(), v.end(), key) - v.begin() - 1];
}

ll right(const vector<ll> &v, ll key) {
  return v[lower_bound(v.begin(), v.end(), key) - v.begin()];
}

int main(){
  int a, b, q;
  cin >> a >> b >> q;
  vector<ll> s(a), t(b), x(q);
  rep(i,a) scanf("%lld", &s[i]);
  rep(i,b) scanf("%lld", &t[i]);
  rep(i,q) scanf("%lld", &x[i]);
  s.push_back(INF);
  t.push_back(INF);
  s.push_back(-INF);
  t.push_back(-INF);
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());

  rep(k,q) {
    ll res = INF;
    rep(i,2) {
      ll shrine = (i ? left(s,x[k]) : right(s,x[k]));
      rep(j,2) {
        ll temple = (j ? left(t,shrine) : right(t,shrine));
        res = min(res,abs(x[k] - shrine) + abs(shrine - temple));
      }
    }

    rep(i,2) {
      ll temple = (i ? left(t,x[k]) : right(t,x[k]));
      rep(j,2) {
        ll shrine = (j ? left(s,temple) : right(s,temple));
        res = min(res,abs(x[k] - temple) + abs(shrine - temple));
      }
    }
    printf("%lld\n", res);
  }
  return 0;
} 

Measured memory_bytes: 3680
# coding UTF-8
# 
# problem C
# 
import itertools
import numpy as np
from scipy.spatial import distance

N = int(input())
city = []
for i in range(N):
    city.append(list(map(int, input().split())))

d = distance.cdist(city, city, metric='euclidean')

ans = []
city_no = list(range(N))
for elem in itertools.permutations(city_no, N):
    for j in range(len(elem)-1):
        ans.append(d[elem[j], elem[j+1]])

print((sum(ans)/len(ans))*(N-1))


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

using namespace std;

int main() {
    int n;
    cin >> n;
    int s[n];
    for (int i = 0; i < n; i++) cin >> s[i];
    vector<int> dp(n, (int) 1e9 + 5);

    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j <= i + 2; j++) {
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(s[i] - s[j]));
        }
    }
    cout << dp[n - 1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    double w, h, x, y;
    scanf("%lf%lf%lf%lf", &w, &h, &x, &y);
    printf("%.10lf ", w / 2.0000000 * h);
    ll W = w, H = h, X = x, Y = y;
    if (x != 0 && y != 0 && x != w && y != h && (y * W == X * H || Y * W == -X * H + W * H))
        printf("1\n");
    else
        printf("0\n");
}


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


int main()
{
	int H, W;
	while (cin >> H >> W)
	{
		if (W == 0 && H == 0)
		{
			break;
		}
		for (int i = 0; i < H; i++)
		{
			for (int p = 0; p < W; p++)
			{


				if ((i+p)%2==0)

				{
					cout << "#";

				}
				else
				{
					cout << ".";

				}

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



Measured memory_bytes: 3116
import numpy as np
l,r = map(int,input().split())
mod = 2019
arr = np.array(list(set([i%mod for i in range(l,min(r+1,l+2019))])))
ans = 2019

for left in range(len(arr)-1):
    ans = min(min(arr[left]*arr[left+1:]%mod),ans)
    if ans == 0:
        print(ans)
        exit()
print(ans)

Measured memory_bytes: 12560
'use strict'

function Main(input) {
  const N = Number(input.split('\n')[0].split(' ')[0]);
  const K = Number(input.split('\n')[0].split(' ')[1]);
  let answer = 1 + Math.ceil((N-K)/(K-1));

  console.log(answer);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

using namespace std;

int main()
{
	string S;

	cin >> S;

	int counts[2] = {};
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == '0')
		{
			counts[0]++;
		}
		else
		{
			counts[1]++;
		}
	}

	cout << min(counts[0], counts[1]) * 2 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int max(int a, int b, int c)
{
    int m;
    m = a >= b ? a : b;
    m = m >= c ? m : c;
    return m;

}

int LCS(const char *X,const char *Y)
{
    int dp[1010][1010] = {0};
    int i,j;
    int flag;

    for (i = 1; i <= strlen(X); ++i) {
        for (j = 1; j <= strlen(Y); ++j) {
            flag = (X[i-1] == Y[j-1] ? 1:0);
            dp[i][j] = max(dp[i-1][j-1] + flag, dp[i-1][j], dp[i][j-1]);
        }
    }
    return dp[strlen(X)][strlen(Y)];

}

int main() {
    int q;
    int i;
    char X[1010],Y[1010];
    int L_ans[160];

    scanf("%d", &q);

    for (i = 0; i < q; ++i) {
        scanf("%s",X);
        scanf("%s",Y);
        L_ans[i] = LCS(X,Y);
    }

    for (i = 0; i < q; ++i) {
        printf("%d",L_ans[i]);
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 5776
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
 
 
#define ll long long int
#define ld long double
 
#define fr first
#define se second
 
 
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define sunq(v) sort(all(v));v.resize(distance(v.begin(),unique(all(v))))
 
 
#define pb push_back
#define mp make_pair
 
 
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define emla(a, val) memset(a, val, sizeof(a))
#define easm(a, b) (a + b - 1) /b 
 
#define PI 3.141592653589793238
 
 
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

 

//bool valid(int i, int j){return i >= 0 && i < n && j >= 0 && j < m;}

int n;
int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  //clock_t z = clock();
  cin >> n;
  vector<int>v(n);
  for(auto &i : v)
    cin >> i;
  sort(all(v));
  cout << v[n-1] - v[0] << endl;
  //debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
  /*
  *try tricky test cases:
    -bounds
    -small input (0, 1)
    -big input
    -random tests
  */
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N;
	int c=0;
	char S[15];
	
	scanf("%s", S);
	
	for(N=0; N<15; N++){
		if (S[N]== 'x'){
			c++;
		}
	}
	
	if( c >= 8 ) printf("NO");
	else printf("YES");
	
	return 0;
}

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

void Main()
{
  ll X;
  cin >> X;
  ll money = 100;
  int i = 0;
  while (true) {
    i++;
    money += money/100;
    if (money >= X) {cout << i << endl; return;}
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3652
import java.util.*;

class Main
{
    //Point class
    static class Point
    {
	public double x;
	public double y;
	
	public Point(double x, double y)
	{
	    this.x=x;
	    this.y=y;
	}
	
	public Point(Point p)
	{
	    x=p.x;
	    y=p.y;
	}
	
	//print method
	public void printPoint()
	{
	    System.out.printf("%.8f %.8f\n", x, y);
	}
    }



    //main
    public static void main(String[] args)
    {
	Scanner read = new Scanner(System.in);
	int n;
	Point zero = new Point(0, 0);
	Point hyaku = new Point(100, 0);
	int i, j, k;

	//read n
	n=read.nextInt();
	read.close();

	//do methods
	zero.printPoint();
	divisionPoint(zero, hyaku, n);
	hyaku.printPoint();
    }

    //methods
    static void divisionPoint(Point p1, Point p2, int n)
    {
	double x = p2.x-p1.x;
	double y = p2.y-p1.y;

	Point s = new Point((x/3)+p1.x, (y/3)+p1.y);
	Point t = new Point(2*(x/3)+p1.x, 2*(y/3)+p1.y);
	Point u = new Point(getKoch(s, t));

	//get point
	if(n>0)
	   {
	       divisionPoint(p1, s, n-1);
	       s.printPoint();

	       divisionPoint(s, u, n-1);
	       u.printPoint();

	       divisionPoint(u, t, n-1);
	       t.printPoint();

	       divisionPoint(t, p2, n-1);       
	   }
    }
    
    static Point getKoch(Point s, Point t)
    {
	double x = t.x - s.x;
	double y = t.y - s.y;

	double moveX = (Math.cos(Math.PI/3)*x - Math.sin(Math.PI/3)*y)+s.x;
	double moveY = (Math.sin(Math.PI/3)*x + Math.cos(Math.PI/3)*y)+s.y;

	Point u = new Point(moveX, moveY);
	return u;
    }
    
}

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

int main() {
    int n; cin >> n;
    
    vector<double> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];

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

    for (int i = 0; i < n - 1; ++i) {
        v[i+1] = (v[i] + v[i+1]) / 2;
    }

    cout << v.back() << endl;

    return 0;
}

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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}


int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    long long x, y;
    cin >> x >> y;
    long long ans = 1e18;
    for(int mask = 0; mask < 4; mask++) {
        long long cur = x;
        long long moves = 0;
        for(int k = 0; k < 2; k++) {
            if((mask >> k) & 1) {
                cur = -cur;
                moves++;
            }
            if(k == 0) {
                if(cur < y) ans = min(ans, moves + abs(y - cur));
                if(cur < -y) moves += (-y-cur), cur = -y;
            }
            if(k == 1) {
                if(cur == y) {
                    ans = min(ans, moves);
                }
            }
        }
    }
    cout << ans << endl;
}





Measured memory_bytes: 3616
N,M = map(int,input().split())
s = []
c = []
if N == 1:
    minn = "0"
elif N == 2:
    minn = "00"
elif N == 3:
    minn = "000"
count = 0
minnlist = list(minn)
for i in range(M):
    am, pm = map(int,input().split())
    s.append(am)
    c.append(pm)

for i in range(M):
    if minnlist[s[i]-1] != "0" and minnlist[s[i]-1] != str(c[i]):
        count = -1
        break
    else:
        minnlist[s[i]-1] = str(c[i])

if not 1 in s:
    minnlist[0]=1
elif minnlist[0] == "0" and N>=2:
    count = -1

hiku = ''.join(map(str,minnlist))
#print(int(hiku))

if count == -1 and M >=1:
    print(-1)
elif M==0:
    if N==1:
        print(0)
    elif N==2:
        print(10)
    else:
        print(100)
else:
    print(hiku)


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

typedef long long ll;
using namespace std;

const ll mod = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, q; cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    for (int i = 0; i < a; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> t[i];
    }
    vector<ll> ans(q);
    for (int i = 0; i < q; i++) {
        ll x; cin >> x;
        auto its = upper_bound(s.begin(), s.end(), x);
        auto itt = upper_bound(t.begin(), t.end(), x);
        vector<ll> cans;
        if (its != s.end() && itt != t.end()) {
            cans.push_back(max(*its, *itt) - x);
        }
        if (its != s.begin() && itt != t.begin()) {
            its--;
            itt--;
            cans.push_back(x - min(*its, *itt));
            its++;
            itt++;
        }
        if (its != s.begin() && itt != t.end()) {
            its--;
            cans.push_back(*itt - *its + min(*itt-x, x-*its));
            its++;
        }
        if (itt != t.begin() && its != s.end()) {
            itt--;
            cans.push_back(*its - *itt + min(*its-x, x-*itt));
            itt++;
        }
        ll mn = -1;
        for (auto &can : cans) {
            if (mn < 0) mn = can;
            else mn = min(mn, can);
        }
        ans[i] = mn;
    }
    for (auto &an : ans) cout << an << endl;
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
  int n,k;
  cin>>n>>k;
  int ans=0;
  if(n==1) ans+=300000;
  else if(n==2) ans+=200000;
  else if(n==3) ans+=100000;
  if(k==1) ans+=300000;
  else if(k==2) ans+=200000;
  else if(k==3) ans+=100000;
  if(n==1 && k==1) ans+=400000;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	int h, m, h2, m2, k;
	cin >> h >> m >> h2 >> m2 >> k;
	cout << max(0, (h2 * 60) + m2 - ((h * 60) + m) - k);
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int LIS(vi as) {
    int n = as.size();
    vi dp(n + 1, 1e9);
    for (int a : as) {
        *lower_bound(dp.begin(), dp.end(), a) = a;
    }
    for (int i = 0; i <= n; i++) {
        if (dp[i] == 1e9) return i;
    }
    return -1;
}

int LDS(vi as) {
    reverse(as.begin(), as.end());
    return LIS(as);
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if (n > 1l * a * b || n + 1 < a + b) {
        cout << -1 << endl;
        return 0;
    }

    vvi ret;
    vi tmp;
    for (int i = 0; i < a; i++) {
        tmp.push_back(i);
    }
    ret.push_back(tmp);
    tmp.clear();
    int k = a;
    int cnt = b - 1;
    int nokori = n - a;
    for (int j = k; j < n; j++) {
        tmp.push_back(j);
        if (tmp.size() == (nokori + cnt - 1) / cnt) {
            ret.push_back(tmp);
            nokori -= tmp.size();
            tmp.clear();
            cnt--;
        }
    }
    ret.push_back(tmp);
    reverse(ret.begin(), ret.end());
    vi ans;
    for (vi &t : ret) {
        for (int a : t) {
            ans.push_back(a + 1);
        }
    }

    for (int a : ans) {
        cout << a << ' ';
    }
    cout << '\n';

    // assert(LIS(ans) == a);
    // assert(LDS(ans) == b);
}


Measured memory_bytes: 21352
n=input()
a=[]
area=[]
x1=[]
x2=[]

x=1
for i in n:
	if i=='\\':
		a.append(x)
		
	elif i=='/' and len(a)>=1:
		area.append(x-a[len(a)-1])
		x1.append(a[len(a)-1])
		x2.append(x)
		a.pop()		
		
		for i in range(len(x1)-2,-1,-1):	
			if x1[len(x1)-1]<x1[i] and x2[len(x2)-1]>x2[i]:
				x1.pop(i)
				x2.pop(i)
				area[i]=area[i]+area[len(area)-1]
				area.pop()
	x+=1

print(sum(area))
print(len(area),*area)

	



Measured memory_bytes: 6360
#include <iostream>

using namespace std;

void get_array(int A[], int N, int M, int n) {
    if ((N - 1 - n) >= 0) {

        if (A[N - 1 - n] < M) {
            A[N - 1 - n]++;
        } else {
            get_array(A, N, M, n + 1);
            A[N - 1 - n] = A[N - 1 -(n + 1)];
        }

    }
    return;
}

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;

    int a[Q];
    int b[Q];
    int c[Q];
    long int d[Q];
    int i;

    long int max = 0;
    long int total = 0;


    for (i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        max += d[i];
    }

    int A[N];

    for (i = 0; i < N; i++) {
        A[i] = 1;
    }

    do {

        int tmp_total = 0;

        for (i = 0; i < Q; i++) {
            if (A[b[i] - 1] - A[a[i] - 1] == c[i]) {
                tmp_total += d[i];
            }
        }

        if (tmp_total > total) total = tmp_total;
        if (total == max) break;

       get_array(A, N, M, 0);
        
        
    } while (A[0] < M);


    int tmp_total = 0;

    for (i = 0; i < Q; i++) {
        if (A[b[i] - 1] - A[a[i] - 1] == c[i]) {
            tmp_total += d[i];
        }
    }

    if (tmp_total > total) total = tmp_total;


    cout << total;

    return 0;
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
            int[] input = Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
            int N = input[0];
            int M = input[1];
            if(Math.Abs(M-N)>1)
            {
                Console.WriteLine(0);
                return;
            }

            ulong dog = 1, monkey = 1;
            for(uint i = 2; i <= M; i++)
            {
                dog = dog * i % 1000000007;
            }
            for(uint i = 2; i <= N; i++)
            {
                monkey = monkey * i % 1000000007;
            }
            ulong ans = dog * monkey % 1000000007;
            if (N == M) ans = ans * 2 % 1000000007;
            Console.WriteLine(ans);
            Console.ReadKey();
		}
	}
}


Measured memory_bytes: 13396
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };


struct Combination {

	vector<ll> fact, rfact;

	Combination(ll sz) : fact(sz + 1), rfact(sz + 1) {

		fact[0] = 1;
		for (ll i = 1; i < fact.size(); i++) {
			fact[i] = fact[i - 1] * i % MOD;
		}
		//逆元
		rfact[sz] = inv(fact[sz]);
		for (ll i = sz - 1; i >= 0; i--) {
			rfact[i] = rfact[i + 1] * (i + 1) % MOD;
		}
	}

	ll inv(ll x) {
		//modpow
		return pow(x, MOD - 2);
	}
	ll pow(ll x, ll n) {
		//累乗
		ll ret = 1;
		while (n > 0) {
			if (n & 1) (ret *= x) %= MOD;
			(x *= x) %= MOD;
			n >>= 1;
		}
		return (ret);
	}
	ll P(ll n, ll r) {
		//順列
		if (r < 0 || n < r) return (0);
		return (fact[n] * rfact[n - r] % MOD);
	}

	ll C(ll p, ll q) {
		//組み合わせ
		if (q < 0 || p < q) return (0);
		return (fact[p] * rfact[q] % MOD * rfact[p - q] % MOD);
	}

	ll H(ll n, ll r) {
		//重複組み合わせ
		if (n < 0 || r < 0) return (0);
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};


/******************************************************************************************/



int main() {

	ll n, k;
	cin >> n >> k;
	ll red = n - k;
	ll inside = k - 1;

	Combination comb(2050);


	for (ll i = 1; i <= k; i++)
	{
		cout << comb.C(k - 1, i - 1)*comb.C(n - k + 1, i) % MOD << endl;

	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n,k; cin>>n>>k;
    vector<int> p(n);
    rep(i,0,n) cin>>p[i];
    sort(all(p));
    int res=0;
    rep(i,0,k){
        res+=p[i];
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
using namespace std;

#include <math.h> 

bool func(long long num) {
    if (num == 2) {
        return true;
    }
    if (num % 2 == 0) {
        return false;
    }

    double sqrtNum = sqrt(num);
    for (long long i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    long long X;
    cin >> X;

    while (!func(X)) {
        X ++;
    }

    cout << X << endl;

    return 0;
}

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

#define N 8
#define FREE -1
bool board[N][N];
int  row[N];
bool col[N], dp[2*N-1], dn[2*N-1]; // 横, 右斜め、左斜めのクイーンの利き

void print()
{
	for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
		{
			if(board[i][j] && row[i] != j)
			{
				return;
			}
		}
	}

	for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
		{
			cout << ((row[i] == j) ? 'Q' : '.');
		}
		cout << endl;
	}
}

void queeeeeen(int i)
{
	if(i == N)
	{
		print();
		return;
	}
	
	for(int j = 0; j < N; j++)
	{
		// クイーンが利いていない
		if(!col[j] && !dp[i + j] && !dn[i - j + N - 1])
		{
			// クイーンを置く
			row[i] = j;
			col[j] = dp[i + j] = dn[i - j + N - 1] = true;
			
			// 再起呼び出し
			queeeeeen(i + 1);
			
			// クイーンを戻す
			row[i] = FREE;
			col[j] = dp[i + j] = dn[i - j + N - 1] = false;
		}
	}
}

int main()
{
	for(int i=0; i<N; i++)
	{
		row[i] = FREE;
		col[i] = false;
	}
	for(int i=0; i<2*N-1; i++)
	{
		dp[i] = dn[i] = false;
	}
	
	for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
		{
			board[i][j] = false;
		}
	}
	
	int k;
	cin >> k;
	
	for(int i = 0; i < k; i++)
	{
		int r,c;
		cin >> r >> c;
		board[r][c] = true;
	}
	
	queeeeeen(0);
	
	return 0;
}




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

int frmBFRtoNum(int building, int floor, int room){
	if(0 < building && building < 5 && 0 < floor && floor < 4 && 0 < room && room < 11){
		return 30*(building-1) + 10*(floor-1)+room-1;
	}
	else
		return -1;
}

int frmNumToB(int num){
	if(0<=num && num<120)
		return (num/30)+1;
	else
		return -1;
}

int frmNumToF(int num){
	if(0<=num && num<120)
		return ((num-30*(num/30))/10)+1;
	else
		return -1;
}

int frmNumToR(int num){
	if(0<=num && num<120)
		return ((num-30*(num/30))%10)+1;
	else
		return -1;
}

int main() {
	int i,n;
	int tenant[120],b,f,r,p,num;
	for(int i=0;i<120;i++)
		tenant[i]=0;			// initalize
	cin >> n;					// input data number
	for(i=0;i<n;i++){
		cin >> b >> f >> r >> p;
		num=frmBFRtoNum(b,f,r);
		if(num == -1)
			i=n+1;
		else
			tenant[num]+=p;
	}
	if(i==n+1)
		return -1;				// Input Error

	for(i=0;i<120;i++){
		if(frmNumToR(i) == 10){
			if(frmNumToF(i) == 3 && frmNumToB(i) != 4){
				cout << ' ' << tenant[i] << endl;
				cout << "####################" << endl;
			} else
			cout << ' ' << tenant[i] << endl;
		} else
			cout << ' ' << tenant[i];
	}
	return 0;
}



Measured memory_bytes: 3104
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n = int(input())
k = int(input())
x = list(map(int,input().split()))
k_d = []
for i in range(len(x)):
    k_d.append(abs(x[i]-k))
ans = 0
for i in range(n):
    diff = min(x[i],k_d[i])
    ans += diff*2
print(ans)


Measured memory_bytes: 12508
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>

using namespace std;
typedef long long ll;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B)
		cout << C << endl;
	else if (A == C)
		cout << B << endl;
	else
		cout << A;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, b, c, t;
    scanf("%d%d%d", &a, &b, &c);
    if (a > b) {
        t = a;
        a = b;
        b = t;
    }
    if (a > c) {
        t = a;
        a = c;
        c = t;
    }
    if (b > c) {
        t = b;
        b = c;
        c = t;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 596
r, g, b, n = map(int, input().split())
count = 0
for i in range(n//r + 1):
  for j in range((n-r*i) // g + 1):
    d = n - r*i - g*j
    if d%b == 0 and d >= 0:
      count += 1
print(count)

Measured memory_bytes: 40684
def main():
    M = Matrix2([[0, 1, 0], [0, 0, 1], [1, 1, 1]])
    F = [1, 2, 4]
    while True:
        n = int(raw_input())
        if n == 0:
            break
        if n <= 3:
            print 1
            continue
        m = M ** (n-3)
        print 1 + (F[0]*m[2][0] + F[1]*m[2][1] + F[2]*m[2][2]) / 10 / 365

class Matrix2(list):

    def __init__(self, m):
        list.__init__(self, [r[:] for r in map(list, m)])
        self.N = len(m)

    @classmethod
    def normal(self, n):
        return Matrix2([[0 if i != j else 1 for j in xrange(n)] for i in xrange(n)])

    @classmethod
    def zero(self, n):
        return Matrix2([[0] * n for _ in xrange(n)])

    def __mul__(self, other):
        ret = Matrix2.zero(self.N)
        for i in xrange(self.N):
            for j in xrange(self.N):
                for k in xrange(self.N):
                    ret[i][j] += self[i][k] * other[k][j]
        return ret

    def __repr__(self):
        return "[" + "\n ".join(map(str, self)) + "]"

    def _pow2(self):
        return self.__mul__(self)

    def __pow__(self, n):
        if n == 0:
            return Matrix2.normal(self.N)
        if n == 2:
            return self._pow2()
        res = Matrix2.normal(self.N)
        x = Matrix2(self)
        while n != 0:
            if (n & 1) == 1:
                res = res * x
            x = x ** 2
            n >>= 1
        return res

if __name__ == "__main__":
    main()

Measured memory_bytes: 4340
use std::io::{BufRead, Write};

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut writer = std::io::BufWriter::new(stdout.lock());

    let x: Vec<usize> = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    for i in 0..5 {
        if x[i] == 0 {
            writeln!(writer, "{}", i + 1).unwrap();
        }
    }
}

Measured memory_bytes: 2120
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	cin >> s;
	while (1) {
		if (s == "-") break;
		int m;
		cin >> m;
		for (int i = 0; i < m; i++) {
			int h;
			cin >> h;
			string b = s.substr(0, h);
			string a = s.substr(h, s.size() - h);
			s = a + b;
		}
		cout << s << endl;
		cin >> s;
	}
	return 0;
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define rep(i,l,r)  for(int i=l;i<=r;i++)
#define pre(i,r,l)  for(int i=r;i>=l;i--)
#define pii pair<int,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int maxn = 500005;
inline int read(){
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}


int main() {
   string s; cin >> s;
   if(s == "ABC") puts("ARC");
   else puts("ABC");
}


Measured memory_bytes: 3588
{-# OPTIONS_GHC -O #-}

import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as M

main = do
    (n:m:_)<-map read.words<$>getLine::IO [Int]
    lrds <- replicateM m $ unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine :: IO[[Int]]
    let grp = foldl (\m (l:r:d:_)->M.alter (ins l (-d)) r $ M.alter (ins r d) l m) M.empty lrds
    putStrLn $ if solve n grp lrds then "Yes" else "No"
--
ins ::Int -> Int -> Maybe [(Int,Int)] -> Maybe [(Int,Int)]
ins n w Nothing = Just [(n,w)]
ins n w (Just nws) = Just ((n,w):nws)
--
solve :: Int -> M.IntMap [(Int,Int)] -> [[Int]] -> Bool
solve n grp lrds = runST $ do
    ckd <- VM.replicate (n+1) False :: ST s (VM.STVector s Bool)
    dst <- VM.replicate (n+1) 0 :: ST s (VM.STVector s Int)
    fmap and $ forM [1..n] $ \i -> do
        d <- VM.unsafeRead dst i
        dfs grp ckd dst (i,d)
--
dfs :: M.IntMap [(Int,Int)] -> VM.STVector s Bool -> VM.STVector s Int -> (Int,Int) -> ST s Bool
dfs grp ckd dst (x,d) = do
    c <- VM.unsafeRead ckd x
    dd <- VM.unsafeRead dst x
    if c then return $ dd==d
    else do
        VM.unsafeWrite ckd x True
        VM.unsafeWrite dst x d
        fmap and $ mapM (dfs grp ckd dst.(\(u,v)->(u, v+d))) $ M.findWithDefault [] x grp


Measured memory_bytes: 144764
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int d[5];

int main(void){
	          int i;

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

	      	  string s;
	      	  cin >> s;

	      	  int n=s.size();

	      	  REP(i,n){
	      		  if(s[i]=='a') d[0]++;
	      		  if(s[i]=='b') d[1]++;
	      		  if(s[i]=='c') d[2]++;
	      	  }

	      	  if((d[0]==0 && d[1]==0) || (d[0]==0 && d[2]==0) || (d[1]==0 && d[2]==0)){
	      		  if(n==1) cout << "YES" << endl;
	      		  else cout << "NO" << endl;
	      	  }
	      	  else if((d[0]==0 && d[1]!=0 && d[2]!=0) || (d[1]==0 && d[2]!=0 && d[0]!=0) || (d[2]==0 && d[0]!=0 && d[1]!=0)){
	      		  if(n==2) cout << "YES" << endl;
	      		  else cout << "NO" << endl;
	      	  }else{
	      		  if(abs(d[0]-d[1])>=2 || abs(d[0]-d[2])>=2 || abs(d[1]-d[2])>=2) cout << "NO" << endl;
	      		  else cout << "YES" << endl;
	      	  }

	          return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
	int N,A,B,ans=0;
	cin>>N>>A>>B;
	for(int i=1;i<=N;i++){
		int c=0,n=i;
		for(int j=0;j<5;j++){
			c=c+n%10;
			n=n/10;
		}
		if(A<=c&&c<=B)ans=ans+i;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	string ss; cin >> ss;
	
	deque<char> s(ss.size());
	for (int i = 0; i < ss.size(); i++) {
		s[i] = ss[i];
	}


	int rev = 0;
	int q; cin >> q; while (q--) {
		int t; cin >> t;
		if (t == 1) rev ^= 1;
		else {
			int f;
			char c;
			cin >> f >> c;
			f--; f ^= rev;
			if (f == 0) {
				s.push_front(c);
			} else {
				s.push_back(c);
			}
		}
	}
	if (rev) {
		reverse(all(s));
	}
	for (auto c : s) {
		cout << c;
	}
	cout << endl;


	return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5


*/

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

int main() {
  int N;
  cin >> N;
  map<int, int> MA;
  int A;
  while (cin >> A) MA[A]++;
  int ans = 0;
  for (auto [a, b] : MA) {
    if (a == b) continue;
    if (a > b) ans += b;
    if (a < b) ans += b - a;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 7912
a, b, c, d = map(int, input().split())

from fractions import gcd

lcm = (c * d) // gcd(c, d)
x = b - (b // c + b // d - b // lcm)

a = a - 1
y = a - (a // c + a // d - a // lcm)

print(x - y)


Measured memory_bytes: 5560