akhauriyash/Code-Regression huggingface dataset:
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>
using namespace std;
//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007
int main() {
	int n, cnt = 0,memo=-1;
	cin >> n;
	VI a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	for (int i = 0; i < n; i++) {
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			cnt++;
		}
	}

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

Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
a = [list(map(int, input().split())) for _ in range(q)]

b = [0] * n
cnt = 0
for i in range(n-1):
	if s[i:i+2] == "AC":
		b[i+1] = b[i] + 1
	else:
		b[i+1] = b[i]
for i in a:
	print (b[i[1]-1] - b[i[0]-1])

Measured memory_bytes: 30656
import heapq

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sorted(A, reverse=True)
b = sorted(B, reverse=True)
c = sorted(C, reverse=True)

added = [(0, 0, 0)]
cakes = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
for k in range(K):
	v = heapq.heappop(cakes)
	print(-v[0])
	va, vb, vc = v[1:]
	if va < X - 1 and (va + 1, vb, vc) not in added:
		heapq.heappush(cakes, (-(a[va + 1] + b[vb] + c[vc]), va + 1, vb, vc))
		added += [(va + 1, vb, vc)]
	if vb < Y - 1 and (va, vb + 1, vc) not in added:
		heapq.heappush(cakes, (-(a[va] + b[vb + 1] + c[vc]), va, vb + 1, vc))
		added += [(va, vb + 1, vc)]
	if vc < Z - 1 and (va, vb, vc + 1) not in added:
		heapq.heappush(cakes, (-(a[va] + b[vb] + c[vc + 1]), va, vb, vc + 1))
		added += [(va, vb, vc + 1)]


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

int main(){
    unsigned long long ans[3];
    int n, k;

    ans[0] = ans[1] = ans[2] = (unsigned long long)-1;

    cin >> n >> k;

    int *x = new int[k];

    
    for(int i=0, cnt=0; i<n; ++i){
        cin >> x[cnt];

        if(cnt == k-1){
            ans[1] = abs(x[0]) + abs(x[cnt] - x[0]);
            ans[2] = abs(x[cnt]) + abs(x[0] - x[cnt]);

            sort(ans, ans + 3);

            for(int j=0; j<k-1; ++j){
                x[j] = x[j+1];
            }
        }else{
            ++cnt;
        }
    }

    cout << ans[0] << endl;

    delete[] x;
}


Measured memory_bytes: 640
class Integer
    def price_playable
        [1, 6, 9].each_with_object([]){|i, arr| 
            next arr << i if i == 1
            
            power = 1
            while i ** power <= self do
                arr << i ** power
                power += 1
            end
        }.sort
    end
end


def count_dp(n, price_playable) #dp法
    c_dp = Array.new(n+1, n)
    c_dp[0] = 0 
    
    (1..n).each{|i| 
        (0...price_playable.size).each{|j| 
            break if i < price_playable[j]
            #puts "#{i}, #{j}, #{c_dp[i]}, #{c_dp[i-price_playable[j]] + 1} , #{i-price_playable[j]}"
            c_dp[i] = c_dp[i-price_playable[j]] + 1 if c_dp[i] > c_dp[i-price_playable[j]] + 1
        }
    }
    
    c_dp[n]
end

n = gets.to_i
price_playable = n.price_playable
#p price_playable
x = count_dp(n, price_playable)
p x

Measured memory_bytes: 2556
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    map<li, li> counts;
    for (int i = 0; i < n; ++i) {
        li x;
        cin >> x;
        counts[x]++;
    }

    priority_queue<li> q;
    for (auto& t : counts) {
        q.push(t.second);
    }

    li ans = n, total = n;
    for (int k = 1; k <= n; ++k) {
        const li kind = q.size();
        if (kind < k) {
            cout << 0 << endl;
            continue;
        }
        while (ans > 0) {
            while (total > ans * k) {
                const li t = q.top();
                if (t <= ans) {
                    break;
                }
                total--;
                q.pop();
                if (t - 1 > 0) {
                    q.push(t - 1);
                }
            }
            if (q.top() <= ans && ans * k <= total) {
                break;
            } else {
                ans--;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a,b;
  int answer = 0;
  
  for(int i = 0; i<N; i++){
    cin >> a >> b;
    answer += b - a + 1;
  }
  
  cout << answer << endl;
  
}

Measured memory_bytes: 256
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,M=pin()
    ans=[0]*N
    for i in range(M):
        a,b=pin()
        ans[a-1]+=1
        ans[b-1]+=1
    for an in ans:
        print(an)
#%%submit!
resolve()

Measured memory_bytes: 38256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
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; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}
int main()
{
    string n;
    cin >> n;
    int x = n.size();

    if(n[x-1] == '2' ||n[x-1] == '4'||n[x-1] == '5'||n[x-1] == '7'||n[x-1] == '9'){
        cout << "hon" << endl;
    }

    else if(n[x-1] == '3') cout << "bon" << endl;
    else cout << "pon" << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#define reg register
#define EN std::puts("")
#define LL long long
inline int read(){
	register int x=0;register int y=1;
	register char c=std::getchar();
	while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
	return y?x:-x;
}
int a[106];
int n,m;
int main(){
	n=read();m=read();
	int tot=0;
	for(reg int i=1;i<=n;i++) tot+=(a[i]=read());
	int least=std::ceil((double)tot/4/m);
	int ans=0;
	for(reg int i=1;i<=n;i++) ans+=(a[i]>=least);
	std::puts(ans>=m?"Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#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 pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000000007
#define MOD 1000000007
#define ARRAY_MAX 3005

int main(){

    int n,a,b;
    cin >> n >> a >> b;
    vector<int> arr(n);
    vector<int> vec(3,0);
    REP(i,n){
        cin >> arr[i];
        if(arr[i] <= a){
            vec[0]++;
        }
        if(arr[i] >= a+1 && arr[i] <= b){
            vec[1]++;
        }
        if(arr[i] >= b+1){
            vec[2]++;
        }
    }
    int ans = vec[0];
    REP(i,3){
        ans = min(ans,vec[i]);
    }
    cout << ans << endl;



    return 0;
}

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

int n;

vector<int> f(int a, int b, int poss) {
    if (__builtin_popcount(poss) == 1) {
        if (__builtin_popcount(a ^ b) == 1)
            return {a, b};
        else
            return {};
    }

    int x = a;
    a ^= x;
    b ^= x;
    if (__builtin_popcount(b) % 2 == 0) {
        return {};
    }

    vector<int> indices;
    for (int i = 0; i < n; i++) {
        if (b & (1 << i)) {
            indices.push_back(i);
        }
    }

    int t = indices[0];
    b ^= 1 << t;

    int c = 0;
    int e = b;
    for (int i = 0; i < n && c < 1; i++) {
        if ((poss & (1 << i)) && (i != t)) {
            e ^= 1 << i;
            c++;
        }
    }
    // case 2????


    // here all with t = indices[0] = 0
    vector<int> res0 = f(a, e, poss ^ (1 << t));
    // then all with t = indices[0] = 1
    vector<int> res1 = f(e ^ (1 << t), b ^ (1 << t), poss ^ (1 << t));

    res0.insert(res0.end(), res1.begin(), res1.end());
    for (auto& y : res0) {
        y ^= x;
    }
    return res0;
}



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

    cin >> n;
    int a, b;
    cin >> a >> b;
    auto res = f(a, b, (1 << n) - 1);
    if (res.size() == (1 << n)) {
        cout << "YES" << '\n';
        for (auto x : res) {
            cout << x << ' ';
        }
        cout << '\n';
    } else {
        cout << "NO" << '\n';
    }
}


Measured memory_bytes: 1780
N = int(input())

restaurants = []
for i in range(1, N + 1):
    name, point = input().split()
    restaurants.append([i, name, int(point)])

restaurants.sort(key=lambda x: x[2], reverse=True)
restaurants.sort(key=lambda x: x[1])

for r in restaurants:
    print(r[0])

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

#define W 0
#define H 1

using Data = pair<int, int>;
using Pair = pair<int, Data>;
int w;
int h;
int WS[114];
int hs[114];
int xs[11][11];
priority_queue<Pair> es;

int main() {
  while (1) {
    scanf("%d%d", &w, &h);
    if (w == 0 && h == 0) return 0;

    multiset<int> wst;
    int ans = 0;
    for (int i=0; i<w; i++) {
      scanf("%d", &WS[i]);
      es.push(Pair(WS[i], Data(i, W)));
      wst.insert(WS[i]);
      ans += WS[i];
    }
  
    for (int i=0; i<h; i++) {
      scanf("%d", &hs[i]);
      es.push(Pair(hs[i], Data(i, H)));
      ans += hs[i];
      if (wst.count(hs[i])) {
        ans -= hs[i];
        wst.erase(wst.find(hs[i]));
      }
    }

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

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

int main()
{
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    bool is_ok = false;
    rep(k, 0, n-1)
    {
        ll max_v = k * d - (n-k-1) * c;
        ll min_v = k * c - (n-k-1) * d;
        if (min_v <= b-a and b-a <= max_v)
            is_ok = true;
    }
    if (is_ok)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

use std::cmp::*;
use std::collections::*;
use std::ops::*;

// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

fn solve() {
    let x = read!(f64);
    let mut val = 100_f64;
    let mut ans = 0;
    loop {
        val *= 1.01;
        val = val.floor();
        ans += 1;
        if val>=x {
            break;
        }
    }
    println!("{}", ans);
}

fn run() {
    solve();
}


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

int main( void ) {
  int n, c;
  string s1, s2;

  cin >> n;
  cin >> s1;
  s2 = s1;

  for(int i=0;i<s1.size();i++) {
    c = s1.at(i);
    c += n;
    if(c>'Z') c-= 26;
    s2.at(i) = c;
  }
	cout << s2 <<endl;
  return ( 0 );
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[100];
int main()
{
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size();i++)
		if(s[i]=='1')
			ans++;
	cout<<ans<<endl;
	return  0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long long int a,b,c;
  scanf("%lld %lld %lld",&a,&b,&c);
  long long int d=c-a-b;
  if(d>0LL && 4LL*a*b<d*d) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<math.h>
 
int main(){
  double x[1001],y[1001],D1=0,D2=0,D3=0,max=0,D4;
  int i,j,n;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%lf",&x[i]);
  }
 
  for(i=0;i<n;i++){
    scanf("%lf",&y[i]);
  }
 
  for(i=0;i<n;i++){
    D1+=fabs(x[i]-y[i]);
  }
  printf("%.11f\n",D1);
 
  for(i=0;i<n;i++){
    D2+=fabs(x[i]-y[i])*fabs(x[i]-y[i]);
  }
  D2=sqrt(D2);
 
  printf("%.11f\n",D2);
 
  for(i=0;i<n;i++){
    D4+=fabs(x[i]-y[i])*fabs(x[i]-y[i])*fabs(x[i]-y[i]);
  }
  D4=cbrt(D4);
  printf("%.11f\n",D4);
   
   
  for(i=0;i<n;i++){
    if(max<fabs(x[i]-y[i])) max=fabs(x[i]-y[i]);
  }
  printf("%.11f\n",max);
  return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

bool ok[111111];

int main(){
	
	string str;cin >> str;
	ok[0] = true;
	string tmp[] = {"dream","dreamer","erase","eraser"};
	REP(i, str.size())if(ok[i]){
		REP(j, 4){
			bool flag = true;
			REP(k, tmp[j].size()){
				if(i + k >= str.size() || str[i+k] != tmp[j][k]){
					flag = false;
					break;
				}
			}
			if(flag)ok[i+tmp[j].size()] = true;
		}			
	}
	
	cout << (ok[str.size()] ? "YES" : "NO") << endl;
	
	return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
        }
        
        Arrays.sort(a);
        
        int Alice = 0;
        int Bob = 0;
        for(int i = N - 1; i >= 0; i -= 2){
            Alice += a[i];
        }
        for(int i = N - 2; i >= 0; i -= 2){
            Bob += a[i];
        }
        System.out.println(Alice - Bob);
    }
}


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

const int INF = 1100000000;

int main() {
  string str;
  int a, z;
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == 'A') {
      a = i;
      break;
    }
  }
  for (int i = str.size() - 1; i >= 0; i--) {
    if (str.at(i) == 'Z') {
      z = i;
      break;
    }
  }
  cout << z - a + 1 << endl;
}


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

using namespace std;

int N, ap[20], E[100009], d[1 << 16], frm[1 << 16];
vector < pair < int, int > > h[100009];
vector < pair < int, int > > v[1 << 16];
bool ap2[1 << 16][4];

void dfs (int nod, int tata)
{
    for (auto it : h[nod])
        if (it.first != tata)
            E[it.first] = it.second, dfs (it.first, nod), E[nod] ^= it.second;
}

priority_queue < pair < int, int > > PQ;
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<N; i++)
{
    int x, y, z;
    scanf ("%d %d %d", &x, &y, &z), x ++, y ++;
    h[x].push_back ({y, z});
    h[y].push_back ({x, z});
}
dfs (1, -1);
for (int i=2; i<=N; i++)
    ap[E[i]] ++;
int ans = 0, msk = 0;
for (int i=1; i<16; i++)
{
    if (ap[i] & 1) msk |= 1 << i;
    ans += (ap[i] >> 1);
}
for (int msk = 0; msk < (1 << 16); msk +=2)
{
    vector < pair < int, int > > curr;
    for (int i=1; i<16; i++)
    {
        if (msk & (1 << i))
        {
            curr.push_back ({msk ^ (1 << i), 1});
            int aux = msk ^ (1 << i);
            for (int j=1; j<16; j++)
                if (aux & (1 << j))
                {
                    if (aux & (1 << (j ^ i))) curr.push_back ({aux ^ (1 << j) ^ (1 << (j ^ i)), 2});
                    else curr.push_back ({aux ^ (1 << j) ^ (1 << (j ^ i)), 1});
                }
        }
        else
        {
            for (int j=1; j<16; j++)
                if (msk & (1 << j))
                    for (int k=j + 1; k<16; k++)
                        if (msk & (1 << k))
                        {
                            int to = msk ^ (1 << j) ^ (1 << k), cst = 1;
                            if (to & (1 << (j ^ i))) cst ++;
                            to ^= (1 << (j ^ i));
                            if (to & (1 << (k ^ i))) cst ++;
                            to ^= (1 << (k ^ i));
                            curr.push_back ({to, cst});
                        }
            for (int j=1; j<16; j++)
                if (msk & (1 << j))
                {
                    int to = msk ^ (1 << j), cst = 1;
                    if (to & (1 << (j ^ i))) cst ++;
                    to ^= (1 << (j ^ i));
                    curr.push_back ({to, cst});
                }
        }
    }
    for (auto it : curr)
        if (ap2[it.first][it.second] == 0)
            ap2[it.first][it.second] = 1, v[msk].push_back (it);
    for (auto it : v[msk])
        ap2[it.first][it.second] = 0;
}
for (int i=0; i<(1 << 16); i++)
    d[i] = -1;
PQ.push ({0, msk}), d[msk] = 0;
for (int i=1; i<16; i++)
    if ((msk & (1 << i)) == 0)
        PQ.push ({0, msk | (1 << i)}), d[msk | (1 << i)] = 0;
while (!PQ.empty ())
{
    auto curr = PQ.top ();
    PQ.pop ();
    if (d[curr.second] != -curr.first) continue;
    int nod = curr.second;
    for (auto it : v[nod])
        if (d[it.first] == -1 || (d[it.first] > d[nod] + it.second))
            d[it.first] = d[nod] + it.second, PQ.push ({-d[it.first], it.first}), frm[it.first] = nod;
}
printf ("%d\n", ans + d[0]);
return 0;
}


Measured memory_bytes: 65664
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

print(max(a) - min(a))

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

typedef long long ll;
using namespace std;

int main() {
  int h,w;
  cin >> h >> w;

  string s[h*w];

  rep(i,0,h) cin >> s[i];

  rep(i,0,h){
    rep(j,0,w){
      if(s[i][j] == '#') printf("#");
      else{
        int count = 0;
        rep(k,0,8){
          int cx = i + d8x[k], cy = j + d8y[k];
          if(cx < 0 || cx >= h || cy < 0 || cy >= w) continue;
          if(s[cx][cy] == '#') count++;
        }
        s[i][j] = count;
        printf("%d",s[i][j]);
      }
    }
    printf("\n");
  }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int gcd(int a,int b){return a%b==0?b:gcd(b,a%b);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;cin >> n;
	if(n<10) cout << n << endl;
	else{
		int ans=0;
		bool flg=true;
		while(n>0){
			if(n>=10 && n%10!=9) flg=false;
			if(n<10) ans+=n-1;
			else ans+=9;
			n/=10;
		}
		if(flg) cout << ans+1 << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 256
D = int(input())
C = [0] + list(map(int,input().split()))
ls_s = [[0]*27] + [[0] + list(map(int,input().split())) for _ in range(D)]
ls_t = [0] + [int(input()) for _ in range(D)]


Score = 0
ls_last = [0] * 27
for d in range(1,D+1):
  a = ls_t[d] #どのコンテストか
  ls_last[a] = d
  Score += ls_s[d][a]
  for i in range(1,27):
    Score -= C[i] * (d - ls_last[i])
  print(Score)  

Measured memory_bytes: 74024
/*---> 04 April 2020 <--- > 14:14:46 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vi a1(a),a2(b),a3(c);
	for(int i=0;i<a;i++)
		cin>>a1[i];
	for(int i=0;i<b;i++)
		cin>>a2[i];
	for(int i=0;i<c;i++)
		cin>>a3[i];
	sort(rall(a1));
	sort(rall(a2));
	// sort(rall(a3));
	for(int i=0;i<min(x,a);i++)
		a3.push_back(a1[i]);
	for(int i=0;i<min(y,b);i++)
		a3.push_back(a2[i]);
	sort(rall(a3));
	int s=0;
	for(int i=0;i<(x+y);i++)
		s+=a3[i];
	cout<<s<<"\n";
return 0;
}

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

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	
	if(x + r > W || x - r < 0)
	{
		if(y + r > H || y - r < 0)
		    cout << "No" << endl;
		else if(y + r <= H && y - r >= 0)
		    cout << "No" << endl;
		else
		    cout << "No" << endl;
	}
	else if(x + r <= W && x - r >= 0)
	{
		if(y + r > H || y - r < 0)
		    cout << "No" << endl;
		else if(y + r <= H && y - r >= 0)
		    cout << "Yes" << endl;
		else
		    cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional> 

using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int (i)=0;(i)<(n);++(i))
#define rep(i,st,ed) for(register int (i)=(st);(i)<=(ed);++(i))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<typename T> inline T qmin(const T a,const T b) {return a<b?a:b;}
template<typename T> inline T qmax(const T a,const T b) {return a>b?a:b;}
template<typename T> inline void getmin(T &a,const T b) {if(a>b) a=b;}
template<typename T> inline void getmax(T &a,const T b) {if(a<b) a=b;}

inline void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=1e9+7;
const ll linf=1e17+7;
const int N=1e5+107,M=4e5+107;

int v[M],nxt[M],m;
int head[N],used[N],n;
ll cnt1,cnt2,cnt3;//1-bipartite 2-not_bipartite 3-single vertices

il void addedge(int p,int x,int y){
	v[p]=y,nxt[p]=head[x],head[x]=p;
}

il bool dfs(int u,int c){
	used[u]=c;
	bool ans=true;
	for(int e=head[u];e;e=nxt[e]){
		if(used[v[e]]){
			if(c+used[v[e]]!=3) ans=false;
		}else{
			ans&=dfs(v[e],3-c);
		}
	}
	return ans;
} 

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i){
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(lch(i),x,y);
		addedge(rch(i),y,x); 
	}
	for(int i=1;i<=n;++i){
		if(used[i]) continue;
		if(dfs(i,1)){
			if(head[i]) ++cnt1;else ++cnt3;
		}else{
			++cnt2;
		}
	}
//	cerr<<cnt1<<endl<<cnt2<<endl<<cnt3<<endl;
	printf("%lld\n",(2*cnt3*n-cnt3*cnt3)+(2*cnt1*cnt1)+(cnt2*cnt2+2*cnt1*cnt2)); 
	return 0;
} 

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  fo(i,n) for(ll i=0;i<n;i++)
#define rfo(i,n) for(ll i=n;i>=0;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()

void solve()
{
	string s;
	cin>>s;
	ll ans =0;
	fo(i,s.length())
	{
		ans = ans + (s[i]-'0');
		if(ans>9 && ans%9 == 0)
		{
			ans =0;
		}
	}
	if(ans%9 == 0)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3700
n = int(input())
a = [int(input()) for _ in range(n)]
seen = [False] * n
seen[0] = True
ans = 0
now = 1
while not now == 2:
    ans += 1
    now = a[now-1]
    if seen[now-1] == True:
        print(-1)
        exit(0)
    seen[now-1] = True
print(ans)

Measured memory_bytes: 7852
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=20;

int n;

int a[maxn];

struct node {
	int l,r,fl,fr;
	node(int _l=0,int _r=0,int _fl=0,int _fr=0){ l=_l; r=_r; fl=_fl; fr=_fr;}
};

inline bool operator <(node a,node b)
{
	return a.l==b.l?a.r==b.r?a.fl==b.fl?a.fr<b.fr:a.fl<b.fl:a.r<b.r:a.l<b.l;
}

inline bool operator ==(node a,node b){ return a.l==b.l && a.r==b.r && a.fl==b.fl && a.fr==b.fr;}

inline void init()
{
	n=read();
	REP(i,1,n)a[i]=read();
}

map<node,ll>mp;

ll dfs(int l,int r,int fl,int fr)
{
	if(l==r-1)return 0;
	if(l+1==r-1)return 1ll*(fl+fr)*a[l+1];
	node x(l,r,fl,fr);
	if(mp.count(x))return mp[x];
	ll ans=1ll<<60;
	REP(k,l+1,r-1)
	{
		ll num=1ll*(fl+fr)*a[k];
		chkmin(ans,num+dfs(l,k,fl,fl+fr)+dfs(k,r,fl+fr,fr));
	}
	return mp[x]=ans;
}

inline void doing()
{
	printf("%lld\n",dfs(1,n,1,1)+a[1]+a[n]);
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
int main(){
int p,q,r,a,b,c,d;
cin >> p >> q >> r;
a=p+q;
b=q+r;
c=r+p;
d=min(a,min(b,c));
cout << d;

return 0;
}


 

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt(); // white : true
    int B = sc.nextInt(); // black : false
    System.out.println("100 100");
    boolean ans[][] = new boolean[100][100];
    // initialize
    for (int i=0; i<100; i++) {
      for (int j=0; j<100; j++) {
        if (i < 50) {
          ans[i][j] = true;
        } else {
          ans[i][j] = false;
        }
      }
    }
    for (int i=0; i<B-1; i++) {
      ans[2*(i/50)][2*(i%50)] = false;
    }
    for (int i=0; i<A-1; i++) {
      ans[2*(i/50) + 51][2*(i%50)] = true;
    }
    
    for (int i=0; i<100; i++) {
      for (int j=0; j<100; j++) {
        if (ans[i][j]) {
          System.out.print('.');
        } else {
          System.out.print('#');
        }
      }
      System.out.println();
    }
  }
}

Measured memory_bytes: 25812
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

vector<int> a;
long long memo[200][21];
long long dp(int n);

int main(void){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.push_back(t);
	}

	cout << dp(n) << endl;

	return 0;
}

long long dp(int n){

	for(int i=0; i<n; i++){
		for(int j=0; j<=20; j++){
			memo[0][i] = 0;
		}
	}
	memo[0][a[0]] = 1;

	for(int i=1; i<n-1; i++){
		for(int j=0; j<=20; j++){
			int add = j + a[i];
			int sub = j - a[i];
			if(add >= 0 && add <= 20) memo[i][add] += memo[i-1][j];
			if(sub >= 0 && sub <= 20) memo[i][sub] += memo[i-1][j];
		}
	}

	/*
	for(int i=0; i<n-1; i++){
		for(int j=0; j<=20; j++){
			printf("%lld ", memo[i][j]);
		}
		puts("");
	}
	*/

	return memo[n-2][a[n-1]];
}

Measured memory_bytes: 1232
/*
17D8101031C 杉山　祥吾 ID:keisei334 C++
*/

#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>

using namespace std;

#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head,tail, n;

void enqueue(P x){
  Q[tail] = x;
  if(tail == n){
    tail = 0;
  }else{
    tail++;
  }
}

P dequeue(){
  P x = Q[head];
  if(head == n){
    head = 0;
  }else{
    head++;
  }
  return x;
}


int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;

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

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head=1;
  tail=0;

  do{
    if(Q[head].t>q){
      elaps+=q;
      Q[head].t=Q[head].t-q;
      u=dequeue();
      enqueue(u);
    }else{
      elaps+=Q[head].t;
      Q[head].t=0;
      cout<<Q[head].name<<" "<<elaps<<"\n";
      dequeue();
    }
  }while(head!=tail);
  
  return 0;
}

/*実行結果
5 100
p1 150                               
p2 80
p3 200
p4 350
p5 20
p2 180
p5 400
p1 450
p3 550
p4 800
*/


Measured memory_bytes: 8132
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		int result = -1;
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int[] s = new int[m];
		int[] c = new int[m];
		for(int i = 0; i < m; i++){
			s[i] = scanner.nextInt();
			c[i] = scanner.nextInt();
		}
		int maxNum = 0;
		if(n == 1) maxNum = 9;
		if(n == 2) maxNum = 99;
		if(n == 3) maxNum = 999;

		if(n == 1){
			if(m == 0){
				result = 0;
			}else{
				Arrays.sort(c);
				int tmp = c[0];
				result = c[0];
				for(int i = 0; i<m; i++){
					if(tmp != c[i]){
						result = -1;
						break;
					}
					tmp = c[i];
				}
			}

		}

		if(n == 2){
			Boolean isOK = false;
			for(int i = 10; i <= maxNum; i++){
				isOK = checkTwo(i,s,c);
				if(isOK){
					result = i;
					break;
				}
			}
		}

		if(n == 3){
			Boolean isOK = false;
			for(int i = 100; i <= maxNum; i++){
				isOK = checkThree(i,s,c);
				if(isOK){
					result = i;
					break;
				}
			}
		}
		System.out.println(result);
	}
	private static Boolean checkTwo(int i, int[] s, int[] c){
		int tt = i /10;
		int t = i%10;
		Boolean isOK = true;
		for(int j = 0; j < s.length; j++){
			if(s[j] == 1){
				if(tt != c[j]){
					isOK = false;
					break;
				}
			}

			if(s[j] == 2){
				if(t != c[j]){
					isOK = false;
					break;
				}
			}
		}
		return isOK;
	}

	private static Boolean checkThree(int i, int[] s, int[] c){
		int ttt = i / 100;
		int tt = (i % 100) /10;
		int t = i%10;
		Boolean isOK = true;
		for(int j = 0; j < s.length; j++){
			if(s[j] == 1){
				if(ttt != c[j]){
					isOK = false;
					break;
				}
			}

			if(s[j] == 2){
				if(tt != c[j]){
					isOK = false;
					break;
				}
			}

			if(s[j] == 3){
				if(t != c[j]){
					isOK = false;
					break;
				}
			}
		}
		return isOK;
	}

}


Measured memory_bytes: 23380
import numpy as np
from decimal import Decimal

N, A, B = map(Decimal, input().split())
ab_max = np.amax(np.array([A, B]))
ab_min = np.amin(np.array([A, B]))

if (A - B) % 2 == 0:
    print(int((ab_max - ab_min) / 2))
else:
    print(int(np.amin([ab_min - 1, N - ab_max]) + (ab_max - ab_min + 1) / 2))


Measured memory_bytes: 22668
import java.io.PrintWriter;
import java.util.Scanner;

class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        while(true){
            final int h = Integer.parseInt(sc.next());
            final int w = Integer.parseInt(sc.next());
            if(h==0&&w==0) break;
            for(int i = 0; i<h; i++){
                for(int j = 0; j<w; j++){
                    out.print("#");
                }
                out.println();
            }
            out.println();
        }
        out.flush();
    }
}

Measured memory_bytes: 28144
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
H_list = list(map(int, input().split()))

low_set = set()
for i in range(M):
    A, B = map(int, input().split())
    if H_list[A - 1] == H_list[B - 1]:
        low_set.add(A)
        low_set.add(B)
    elif H_list[A - 1] > H_list[B - 1]:
        low_set.add(B)
    else:
        low_set.add(A)

print(N - len(low_set))

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

#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))

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


int main(){
string S,T; cin>>S>>T;
int ans=0;
for(int i=0;i<(S.size()-T.size()+1);i++){
    int cou=0;
    for(int j=0;j<T.size();j++){
        if(T.at(j)==S.at(j+i)){
            cou++;

        }
    }
    if(ans<cou){
        ans=cou;
    }
}
 cout<<T.size()-ans<<endl;
}
  

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

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) { cin >> a[i]; }

  sort(a, a + n);
  rep(i, n - 1) {
    if (a[i] == a[i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	int l, r, d;
	cin >> l >> r >> d;
	printf("%d\n", r / d - (l - 1) / d);
	return 0;
}

Measured memory_bytes: 3748
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut d: Vec<usize> = vec(n, |_| scan(tokens));
    d.sort();
    println!("{}", d[n / 2] - d[n / 2 - 1]);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1 + 1e5;
typedef long long LL;
typedef pair < int, int > II;
typedef pair < int, II > III;

int n, a[MAXN][3], f[MAXN][3];

int main()
{
    #define TASK "ABC"
 //   freopen(TASK".inp","r",stdin);
 //   freopen(TASK".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 3; k++){
                if (j == k)continue;
                f[i][j] = max (f[i][j] , f[i-1][k] + a[i][j]);
            }
        }
    }
    cout << max (f[n-1][0] , max (f[n-1][1] , f[n-1][2]));
    return 0;
}




Measured memory_bytes: 2560
#include<iostream>

using namespace std;

int main(){
  int n,m;
 cin >> n >> m;
  
  int a[m],b[m];
  int cnt[n]={0};
  
  for(int i=0;i<m;i++) {
   cin >> a[i] >> b[i];
    cnt[a[i]-1]++;
    cnt[b[i]-1]++;
  }
 
  for(int i=0;i<n;i++) cout << cnt[i] << endl;
}

Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  while(cin >> n){
    int tmp = n;
    vector<int> res;
    for(int i = 9; i >= 0; i--){
      if(tmp >= (1 << i)){
        res.pb((1 << i));
        tmp -= (1 << i);
      }
    }
    for(int i = res.size() - 1; i >= 0; i--){
      cout << res[i];
      if(i != 0)cout << " ";
      else cout << endl;
    }
  }
	return 0;
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
void Add(int &x, int y) { (x += y) >= mod ? x -= mod : x; }
int n, res;
int inv[2000006];

int main() {
    scanf("%d", &n), inv[1] = 1;
    for (int i = 2; i <= max(n, 3); ++i)
        inv[i] = 1ll * inv[mod % i] * (mod - mod / i) % mod;
    for (int i = 1, p3 = inv[3]; i <= n; ++i, p3 = 1ll * p3 * inv[3] % mod)
        Add(res, 1ll * p3 * inv[n - i + 1] % mod);
    printf("%lld\n", 1ll * res * inv[n] % mod);
    return 0;
}

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

#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define loop(i,a,b) for(int i=a;i<b;i++)
#define inf (long long int) 1e18
#define vi vector<int> 
#define pii pair<int, int>
#define mii map<int, int> 
#define mod 1000000007

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

int palindrome(string s){
    int l = 0;
    int h = s.length() - 1;
    while (h > l){
        if (s[l++] != s[h--]){
            return 0;
        }
    }
    return 1;
}

long long modexp(long long a, long long b, long long m){
    if (b==0)
        return 1;
    long long temp = modexp(a,b/2,m);
    temp = (temp*temp)%m;
    if (b&1)
        return (temp*(a%m))%m; // if b is odd a^b = a^(b/2)*a^(b/2)*a
    return temp;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/

    string s,t;
    cin>>s>>t;
    //string s2;
    string s2=t+t;
    if(s2.find(s)!=string::npos) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int k, t;
    cin >> k >> t;
    int m = 0;
    for (int i = 0; i < t; ++i) {
        int a;
        cin >> a;
        m = max(m, a);
    }
    cout << max(0, m-(k-m)-1) << "\n";
    return 0;
}


Measured memory_bytes: 256
import sys
import math

input = sys.stdin.readline

K = int(input())
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        n = math.gcd(i, j)
        for l in range(1, K + 1):
            ans += math.gcd(n, l)

print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a, b; cin >> n >> a >> b;
  cout << min(n, min(a, b)) << ' ' << max(0, a+b-n) << "\n";
  return 0;
}


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

int main(){
  string S,T;
  cin>>S;
  cin>>T;
  cout<<T<<S<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL INF=1e18;
const int MAXN=60;
const double eps=1e-10;
LL a[MAXN];

int main()
{
    LL n;
    while(scanf("%lld",&n)!=EOF)
    {
        for(int i=1;i<=n;++i)
            scanf("%lld",&a[i]);
        bool flag=true;
        LL ans=0,div=0;
        int p=0;
        while(flag)
        {
            p=1;
            if(a[p]<n) flag=false;
            for(int i=2;i<=n;i++)
            {
                if(a[i]>a[p]&&a[i]>=n)
                {
                    flag=true;
                    p=i;
                }
            }
            if(flag)
            {
                div=a[p]/n;
                ans+=div;
                a[p]%=n;
                for(int i=1;i<=n;i++)
                    if(i!=p) a[i]+=div;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){

    int a,b,c;
    
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    
    if(b>c){
        printf("%d",c);
    }
    else if(b<c){
        printf("%d",b);
    }    
    else if(b==c){
        printf("%d",b);
    }
    
    if (a<b+c){
        printf(" %d",b+c-a);
    }
    else if(a>=b+c){
        printf(" 0");
    }    
}

Measured memory_bytes: 128