akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[derive(Clone, Default, Copy)]
struct Point {
    x: f64,
    y: f64,
}

impl Point {
    fn angle(&self) -> f64 {
        self.y.atan2(self.x) + std::f64::consts::PI
    }

    fn abs(&self) -> f64 {
        self.x.hypot(self.y)
    }
}

impl std::ops::Add for Point {
    type Output = Point;
    fn add(self, other: Point) -> Point {
        Point {
            x: self.x + other.x,
            y: self.y + other.y,
        }
    }
}

impl std::ops::Sub for Point {
    type Output = Point;
    fn sub(self, other: Point) -> Point {
        Point {
            x: self.x - other.x,
            y: self.y - other.y,
        }
    }
}

fn main() {
    let n = read::<usize>();
    let mut points = vec![];
    for _ in 0..n {
        let v = read_vec::<f64>();
        if v[0] == 0.0 && v[1] == 0.0 {
            continue;
        }
        points.push(Point { x: v[0], y: v[1] });
    }
    let n = points.len();
    let mut clone = points.clone();
    points.append(&mut clone);

    let mut points_angles = vec![];
    for (i, point) in points.into_iter().enumerate() {
        let mut angle = point.angle();
        if i >= n {
            angle += 2.0 * std::f64::consts::PI;
        }
        points_angles.push((angle, point));
    }
    points_angles.sort_by_key(|x| Total(x.0));

    let mut end_pointer = 0;
    let mut sum = Point { x: 0.0, y: 0.0 };
    let mut ans = 0.0;
    for i in 0..points_angles.len() {
        while end_pointer < points_angles.len()
            && sum.abs() < (sum + points_angles[end_pointer].1).abs()
            && end_pointer - i < n
        {
            sum = sum + points_angles[end_pointer].1;
            end_pointer += 1;
        }
        ans = max(Total(ans), Total(sum.abs())).0;
        sum = sum - points_angles[i].1;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,k;cin>>n>>k;
	ll a[n];For(i,0,n) cin>>a[i];
	ll ans=0;

	if(k>=n){
		ll temp = 0;
		vector<ll> e;
		For(i,0,n) e.pb(a[i]);
		sort(e.begin(),e.end());
		ll rem = k-n;
		for(ll x:e){
			if(x>0 || rem==0) temp+=x;
			else{
				rem--;
			}
		}
		ans = max(ans,temp);
	}

	For(i,0,n) For(j,i,n){
		ll total = i+(n-1-j);
		if(total>k) continue;
		ll rem = k-total;
		vector<ll> e;
		For(t,0,i) e.pb(a[t]);
		Fod(t,n,j+1) e.pb(a[t]);

		sort(e.begin(),e.end());
		ll sum=0;
		for(ll x:e){
			if(x>0 || rem==0) sum+=x;
			else{
				rem--;
			}
		}
		ans = max(ans,sum);
	}

	cout<<ans<<endl;








	
}

Measured memory_bytes: 256
s = input()
t = input()

count_s = dict(zip([chr(i) for i in range(97, 97+26)], [0]*26))
count_t = dict(zip([chr(i) for i in range(97, 97+26)], [0]*26))
for ss, tt in zip(s, t):
    count_s[ss] += 1
    count_t[tt] += 1
v_s = sorted(count_s.values())
v_t = sorted(count_t.values())

ans = 'Yes' if v_s == v_t else 'No'
print(ans)


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

int main(){
    int N, K, R, S, P, ans = 0;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    for(int i = 0; i < K; i++){
        bool sw;
        for(int j = 0; i + j * K < N; j++){
            if(j == 0 || T[i + (j - 1) * K] != T[i + j * K] || sw){
                if(T[i + j * K] == 'r') ans += P;
                if(T[i + j * K] == 's') ans += R;
                if(T[i + j * K] == 'p') ans += S;
                sw = false;
            }else{
                sw = true;
            }
        }
}
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 512
import heapq
n, m = map(int, input().split())
li = [-int(x) for x in input().split()]
heapq.heapify(li)
for i in range(m):
  a = heapq.heappop(li)
  heapq.heappush(li, a/2)
print(-sum(int(x) for x in li))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)

/////////////////////////////////////////////////////////

void Main() {
	vector<ll> N(3);
  rep(i, 0, 3) cin >> N[i];
  ll K; cin >> K;
  vector<vector<ll>> T(3);
  rep(i, 0, 3){
    rep(j, 0, N[i]){
      ll tmp; cin >> tmp;
      T[i].push_back(tmp);
    }
  }
  rep(i, 0, 3) sort(all(T[i]), greater<ll>());
  vector<ll> cand;
  rep(i, 0, min(N[0], K)){
    rep(j, 0, min(N[1], K)){
      cand.push_back(T[0][i] + T[1][j]);
    }
  }
  rep(i, 0, 3) sort(all(cand), greater<ll>());
  vector<ll> res;
  rep(i, 0, min(N[0] * N[1], K)){
    rep(j, 0, min(N[2], K)){
      res.push_back(cand[i] + T[2][j]);
    }
  }
  rep(i, 0, 3) sort(all(res), greater<ll>());
  rep(i, 0, K) cout << res[i] << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 43384
#include <bits/stdc++.h>
using namespace std;
int N, A[101010], gl[101010], gr[101010];
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if (i > 0)gl[i] = __gcd(gl[i - 1], A[i]);
        else gl[i] = A[i];
    }
    for(int i = N - 1; i >= 0; i--){
        if (i < N - 1)
            gr[i] = __gcd(gr[i + 1], A[i]);
        else gr[i] = A[i];
    }

    int result = 0;
    for(int i = 0 ; i < N; i++){
        if(i == 0)result = max(result, gr[i + 1]);
        else if(i == N - 1)result = max(result, gl[i - 1]);
        else result = max(result, __gcd(gl[i - 1], gr[i + 1]));
    }
    cout << result << endl;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main() {
  int N;
  bool isSevenExist = false;
  cin >> N;
  for (int i = 0; i < 3; i++) {
    if (N % 10 == 7) {
      isSevenExist = true;
      break;
    }
    N /= 10;
  }
  
  cout << (isSevenExist ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
fn main() {
    let ns: Vec<i64> = read_vec();
    let a: i32 = ns[0] as i32;
    let b: i32 = ns[1] as i32;
    let c: i32 = ns[2] as i32;
    let k: i64 = ns[3];
    
    if k % 2 == 0 {
        println!("{}", a - b);
    } else {
        println!("{}", b - a);
    }

}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
import itertools
 
n = int(input())
x = [list(map(int, input().split())) for i in range(n)]

ans = 0
cnt = 0

for i in itertools.permutations(x):
    cnt += 1
    for j in range(len(i) - 1):
        ans += ((i[j][0] - i[j + 1][0])**2 + (i[j][1] - i[j + 1][1])**2)**0.5

print(ans / cnt)

Measured memory_bytes: 3064
import java.util.Scanner;

 class Main{
 	int n;
	int k;
	int hoz=1;
	int x=0;
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
		n=sc.nextInt();
		while(n!=0){
		for(int i=0;i<n;i++){
			k=sc.nextInt();
						
				if(k>=2){
					hoz++;
				}else{
				}
				if(k==1){
					x++;
				}
			}
			
			if(hoz>=2){
				System.out.println(hoz+x);
			}else{
				System.out.println("NA");
			}
			
			hoz=1;
			x=0;
			n=sc.nextInt();
		}
	}

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

Measured memory_bytes: 158764
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define N 200002
ll n,X;
ll cal(ll x,ll y)
{
	if(x%y==0)return y*(2*(x/y)-1);
	return cal(y,x%y)+2*y*(x/y);
}
int main()
{
	scanf("%lld%lld",&n,&X);
	if(X>n/2)X=n-X;
	printf("%lld\n",cal(n-X,X)+n);
}


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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e6+10, mod=1e9+7;


int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,i; string s;
	cin>>n;
	map<string,int> mp;
	for(i=0;i<n;i++){
		cin>>s;
		sort(s.begin(),s.end());
		mp[s]++;
	}
	ll res=0;
	
	for(auto x:mp){
		res+=1ll*x.yy*(x.yy-1)/2;
	}
	cout<<res;
	
}


Measured memory_bytes: 11264
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ a ] = readMany(1).map(it => parseInt(it))
    console.log(a + a ** 2 + a ** 3)
})()


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

using namespace std;

int main()
{
    string n;
    cin>>n;
    for(int i=0;i<n.size();i++)
    {
        if(n[i]=='7')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;

int N, M, Q;
ll a[60], b[60], c[60], d[60];
ll ans = 0;

void dfs(vector<int> vec, int dps) {
    if (dps == N) {
        ll tmp = 0;
        for (int i = 0; i < Q; i++) {
            if (vec[b[i] - 1] - vec[a[i] - 1] == c[i]) {
                tmp += d[i];
            }
        }
        ans = max(tmp, ans);
    }
    else {
        if (dps == 0) {
            for (int i = 1; i <= M; i++) {
                vector<int> next = vec;
                next.push_back(i);
                dfs(next, dps+1);
            }
        }
        else {
            for (int i = vec[dps-1]; i <= M; i++) {
                vector<int> next = vec;
                next.push_back(i);
                dfs(next, dps+1);
            }
        }
        
    }
    return;
}


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

    vector<int> aaa;
    dfs(aaa, 0);

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


Measured memory_bytes: 3632
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
string enc;
vector<string> decoding;

void dfs(int index, string s){
	if(index == enc.size()){
		vector<bool> use_moji(26,false);
		use_moji[0] = true;
		bool is_match = true;
		for(int i=0;i<enc.size();i++){
			int moji_index = s[i] - 'a';
			if(use_moji[moji_index] == false && (char)(s[i]-1) == enc[i]){
				use_moji[moji_index] = true;
			}else if(use_moji[moji_index] == true && s[i] == enc[i]){
			}else{
				is_match = false;
				break;
			}
		}
		if(is_match)decoding.push_back(s);
		return;
	}
	/*	cout << s + char(enc[index] + 1) << endl;
			cout << s + enc[index] << endl;*/
	if(enc[index] !='z'){
		dfs(index + 1,s + char(enc[index] + 1));
	}
	dfs(index + 1,s + enc[index]);
	return;
}
int main(){

	while(cin >> enc,enc[0]!='#'){
		string s;
		dfs(0,s);
		cout << decoding.size() << endl;
		sort(decoding.begin(),decoding.end());
		if(decoding.size() <= 10){
			for(int i=0;i<decoding.size();i++)
				cout << decoding[i] << endl;
		}else{
			for(int i=0;i<5;i++){
				cout << decoding[i] << endl;
			}
			for(int i=decoding.size()-5;i<decoding.size();i++){
				cout << decoding[i] << endl;
			}
		}
		decoding.clear();
	}
}

Measured memory_bytes: 4256
w = gets.chomp.to_i
n = gets.chomp.to_i

table = Hash.new
w.times do |i|
  table[i] = Hash.new
end

n.times do |n|
  a, b = gets.chomp.split(",").map{|i| i.to_i - 1}
  table[a][n] = b
  table[b][n] = a
end

result = Array.new
w.times do |base|
  current = base
  n.times do |i|
    current = table[current][i] unless table[current][i].nil?
  end
  result[current] = base + 1
end

puts result

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

using namespace std;

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

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

   int a,b;
   cin >> a >> b;
   cout << (b - a) * (b - a + 1) / 2 - b << endl;
   
   return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main()
{
	int n;
	
	std::cin >> n;
	
	int max = 0;
	int semi_max = 0;
	int index;
	
	for (int i = 0; i < n; ++i)
	{
		int tmp;
		std::cin >> tmp;
		if (max <= tmp)
		{
			semi_max = max;
			max = tmp;
			index = i;
		}
		else if (semi_max < tmp)
		{
			semi_max = tmp;
		}
	}
	
	for (int i = 0; i < n; ++i)
	{
		if (index == i)
		{
			std::cout << semi_max << std::endl;
		}
		else
		{
			std::cout << max << std::endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<string>
#include<vector>
#include<iostream>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>
 
using namespace std;
 
int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> c(r);
  for(int i = 0; i < r; i++) cin >> c[i];
  for(int i = 0; i < r; i++) --c[i];
  vector<vector<long long>> p(n);
  for(int i = 0; i < n; i++) p[i].resize(n);
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) p[i][j] = 1000000000;
  for(int i = 0; i < m; i++) {
    long long A, B, C;
    cin >> A >> B >> C;
    A--; B--;
    p[A][B] = p[B][A] = C;
  }
 
  for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) p[i][j] = min(p[i][j], p[i][k] + p[k][j]);
 
  long long ans = 1000000000000000;
  long long l = 1;
  for(int i = 1; i <= r; i++) l *= i;
  sort(c.begin(), c.end());
  for(int i = 0; i < l; i++) {
    next_permutation(c.begin(), c.end());
    long long cr = 0;
    for(int i = 1; i < r; i++) cr += p[c[i - 1]][c[i]];
    ans = min(ans, cr);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
A = int(input())
B = int(input())
C = int(input())
X = int(input())//50

cnt = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 10*i + 2*j + k == X:
                cnt += 1
                #print(i, j, k)

print(cnt)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <cmath>
#include <random>
#include <bitset>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;

constexpr int dy[] = {1,0,-1,0,1,-1,-1,1};
constexpr int dx[] = {0,1,0,-1,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A, B>;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
inline int updiv(int a, int b) { return (a + b - 1) / b; }

int n;
vector<int> a, dp, res;
vector<vector<int> > G;
vector<bool> visited;

void dfs(int now){
    visited[now] = true;
    auto itr = lower_bound(all(dp), a[now]);
    int tmp = *itr;
    chmin(*itr, a[now]);
    res[now] = distance(dp.begin(), lower_bound(all(dp), INF)) - 1;
    for(auto e : G[now]){
        if(!visited[e]){
            dfs(e);
        }
    }
    *itr = tmp;
    return;
}

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

    cin >> n;

    a.resize(n+1);
    G.resize(n+1);
    dp.resize(n+10, INF);
    res.resize(n+1);
    visited.resize(n+1);

    dp[0] = -1;

    reps(i,n){
        cin >> a[i];
    }

    rep(i,n-1){
        int u, v;
        cin >> u >> v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    dfs(1);

    reps(i,n){
        cout << res[i] << '\n';
    }

    return 0; 

}

Measured memory_bytes: 27464
#include <iostream>

using namespace std;

void printArray(int arr[], int n)
{
  for (int i = 0; i < n; i++)
  {
    cout << arr[i];
    if (i != n - 1) {
        cout << " ";
    }
  }
  cout << endl;
}

void insertionSort(int arr[], int n)
{
  for (int i = 1; i <= n; i++)
  {
    printArray(arr, n);
    int v = arr[i];
    int j = i - 1;
    while (j >= 0 && arr[j] > v)
    {
      arr[j + 1] = arr[j];
      j--;
    }
    arr[j + 1] = v;
  }
}

int main()
{
  int n;
  cin >> n;
  int nums[n];
  for (int i = 1; i <= n; i++)
  {
    cin >> nums[i - 1];
  }
  insertionSort(nums, n);
  return 0;
}



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

typedef long long ll;

int n, t;
double res;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(10) << fixed;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        res += 1.0L / t;
    }
    cout << 1.0L / res << endl;

    return 0;
}



Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int a[n + 1];
  REP1(i, n) cin >> a[i];
  int index[n + 1];
  REP1(i, n) index[a[i]] = i;
  set<int> st;
  st.insert(0);
  st.insert(n + 1);
  ll ans = 0;
  REP1(i, n) {
    st.insert(index[i]);
    auto it = st.lower_bound(index[i]);
    it--;
    int l = *it;
    it = st.upper_bound(index[i]);
    int r = *it;
    ans += 1ll * i * (index[i] - l) * (r - index[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

struct team{
	int num;
	int ans;
	double time;
};

bool hikaku(const team &right,const team &left){
 if(right.ans == left.ans){
 	if(right.time == left.time){
 		return right.num > left.num;
 	}
 	return right.time < left.time;
 }
 else return left.ans < right.ans;
}

int main(){
	int t,p,r,M;
	int wrong[52][12];
	int res[52];
	double pe[52];
	vector<team> v;
	int tid,pid,time;
	int hantei;
	team te;
	while(1){
		cin >> M >> t >> p >> r;
		if(M == 0)break;
		for(int i = 0;i <= t;i++){
			res[i] = 0;
			pe[i] = 0;
			for(int j = 0;j <= p;j++){
				wrong[i][j] = 0;	
			}
		}
		v.clear();
		for(int i = 0;i < r;i++){
			cin >> time >> tid >> pid >> hantei;
			if(hantei == 0){
				res[tid]++;
				pe[tid] += wrong[tid][pid] * 20 + time;
			}
			else if(hantei != 0){
				wrong[tid][pid]++;
			}
		}
		for(int i = 1;i <= t;i++){
			te.num = i;
			te.ans = res[i];
			te.time = pe[i];
			v.push_back(te);
		}
		sort(v.begin(),v.end(),hikaku);
		for(int i = 0;i < v.size();i++){
			cout << v[i].num;
			if(i != v.size()-1){
				if(v[i].ans == v[i+1].ans && v[i].time == v[i+1].time){
					cout << "=";
				}
				else cout << ",";
			}
		}
		cout <<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long s64;
s64 sumArray[200000];
int N;

void calcLR(int first, int last, int leftLast, s64* left, s64* right)
{
    *left = sumArray[leftLast];
    if (first != 0)
    {
        *left -= sumArray[first - 1];
    }
    *right = sumArray[last] - sumArray[leftLast];
}

int findLeftLast(int first, int last, int candFirst, int candLast, int depth)
{
    if (candFirst == candLast)
    {
        return candFirst;
    }
    if (candLast - candFirst == 1)
    {
        s64 left, right;
        calcLR(first, last, candFirst, &left, &right);
        s64 diff1 = abs(left - right);
        calcLR(first, last, candLast, &left, &right);
        s64 diff2 = abs(left - right);
        if (diff1 < diff2)
        {
            return candFirst;
        }
        else
        {
            return candLast;
        }
    }
    int llast = (candFirst + candLast) / 2;
    s64 left, right;
    calcLR(first, last, llast, &left, &right);
    if (left == right)
    {
        return llast;
    }
    else if (left < right)
    {
        if (llast == last - 1)
        {
            return llast;
        }
        return findLeftLast(first, last, llast, candLast, depth + 1);
    }
    else
    {
        if (llast == 0)
        {
            return llast;
        }
        return findLeftLast(first, last, candFirst, llast, depth + 1);
    }
}

int main()
{
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        int a;
        cin >> a;
        if (i == 0)
        {
            sumArray[i] = a;
        }
        else
        {
            sumArray[i] = sumArray[i - 1] + a;
        }
    }

    auto calc = [](int first, int last, s64* min, s64* max) {
        int leftLast = findLeftLast(first, last, first, last - 1, 0);
        s64 left, right, diff;
        calcLR(first, last, leftLast, &left, &right);
        if (left < right)
        {
            *min = left;
            *max = right;
        }
        else
        {
            *min = right;
            *max = left;
        }
    };

    s64 diffMin = -1;
    for (int leftLast = 1; leftLast <= N - 3; ++leftLast)
    {
        s64 leftMin, leftMax, rightMin, rightMax;
        calc(0, leftLast, &leftMin, &leftMax);
        calc(leftLast + 1, N - 1, &rightMin, &rightMax);
        s64 diff = max(leftMax, rightMax) - min(leftMin, rightMin);
        if (diffMin == -1 || diff < diffMin)
        {
            diffMin = diff;
        }
    }
    cout << diffMin << endl;

    return 0;
}


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

const int N=2e5+20;

int n,a[N],mn=INT_MAX,ans;

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

		if(a[i]<mn) ans++;
		mn=min(mn,a[i]);
	}

	cout<<ans;
}

Measured memory_bytes: 4408
hash = Hash.new(0)
hash[1] = "1"
uniq_hash = Hash.new([])
n, m = gets.chop.split.map(&:to_i)
m.times {
  s, c = gets.chop.split.map(&:to_i)
  hash[s] = "#{c}"
  uniq_hash[s] = uniq_hash[s] + [c]
}
if hash[1] == "0"
  if n == 1 && m == 1
    print 0
  else
    print '-1'
  end
elsif n == 1 && m == 0
  print 0
else
  result = ""
  for i in 1..n
    if uniq_hash[i].uniq.count > 1
      result = '-1'
      break
    end
    result = "#{result}#{hash[i]}"
  end
  print result.to_i
end

Measured memory_bytes: 1788
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.io.*;
import java.util.*;
public class Main
{
    public static double func(double p [], int n , int tail,int curr,double dp[][])
    {
        
        
        
        if((n-tail)<=tail)
        {
            return 0.0;
        }
        
        if(curr>=n)
        {
            
            return 1.0;
            
        }
        if(dp[curr][tail]>-1.0)return dp[curr][tail];
        return dp[curr][tail]=p[curr]*func(p,n,tail,curr+1,dp)+(1.0-p[curr])*func(p,n,tail+1,curr+1,dp);
      
    }
    
    
	public static void main(String[] args) throws Exception {
	
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		String ss[]=(br.readLine()).split(" ");
		
		double p[]=new double [n];
		for (int i=0;i<n;i++)
		{
		    p[i]=Double.parseDouble(ss[i]);
		    
		}
	    double dp[][]=new double[n][n];
	    for(double row[]:dp)
	    Arrays.fill(row,-1.0);
	    
		double ans1=func(p,n,0,0,dp);
		System.out.println(ans1);
		
		
		
		
	}
}


Measured memory_bytes: 98216
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int p = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());

        int result = Math.min(Math.min(p + q, q + r), p + r);

        System.out.println(result);
    }
}


Measured memory_bytes: 23764
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;

typedef long long ll;

const int MOD = 1000000000 + 7;
const int MAX_DIGIT = 10001;
const int MAX_D = 101;

ll dp[MAX_DIGIT][2][MAX_D];


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

  string s;
  cin >> s;

  int N = s.size();

  int K[N];
  for (int i = 0; i < s.size(); i++) K[i] = s[i] - '0';
  
  int D;
  cin >> D;

  dp[0][0][0] = 1;
  
  for (int i = 0; i < N; i++) {
    for (int d = 0; d < D; d++) {
      
      for (int k = 0; k <= 9; k++) {
	dp[i + 1][1][(d + k) % D] += dp[i][1][d];
	dp[i + 1][1][(d + k) % D] %= MOD;
      }
      
      for (int k = 0; k < K[i]; k++) {
	dp[i + 1][1][(d + k) % D] += dp[i][0][d];
	dp[i + 1][1][(d + k) % D] %= MOD;
      }

      dp[i + 1][0][(d + K[i]) % D] += dp[i][0][d];
      dp[i + 1][0][(d + K[i]) % D] %= MOD;
      
    }
  }

  int res = (dp[N][0][0] + dp[N][1][0] - 1 + MOD) % MOD;
  cout << res << endl;
  
  return 0;
}



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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,c;cin>>a>>b>>c;
  if(a>b)swap(a,b);
  if(a<c&&c<b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

#define MOD 1000000007
using namespace std;
long long mod(const long long &a) {
	if (a >= 0)return a % 1000000007;
	return 1000000007 - (-a) % 1000000007;
}
int mod(const int &a) {
	if (a >= 0)return a % 1000000007;
	return 1000000007 - (-a) % 1000000007;
}

typedef pair<int, int> P;

int n, m,l;
string s;

int main() {
	cin >> n>>m;
	vector<vector<P>> grid(n, vector<P> (m));
	vector < vector<bool>> masu(n, vector<bool>(m));
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		vector<int> cnt(m);
		int now = 0;
		for (int j = 0; j < m; j++)
		{
			if (s[j] == '#') {
				masu[i][j] = 0;cnt[j] = 0;
			}
			else {
				masu[i][j] = 1;cnt[j] = (j>0?cnt[j-1]+1:1);
			}
		}
		int temp=cnt[m-1];
		for (int j =m-1; j >= 0; j--)
		{
			temp = (cnt[j]==0?0:max(temp,cnt[j]));
			grid[i][j].first = temp;
		}
	}
	for (int i = 0; i < m; i++)
	{
		vector<int> cnt(n);
		for (int j = 0; j < n; j++)
		{
			if (masu[j][i]==0) {
				cnt[j] = 0;
			}
			else {
				cnt[j] = (j > 0 ? cnt[j - 1] + 1 : 1);
			}
		}
		int temp = cnt[n - 1];
		for (int j = n - 1; j >= 0; j--)
		{
			temp = (cnt[j] == 0 ? 0 : max(temp,cnt[j]));
			grid[j][i].second = temp;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if(grid[i][j].first && grid[i][j].second)ans = max((grid[i][j].first + grid[i][j].second-1), ans);
			else ans = max((grid[i][j].first + grid[i][j].second), ans);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 34176
import heapq
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n, m = LI()
a = LI()
a = list(map(lambda x: -1 * x, a))
heapq.heapify(a)
for _ in range(m):
    price = -1 * heapq.heappop(a)  # 現時点での最大値をO(log N)で取得
    heapq.heappush(a,  -1 * (price // 2))
print(-1 * sum(a))


Measured memory_bytes: 20124
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = K
for i in range(1, N):
    r = K - (A[i] - A[i - 1])
    ans = min(r, ans)

r = A[N - 1] - A[0]
ans = min(r, ans)

print(ans)


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

using namespace std;

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

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1.0);

ll n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<ll> a(n);

    for (int i = 0; i < n; ++i)
        cin >> a[i];

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

    double ans = a[0];
    for (int i = 0; i < n; ++i) {
        ans = (ans + a[i]) / 2.0;
    }

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


template <std::uint_fast64_t Modulus> 
struct ModInt {
    using u64 = std::uint_fast64_t;

    u64 a;

    constexpr ModInt(const long long x = 0) noexcept : a(x >= 0 ? x % Modulus : (Modulus - (-x) % Modulus) % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr ModInt operator+(const ModInt rhs) const noexcept {return ModInt(*this) += rhs;}
    constexpr ModInt operator-(const ModInt rhs) const noexcept {return ModInt(*this) -= rhs;}
    constexpr ModInt operator*(const ModInt rhs) const noexcept {return ModInt(*this) *= rhs;}
    constexpr ModInt operator/(const ModInt rhs) const noexcept {return ModInt(*this) /= rhs;}
    constexpr ModInt operator^(const long long rhs) const noexcept {return ModInt(*this) ^= rhs;}
    constexpr ModInt &operator+=(const ModInt rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr ModInt &operator/=(ModInt rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }
    constexpr ModInt &operator^=(long long exp) noexcept {
        ModInt rhs = a;
        a = 1;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }

    bool operator==(const ModInt &p) const {return a == p.a;}
    bool operator!=(const ModInt &p) const {return a != p.a;}

};

using mint = ModInt<MOD>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    mint ans = K;
    ans ^= N;
    cout << ans.a << ln;
}


Measured memory_bytes: 3216
#include<stdio.h>
int main(void)
{
	int H, W;
	int i, j;
	
	while(1){
		scanf("%d %d", &H, &W);
		if(H==0 && W==0){
			break;
		}
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){
				if(i%2==1){
					if(j%2==1){
						printf("#");
					}else if(j%2==0){
						printf(".");
					}
				}
				if(i%2==0){
					if(j%2==0){
						printf("#");
					}else if(j%2==1){
						printf(".");
					}
				}
		}
		printf("\n");
	}
	printf("\n");
}	
	return 0;
}
					

Measured memory_bytes: 572
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

	for(int a, b, c; cin >> a >> b >> c, a;) {
		vector<int> state(a + b + c, 2);
		
		int t;
		cin >> t;
		
		vector<int> l, m, n;
		for(int i = 0; i < t; ++i) {
			int x, y, z;
			bool r;
			cin >> x >> y >> z >> r;
			--x; --y; --z;
			
			if(r) {
				state[x] = state[y] = state[z] = 1;
			}
			else {
				l.push_back(x);
				m.push_back(y);
				n.push_back(z);
			}
		}
		
		for(int i = 0; i < l.size(); ++i) {
			if(state[l[i]] == 1 && state[m[i]] == 1)
				state[n[i]] = 0;
			
			if(state[m[i]] == 1 && state[n[i]] == 1)
				state[l[i]] = 0;
			
			if(state[n[i]] == 1 && state[l[i]] == 1)
				state[m[i]] = 0;
		}
		
		for(int i = 0; i < state.size(); ++i)
			cout << state[i] << endl;
	}

	return EXIT_SUCCESS;
}

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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _ % MOD
#define __ %= MOD

#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))

#define swap(a, b) \
	{              \
		a = a + b; \
		b = a - b; \
		a = a - b; \
	}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

#define pv(a)                                 \
	{                                         \
		rep(i, a.size()) cout << a[i] << " "; \
		cout << endl;                         \
	}
#define mark(v) cout << "Here--" << v << endl;

const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}
ll power(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y & 1)
			res = res * x;
		y = y >> 1;
		x = x * x;
	}
	return res;
} // modular exponent

int main()
{
	ios_base::sync_with_stdio(false); // don't use printf and scanf
	cin.tie(NULL);					  // cout<<fixed<<setprecision
	string n;
	ll k;
	cin >> n >> k;
	set<int> nt;
	rep(i, k)
	{
		ll x;
		cin >> x;
		nt.insert(x);
	}

	ll num = stoll(n);

	ll ans;
	while (1)
	{
		n = to_string(num);
		bool flag = true;

		rep(i, n.size())
		{
			if (nt.find(n[i] - '0') != nt.end())
			{
				flag = false;
				break;
			}
		}
		if (flag == true)
		{
			ans = num;
			break;
		}
		num++;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  string S;
  long long K;
  cin >> S >> K;
  vector<long long> cnt(S.size());
  long long j=0;
  for(long long i=0; i<S.size()-1; i++){
    if(S.at(i)==S.at(i+1)){
      cnt.at(j)++;
    }
    else j++;
  }
  long long ans=0;
  for(long long i=0; i<S.size(); i++){
    if(cnt.at(i)>0) ans+=(cnt.at(i)+1)/2;
  }
  //
  //for(int i=0; i<S.size(); i++) cout << cnt.at(i) << ' ';

  long long lst=1;
  for(long long i=S.size()-1; i>0; i--){
    if(S.at(i)==S.at(i-1)) lst++;
    else break;
  }
  long long plu=0;
  if(S.at(0)==S.at(S.size()-1)){
    if((cnt.at(0)+1)%2==1 && lst%2==1) plu++;
  }
  //
  //cout << endl;
  //cout << lst << endl;
  //cout << plu << endl;

  if(K==1) cout << ans << endl;
  else if(lst==S.size() && lst%2==1) cout << lst*K/2 << endl;
  else cout << (ans+plu)*K-plu << endl;
}

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

int main(){
  long long x, y;
  cin >> x >> y;
  y /= x;
  long long i, b=1;
  for(i=0; i<60; i++){
    if(y<b){
      break;
    }
    else{
      b*=2;
    }
  }
  cout << i;
  return 0;
}
  

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

int n;
queue<int> edge;
vector<int> ans;
vector<vector<pair<int,int>>> e;

void dfs(int i){
  for(int j=0; j<e[i].size(); ++j){
    int v=e[i][j].first, w=e[i][j].second;
    if(ans[v]==0)edge.push(v);
    else continue;

    if(w%2==0)ans[v]=ans[i];
    else if(ans[i]==1)ans[v]=2;
    else if(ans[i]==2)ans[v]=1;
  }
}

int main(){
  cin>>n;
  e.resize(n+1);
  for(int i=0; i<n-1; ++i){
    int u,v,w; cin>>u>>v>>w;
    e[u].push_back(make_pair(v,w));
    e[v].push_back(make_pair(u,w));
  }

  ans.resize(n+1);

  edge.push(1);
  ans[1]=1;
  while(!edge.empty()){
    int x=edge.front(); edge.pop();
    dfs(x);
  }

  for(int i=1; i<=n; ++i)cout<<ans[i]-1<<endl;
  
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
int main()
{
    int N, K, M;
    while (cin >> N >> K >> M)
    {
        if (N == 0 && K == 0 && N == 0)
            break;
        queue<int> que;
        rep(i, N) que.push(i + 1);
        rep(i, M - 1)
        {
            int tmp = que.front();
            que.pop();
            que.push(tmp);
        }
        que.pop();
        int pos = 1;
        while (que.size() != 1)
        {
            if (pos == K)
            {
                //cout << que.front() << endl;
                pos = 1;
                que.pop();
            }
            else
            {
                int tmp = que.front();
                que.pop();
                que.push(tmp);
                pos++;
            }
            //pos++;
        }
        cout << que.front() << endl;
    }
}



Measured memory_bytes: 3172
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[("0"*40+bin(A[i])[2:])[-40:] for i in range(N)]

cnt="".join([str(int(sum([int(B[i][j]) for i in range(N)]) < (N+1)//2)) for j in range(40)])
M=("0"*40+bin(M)[2:])[-40:]

ans=[]

def dp(cur,seq):
    if cur==40:
        if seq<=M:
            ans.append(seq)
    elif seq[:cur]+cnt[cur:] <= M:
        ans.append(seq[:cur]+cnt[cur:])
    elif seq[:cur]+"0"*(40-cur) > M:
        pass
    else:
        dp(cur+1,seq[:cur]+"0"+cnt[cur+1:])
        dp(cur+1,seq[:cur]+"1"+cnt[cur+1:])
        
dp(0,cnt)
print(max([sum([a^int(i,2) for a in A]) for i in ans]))

Measured memory_bytes: 21932
#include <iostream>
#include <locale>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
using namespace std;

int main() {
	double x1,y1,x2,y2;
	
	cin >> x1>>y1 >> x2 >> y2;
	
	double distance;
	
	distance =sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	
	cout << fixed << setprecision(6) << distance << endl;
	
	return 0;
}


Measured memory_bytes: 3268
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1], K = ip[2];
	ulong cnt;
	foreach_reverse(i; 1..A*B+1) {
		debug writefln("%d %d %d", A%i, B%i, i);
		if(A%i == 0 && B%i == 0) { cnt++; debug i.writeln;} 
		if(cnt == K) {
			writeln(i);
			return;
		}
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
# encoding:utf-8

import fractions

def check(l):
	l = list(map(int, l.split()))
	print(len(l), len([x for x in l if x % 2 == 0]), len([x for x in l if x % 2 == 1]))
	if max(l) >= 30001:
		print("max >= 30001")
		return False

	if len(set(l)) != len(l):
		print("not unique")
		return False

	tmp = l[0]


	for i in range(len(l) - 1):
		tmp = fractions.gcd(tmp, l[i+1])
	if tmp != 1:
		print("gcd is 1")
		return False 

	for i in range(len(l)):
		if fractions.gcd(l[i], sum(l) - l[i]) == 1:
			print("not special")
			return False

	return True


def main(n):
	if n == 3:
		return "2 5 63"

	sub1 = [str(i * 3) for i in range(1, 10001) if i % 2 == 1]
	sub2 = [str(i) for i in range(1, 30000) if i % 2 == 0 and i % 3 != 0]
	sub3 = [str(i) for i in range(1, 30001) if i % 6 == 0]
	if n <= 5003:
		if n % 2 == 0:
			s = "2 4 " + " ".join([str(x) for x in sub1[0:(n-2)]])
			return(s)
		else:
			s = "2 4 6 " + " ".join([str(x) for x in sub1[0:(n-3)]])
			return(s)
	elif n <= 15000:
		if n % 2 == 0:
			s = " ".join(sub2[0:(n-5000)]) + " " +  " ".join(sub1)
			return(s)
		else:
			s = " ".join(sub2[0:(n-5001)]) + " 6 " +  " ".join(sub1)
			return(s)
	else:
		s = " ".join(sub2) + " " +  " ".join(sub1) + " " + " ".join(sub3[0:(n-15000)]) 
		return(s)

if __name__ == '__main__':
	n = int(input())
	#print(check(main(n)))
	#print(check(main(15)))
	#print(check(main(17)))
	#print(check(main(5002)))
	#print(check(main(5003)))
	#print(check(main(15002)))
	#print(check(main(15003)))
	print(main(n))
	#print(check("2 4 3 20001"))
	#for i in range(5001, 5006):
	#	ans = main(i)
	#	print(i, check(ans))
	

Measured memory_bytes: 6868
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli n;
	cin >> n;
	vector<lli> h(n);
	rep(i,n) cin >> h[i];

	lli max = 0;
	lli at = 0;
	lli j;

	while(at < n-1){
		lli cnt = 0;
		while(h[at+1] <= h[at] && at+1 < n){
			cnt++;
			at++;
		}
		if(max < cnt) max=cnt;
		at++;
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int abs(int x,int y){
	if(x>y) return (x-y);
	else return (y-x);
}
int main(){
	int a1,a2,a3,i,j;
	cin>>a1>>a2>>a3;
	int t=0,a[4]={0};
	a[0]=abs(a1-a2),a[1]=abs(a2-a3),a[2]=abs(a3-a1);
	sort(a,a+3);
	cout<<a[0]+a[1];
	return 0;
}

Measured memory_bytes: 256
from math import factorial

def main():
    n, *s = open(0).read().split()

    exist_s = {}
    for cur_s in s:
        cur_s = ''.join(sorted(list(cur_s)))
        if cur_s in exist_s:
            exist_s[cur_s] += 1
        else:
            exist_s[cur_s] = 1

    ans = 0
    for val in exist_s.values():
        if val < 2:
            continue
        ans += factorial(val) // (factorial(val - 2) * factorial(2))

    print(ans)
    return()

if __name__ == '__main__':
    main()


Measured memory_bytes: 26376
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){
    ll x,y;
    cin >> x >> y;
    if(x < 0 && y < 0){
        if(x > y){
            cout << 2 + x - y << endl;
        }
        else{
            cout << y - x << endl;
        }
    }
    else if(x < 0 && y >= 0){
        if(y == 0){
            cout << abs(x) << endl;
        } 
        else{
            cout << 1 + abs(abs(x) - abs(y)) << endl;
        }
    }
    else if(x >= 0 && y < 0){
        if(x == 0){
            cout << 1 + abs(y) << endl;
        } 
        else{
            cout << 1 + abs(abs(x) - abs(y)) << endl;
        }
    }
    else{
        if(y == 0){
            cout << 1 + x << endl;
        }
        else if(x <= y){
            cout << y - x << endl; 
        }
        else{
            cout << 2 + x - y << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3604
#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 k;
    cin >> k;
    vector<ll> a;
    for(int i = 1; i<=9;++i) a.push_back(i);
    while (1){
        // rep(i,a.size())
        if(k<=a.size()){
            cout << a[k-1] << endl;
            return 0;
        }
        k -= a.size();
        vector<ll> old;
        swap(old,a);
        for (ll x:old){
            for(int i = -1;i<=1; ++i){
                int d = x%10+i;
                if(d<0 || d>9) continue;
                ll nx  = x*10 +d;
                a.push_back(nx);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1712
#include <stdio.h>
int main(){
 int N;
 scanf("%d",&N);
 int A[N];
 int judge=1;
 for(int i=0;i<N;i++){
  scanf("%d",&A[i]);
  if(A[i]%2==0){
  if(A[i]%3==0||A[i]%5==0);
   else judge=0;
   }
 }
 if(judge==1)printf("APPROVED");
   else printf("DENIED");
 return 0;
}

Measured memory_bytes: 2156