akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    
    long double deg = abs((30.0 * h + 0.5 * m) - (6.0 * m));
    if(deg > 180) deg = 360 - deg;
    long double rad = deg * (pai/180.0);
    
    //a2=b2+c2−2bccosA
    long double c = a*a + b*b - 2.0 * a * b * cos(rad);
    
    cout << setprecision(20) << sqrtl(c) << endl;

    return 0;
}


Measured memory_bytes: 4164
while True:
    middle, final, retry = map(int, input().split())
    if middle == -1 and final == -1 and retry == -1:
        break
    if middle == -1 or final == -1:
        print("F")
    else:
        total = middle + final
        if total >= 80:
            print("A")
        elif 65 <= total < 80:
            print("B")
        elif 50 <= total < 65:
            print("C")
        elif 30 <= total < 50:
            print("D" if retry < 50 else "C")
        else:
            print("F")


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  vector<int> cost(N);
  for(int i=0;i<N;i++){
    cin >> h.at(i);
    cost.at(i) = 10000000000;
  }
  cost.at(0) = 0;
  if(N > K){
    for(int i=1;i<K;i++){
      for(int j=i;j>0;j--){
        cost.at(i) = min((cost.at(i-j) + abs(h.at(i)-h.at(i-j))),cost.at(i));
      }
    }

    for(int i=K;i<N;i++){
      for(int j=K;j>0;j--){
        cost.at(i) = min((cost.at(i-j) + abs(h.at(i)-h.at(i-j))),cost.at(i));
      }
    }
  }
  else{
    for(int i=1;i<N;i++){
      for(int j=i;j>0;j--){
        cost.at(i) = min((cost.at(i-j) + abs(h.at(i)-h.at(i-j))),cost.at(i));
      }
    }
  }
    
    cout << cost.at(N-1) << endl;
}

Measured memory_bytes: 1152
mod = 10**9 + 7

def nCr(n,r):
  if n < r:
    return 0
  if n < 0 or r < 0:
    return 0
  return (fac[n] * facinv[r] * facinv[n - r]) % mod

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

fac = [1]
for i in range(1,N+1):
  fac.append((fac[-1] * i) % mod)

inv = [1 for _ in range(N+1)]
for i in range(2,N+1):
  inv[i] = -(mod // i) * inv[mod % i] % mod

facinv = [1 for _ in range(N+1)]
for i in range(1, N+1):
  facinv[i] = (facinv[i-1] * inv[i]) % mod

ans = 0
for i in range(N):
  ans = (ans + (nCr(i, K - 1) * A[i]))
  ans = (ans - (nCr(N - i - 1, K - 1) * A[i]))
print(ans % mod)

Measured memory_bytes: 18908
#include<stdio.h>
int main(){
	int a,b,c,n;
	scanf("%d",&n);
	while(n>0){
		scanf("%d %d %d",&a,&b,&c);
		if((a*a+b*b==c*c) || (c*c+b*b==a*a) || (a*a+c*c==b*b))
			printf("YES\n");
		else
			printf("NO\n");
		n--;
	}
	return 0;
}


Measured memory_bytes: 1816
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    String s = sc.next();
    String ans = "";
    for(int i = 0; i < s.length(); i++) {
      String str = String.valueOf(s.charAt(i));
      if(i == (k - 1)) str = str.toLowerCase();
      ans += str; 
    }
    System.out.println(ans);
  }
}

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

int main()
{
  int K,N;
  cin >> K >> N;
  int point[N];
  int distance[N];
  for(int i=0;i<N;i++){
    cin >> point[i];
  }
  sort(point,point+N);
  
  for(int i=0;i<N-1;i++){
    distance[i] = point[i+1]-point[i];
  }
  distance[N-1] = K-point[N-1]+point[0];
  
  int max = 0;
  for(int i=0;i<N;i++){
    max = max > distance[i]? max : distance[i];
  }
  cout<<K-max<<endl;
  return 0;
}

Measured memory_bytes: 1792
// hima.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>


using namespace std;



int main() {
	int N;
	int count2=0;

	cin>>N;
	for(int i=1;i<=N;i++){
		int j=i;
			int count=0;
		while(j>0){
			j/=10;
			count++;

		}
		if(count%2==1){
			count2++;
		}

	}
	cout<<count2<<endl;
}





Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
const int maxn = 20;
int n,m,cnt;bool vis[maxn];
vector<int>g[maxn];
void dfs(int u,map<int,bool>m){
	bool flag = 0;
	for(register int i=g[u].size()-1;i>=0;i--){
		int v = g[u][i];
		if(!vis[v]){
			flag=1;
			m[v]=1;
			vis[v]=1;
			dfs(v,m);
			m.erase(v);//cnmb rnm cnm STL ++!
			vis[v]=0;
		}
	}
	if(!flag){
		if(m.size()==n){
			++cnt;
		}
	}
}
void addE(int u,int v){
	g[u].push_back(v);
	g[v].push_back(u);
}
int main(){
	scanf("%d%d",&n,&m);
	int a,b;
	for(register int i=1;i<=m;++i){
		scanf("%d%d",&a,&b);
		addE(a,b);
	}
	map<int,bool>m;vis[1]=1;m[1]=1;
	dfs(1,m);printf("%d",cnt);
}

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

using namespace std;

vector<pair<int, int>> MaxOccurence(const vector<int> &v, int start_index) {
	map<int, int> occurences;
	int max_occurence = 0;
	pair<int, int> max_pair, second_max_pair;

	for (int i = start_index; i < (int)v.size(); i += 2) {
		occurences[v[i]]++;
		if(occurences[v[i]] > max_occurence) {
			max_occurence = occurences[v[i]];
			max_pair = {v[i], max_occurence};
		}
	}
	int second_max = 0;
	for (auto it: occurences) {
		int element = it.first;
		int occ = it.second;

		if (occ > second_max && max_pair.first != element) {
			second_max = occ;
			second_max_pair = {element, second_max};
		}
	}
	vector<pair<int, int>> result;

	result.push_back(max_pair);

	if (second_max != 0) {
		result.push_back(second_max_pair);
	}
	return result;
}

int MinToReplace(const vector<int> &v) {
	int n = v.size();

	auto max_even_vector = MaxOccurence(v, 0);
	auto max_odd_vector = MaxOccurence(v, 1);
	
	int e_max_occ1 = max_even_vector[0].second;
	int e_max_elm1 = max_even_vector[0].first;

	int o_max_occ1 = max_odd_vector[0].second;
	int o_max_elm1 = max_odd_vector[0].first;


	if (e_max_elm1 != o_max_elm1) {

		return n - o_max_occ1 - e_max_occ1;
	} else {
		if (e_max_occ1 < n/2 && o_max_occ1 < n/2) {

			return min(n - e_max_occ1 - max_odd_vector[1].second, n - o_max_occ1 - max_even_vector[1].second);
		} else {
			if (e_max_occ1 == n/2 && o_max_occ1 == n/2) {
				return n/2;
			} else {
				if (e_max_occ1 == n/2) {
					return n/2 - max_odd_vector[1].second;
				} else {
					return n/2 - max_even_vector[1].second;
				}
			}
		}
	}
	return -1;
}

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

	cout << MinToReplace(v) << endl;


	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;
#define B

#ifdef A
int main(void)
{
	int W, H;
	vector<pair<int, int> > arr(0);

	while (true)
	{
		cin >> H >> W;

		if (W == 0 || H == 0)
			break;
		arr.push_back(pair<int, int>(H, W));

	}

	for (auto a : arr) {
		for (size_t i = 0; i < a.first; i++)
		{
			for (size_t i = 0; i < a.second; i++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}



	return 0;
}


#endif // A

#ifdef B
int main(void)
{
	int H, W;
	vector<pair<int, int> > arr;
	while (true)
	{
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		arr.push_back(pair<int, int>(H, W));

	}
	for (auto a : arr) {
		for (int i = 0; i < a.second; ++i)
		{
			cout << "#";
		}
		cout << endl;
		for (int i = a.first - 3; i >= 0; i--)
		{

			cout << "#" ;
			for (int i = a.second - 3; i >= 0; i--)
			{
				cout << ".";
			}
			cout << "#\n";
		}


		for (int i = a.second - 1; i >= 0; i--)
		{
			cout << "#";
		}
	
		cout << endl<< endl;
	}

	return 0;
}
#endif // B

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

int main() {
  
  string str; int q; cin >> str >> q;
  
  for (int i = 0; i < q; i++) {
    
    string instruction; cin >> instruction;
    
    int a, b; cin >> a >> b;
    
    if (instruction == "print") {
      for (int j = a; j <= b; j++) cout << str.at(j);
      cout << endl;
    }
    
    if (instruction == "reverse") {
      string tmp = str; int k = b;
      for (int j = a; j <= b; j++) {
        str.at(j) = tmp.at(k);
        k--;
      }
    }
    
    if (instruction == "replace") {
      string p; cin >> p; int k = 0;
      for (int j = a; j <= b; j++) {
        str.at(j) = p.at(k);
        k++;
      }
    }
    
  }
  
}


Measured memory_bytes: 3216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    int n;
    long k;
    SortedSet<Integer> set;
    Map<Integer, Long> map;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        k = sc.nextLong();
        set = new TreeSet<>();
        map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            long b = sc.nextInt();
            set.add(a);
            if (map.containsKey(a)) {
                map.put(a, map.get(a) + b);
            } else {
                map.put(a, b);
            }
        }
        solve();
    }

    void solve() {
        long count = 0;
        Iterator<Integer> it = set.iterator();
        while (it.hasNext()) {
            int key = it.next();
            long value = map.get(key);
            long newCount = count + value;
            if (k <= newCount) {
                System.out.println(key);
                return;
            } else {
                count = newCount;
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 48716
#include <stdio.h>

int main(void){
	int day, sumJ, sumM, j, m;
	
	scanf("%d %d %d %d %d", &day, &sumJ, &sumM, &j, &m);	
	
	if (sumJ/j < sumM/m){
		if (sumM%m == 0) day -= sumM/m;
		else day -= sumM/m+1;
	}
	else {
		if (sumJ%j == 0) day -= sumJ/j;
		else day -= sumJ/j+1;
	}
	
	printf("%d\n", day);
	
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (a >= b) {
		dump("delicious");
	}
	else if (a + x >= b) {
		dump("safe");
	}
	else {
		dump("dangerous");
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n-1];
  rep(i,0,n-1) cin>>a[i];
  int b[n];
  rep(i,0,n) b[i]=0;
  b[0]=a[0];
  rep(i,1,n)
  { 
    if(b[i-1]>a[i-1])b[i-1]=a[i-1];
    b[i]=max(b[i-1],a[i-1]);
  }
  int ans=0;
  rep(i,0,n) ans+=b[i];
  //rep(i,0,n) cout<<b[i]<<" ";
  cout<<ans;



}

Measured memory_bytes: 256
// AOJ 1370 Hidden Anagrams
// 2018.2.8 bal4u

#include <stdio.h>
#include <string.h>

#define HASHSIZ		49999
typedef struct { short f[26]; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;			// Hash table

void insert(short *f)
{
	int i;
	unsigned long long k;
	HASH *tp;

	f[0]++;
	k = 0; for (i = 0; i < 26; i+=2) k = (k << 4) + f[i];
	tp = hash + (int)(k % HASHSIZ);
	while (tp->f[0]) {
		if (!memcmp(tp->f, f, 52)) goto done;
		if (++tp == hashend) tp = hash;
	}
	memcpy(tp->f, f, 52);
done:
	f[0]--;
}

int lookup(short *f)
{
	int i;
	unsigned long long k;
	HASH *tp;

	f[0]++;
	k = 0; for (i = 0; i < 26; i+=2) k = (k << 4) + f[i];
	tp = hash + (int)(k % HASHSIZ);
	while (tp->f[0]) {
		if (!memcmp(tp->f, f, 52)) { f[0]--; return 1; }
		if (++tp == hashend) tp = hash;
	}
	f[0]--;
	return 0;
}

char sa[4004]; int wa;
char sb[4004]; int wb;
short f[26];

int main()
 {
	int i, k, w;
	char *p, *q;

	fgets(p=sa, 4004, stdin); while (*p > ' ') *p -= 'a', p++; wa = p - sa;
	fgets(p=sb, 4004, stdin); while (*p > ' ') *p -= 'a', p++; wb = p - sb;
	w = wa; if (w > wb) w = wb;

    for (k = w; k > 0; k--) {
		memset(hash, 0, sizeof(hash));

		memset(f, 0, sizeof(f));
		p = sa; for (i = 0; i < k; i++) f[*p++]++;
		insert(f);

		i = wa - k, q = sa; while (i--) {
			f[*q++]--, f[*p++]++;
			insert(f);
		}

		memset(f, 0, sizeof(f));
		p = sb; for (i = 0; i < k; i++) f[*p++]++;
		if (lookup(f)) goto done;

		i = wb - k, q = sb; while (i--) {
			f[*q++]--, f[*p++]++;
			if (lookup(f)) goto done;
		}
    }
done:
	printf("%d\n", k);
    return 0;
}


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

vector<int> g[MAX];
vector<int> color(MAX,0);

bool dfs(int v, int c){
  color[v] = c;
  rep(i,g[v].size()){
    if(color[g[v][i]] == c) return false;
    if(color[g[v][i]] == 0 && !dfs(g[v][i],-c)) return false; 
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  bool f = dfs(0,1);
  vector<int> p, q;
  rep(i,n) {
    if(color[i] == 1) p.push_back(i);
    else q.push_back(i);
  }
  int x = p.size(), y = q.size();
  vector<int> s, t;
  if(x < y) {
    s = p, t = q;
  } else {
    s = q, t = p;
  }
  vector<int> ans(n,0);
  queue<int> que[3];
  rep(i,n) que[(i+1)%3].push(i+1);
  if(min(x,y) <= n/3) {
    for(auto k : s) {
      ans[k] = que[0].front();
      que[0].pop();
    }
    for(auto k : t) {
      if(!que[0].empty()) {
        ans[k] = que[0].front();
        que[0].pop();
      } else if(!que[1].empty()) {
        ans[k] = que[1].front();
        que[1].pop();
      } else {
        ans[k] = que[2].front();
        que[2].pop();
      }
    }
  } else {
    for(auto k : s) {
     if(!que[2].empty()) {
        ans[k] = que[2].front();
        que[2].pop();
      } else {
        ans[k] = que[0].front();
        que[0].pop();
      }
    }
    for(auto k : t) {
      if(!que[0].empty()) {
        ans[k] = que[0].front();
        que[0].pop();
      } else {
        ans[k] = que[1].front();
        que[1].pop();
      }
    }
  }
  for(auto y : ans) cout << y << " ";
  cout << endl;
  return 0;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){ 
  string S;
  cin >> S;
  int N = S.size();
  vector<int> ans(S.size(), 0);
  REP(i, N-1){
    if(S[i]=='R' && S[i+1] == 'L'){
      ans[i]++, ans[i+1]++;
      FOR(j, i+2, N){
        if(S[j] =='R') break;
        if((j-i)%2){
          ans[i+1]++;
        }
        else{
          ans[i]++;
        }
      }
      for(int j = i-1; j >= 0; j--){
        if(S[j] == 'L') break;
        if((i-j) % 2){
          ans[i+1]++;
        }
        else{
          ans[i]++;
        }
      }
    }
  }
  REP(i, N){
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 1024
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::iter::once;
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

macro_rules! read {
    ([$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ([$t:ident]) =>
        (rl().split_whitespace().map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    (_, [$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!(_, [$t])).collect::<Vec<_>>());
    (_, [$t:ident]) =>
        (rl().split_whitespace().skip(1).map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    ($($t:ident),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ($t:ident) => (read_type!(rl(), $t));
    ($($t:ident),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(read_type!(w.next().unwrap(), $t)),*)
    }};
}

macro_rules! read_type {
    ($s:expr, chars) => {
        $s.chars().collect::<Vec<char>>()
    };
    ($s:expr, usize1) => {
        read_type!($s, usize) - 1
    };
    ($s:expr, $t:ty) => {
        $s.parse::<$t>().unwrap()
    };
}

fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

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

fn main() {
    let (n, c) = read!(usize, i64);
    let mut xc = read!(i64, i64; n);
    xc.insert(0, (0, 0));
    xc.push((c, 0));
    debug!(xc);

    let mut l = xc
        .windows(2)
        .map(|s| (s[1].0 - s[0].0, s[1].1))
        .map(|(x, c)| c - x)
        .vec();
    debug!(l);
    for i in 1..l.len() {
        l[i] = l[i - 1] + l[i];
    }
    debug!(l);
    for i in 1..l.len() {
        l[i] = max(l[i - 1], l[i]);
    }
    debug!(l);

    let mut r = xc
        .windows(2)
        .map(|s| (s[1].0 - s[0].0, s[0].1))
        .map(|(x, c)| c - x)
        .rev()
        .vec();
    debug!(r);
    for i in 1..r.len() {
        r[i] = r[i - 1] + r[i];
    }
    debug!(r);
    for i in 1..r.len() {
        r[i] = max(r[i - 1], r[i]);
    }
    debug!(r);

    let mut ans: i64 = 0;
    ans = max(*l.iter().max().unwrap(), ans);
    ans = max(*r.iter().max().unwrap(), ans);
    debug!(ans);

    for i in 0..n - 1 {
        let a = l[i] - xc[i + 1].0 + r[n - 2 - i];
        debug!(xc[i + 1].0, a);
        ans = max(a, ans);
    }

    for i in 0..n - 1 {
        let a = r[i] - (c - xc[n - i].0) + l[n - 2 - i];
        debug!(c - xc[n - i].0, a);
        ans = max(a, ans);
    }

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


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> ans(N, 0);
    rrep(i, N - 1, 0) {
        ll a = A[i];
        ll j = i + 1;
        ll c = 0;
        while (j <= N) {
            c += ans[j - 1];
            j += i + 1;
        }
        if (c % 2 == a) {
            continue;
        } else {
            ans[i] = 1;
        }
    }
    ll m = accumulate(ans.begin(), ans.end(), 0LL);
    cout << m << '\n';
    rep(i, N) {
        if (ans[i]) {
            cout << i + 1 << '\n';
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3968
import java.util.*;
public class Main
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int y=sc.nextInt();
    int m=0,flag=0;
    if(y<=x*2 || y<=x*4)
    {
      for(int i=1;i<=x;i++)
      {
      int j=i*2;
      m=i*4;
      int h=y-j;
      int h1=y-m;
      if((h1%2==0 && h1/2==x-i)|| (h%4==0 && h/4==x-i))
      {  
        flag=1;
        break;
      }
      }
    }
    if(flag==1)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}

Measured memory_bytes: 35724
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>vec(N);
  for(int X=0;X<N;X++){
    cin>>vec.at(X);
  }
  sort(vec.begin(), vec.end());
  double M=(vec.at(0));
  for(int X=1;X<N;X++){
    M=(M+vec.at(X))/2;
  }
  cout<<M<<endl;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

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

    int flag = true;
    for (auto i = mp.begin(); i != mp.end(); ++i){
        if(i->second != 1){
            flag = false;
            break;
        }
    }

    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main()
{
	int x = 0;
	string a;
	cin >> a;
	int b;
	cin >> b;
	for (int c = 0; c < b; c++) {
		int s = 0;
		string d;
		cin >> d;
		d += d;
		for (int e = 0; e < d.length() / 2; e++) {
			for (int f = 0; f < a.length(); f++) {
				if (d[e+f] != a[f])break;
				if (a.length() - 1 == f)s++;
			}
		}
		if (s)x++;
	}
	cout << x << endl;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define mk make_pair
#define fi first
#define se second
typedef pair<int, int> pii;

int n, m, a[310][310], cnt[310], now[310], vis[310];
int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; ++ i) {
		for (int j = 1; j <= m; ++ j) {
			cin >> a[i][j];
		}
	}
	
	for (int i = 1; i <= n; ++ i) {
		++ cnt[a[i][1]];
		now[i] = 1;
	}
	
	int ans = n + 1;
	for (int i = 1; i <= m; ++ i) {
		pii mx = mk(0, 0);
		for (int j = 1; j <= m; ++ j) {
			mx = max(mx, mk(cnt[j], j));
		}
		ans = min(ans, mx.fi);
		int x = mx.se;
		vis[x] = 1;
		if (i == m) continue ;
		for (int j = 1; j <= n; ++ j) {
			-- cnt[a[j][now[j]]];
			while (vis[a[j][now[j]]]) ++ now[j];
			++ cnt[a[j][now[j]]];
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
#coding: utf-8

n = int(raw_input())
for i in range(n):
    s = raw_input()
    l = set([s])
    for k in range(len(s)-1):
        t1 = s[:k+1]
        t2 = s[k+1:]
        n1 = t1 + t2[::-1]
        n2 = t1[::-1] + t2
        n3 = t1[::-1] + t2[::-1]
        n4 = t2 + t1[::-1]
        n5 = t2[::-1] + t1
        n6 = t2[::-1] + t1[::-1]
        n7 = t2 + t1
        l2 = set([n1,n2,n3,n4,n5,n6,n7])
        l = l.union(l2)
    print len(l)

Measured memory_bytes: 6316
#include<bits/stdc++.h>
using namespace std;
int N;
int A[20], mat[20][20];
int state[20];
int sum(int val) {
    int num = 0;
    while(val)
    {
        val &= (val - 1);
        ++num;
    }
    return num;
}
int check(int s) {
    for (int i = 0; i < N; i++) {
        if ((s & (1 << i)) != 0) {
            state[i + 1] = 1;
        }
        else {
            state[i + 1] = -1;
        }
    }
    bool flag = true;
    for (int i = 1; i <= N; i++) {
        if (state[i] == 1) {
            for (int j = 1; j <= N; j++) {
                if (mat[i][j] != 0 && state[j] != mat[i][j]) {
                    return false;
                }
            }
        }
    }
    return true;
}
int main() {
    int x, y;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        scanf("%d", &A[i]);
        for (int j = 1; j <= A[i]; j++) {
            scanf("%d%d", &x, &y);
            if (y == 0) {
                mat[i][x] = -1;
            }
            else {
                mat[i][x] = 1;
            }
        }
    }
    int ans = 0;
    for (int j = 0; j <= (1 << N) - 1; j++) {
        if (check(j)) {
            ans = max(ans, sum(j));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

int main(){
	int n=ci();
	int now=1, ans=0;
	rep(i,1,n){
		int x=ci();
		if( x==now ) now++;
		else ans++;
	}
	if( now==1 ) puts("-1");
	else printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

template<class V, int ME> class BIT{
    public:
        V bit[1<<ME];
        V operator()(int e){V s=0;e++;while(e) s+=bit[e-1],e-=e&-e;return s;}
        V add(int e,V v){e++;while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};

BIT<ll,20> bt;
int N, M;
vector<int> E[100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M;
    rep(i,N){
        int x,y; cin>>x>>y;
        E[y-x+1].push_back(x);
    }
    
    int morethan=N;
    rep1(i,M){
        int ret=0;
        for(int x=i;x<=M;x+=i) ret+=bt(x);
        
        for(auto& e:E[i]) bt.add(e,1), bt.add(e+i,-1);
        cout1(morethan+ret);
        morethan-=E[i].size();
    }
}

Measured memory_bytes: 12288
n = int(input())
count_dict = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for i in range(n):
    s = input()
    if s in count_dict:
        count_dict[s] += 1
for k, v in count_dict.items():
    print("{} x {}".format(k, v))


Measured memory_bytes: 69848
// E - Almost Everywhere Zero
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
string N;
int K;
int dp[100][2][4];// digit DP, [|N|: 0 origin][notLessThan?][k:0~3], init = 0
int lt = 0, eq = 1;//lt: <, eq: =

int solve(){
	int dn = N.size();
	int di = N[0] - '0';
	dp[0][lt][0] = 1;
	dp[0][lt][1] = di>0? di-1:di;
	dp[0][eq][1] = 1;

	rp(i,1,dn){
		di = N[i] - '0';
		int lt0 = 1, ltn = 9;//lt <
		int eq0 = di? 1:0, eqn = max(0, di-1);//eq =

		// lt <
		rp(k,0,4){
			int x = dp[i-1][lt][k] * lt0 + dp[i-1][eq][k] * eq0;
			if(k) x += dp[i-1][lt][k-1] * ltn + dp[i-1][eq][k-1] * eqn;
			dp[i][lt][k] = x;
		}

		// eq =
		irp(k,2,-1){
			if(dp[i-1][eq][k]){
				if(di) dp[i][eq][k+1] = di>0;
				else dp[i][eq][k] = 1;
			}
		}

	}

	return dp[dn-1][lt][K] + dp[dn-1][eq][K];
}

int main(){
	cin>>N>>K;
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string a,b;
  cin>>a>>b;
  if(a=="H"){
    cout<<b<<"\n";
    return(0);
  }
  if(a=="D"){
    if(b=="H"){
    cout<<"D"<<"\n";
    return(0);
    }
    cout<<"H"<<"\n";
    
  return(0);
  }}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
int A,B;
int main(){
    cin >> A >> B;
    if(A >= B) cout << max(A,B) + max(A-1,B) << endl;
    else cout << max(A,B) + max(A,B-1) << endl;
}

Measured memory_bytes: 256
# 合計金額がY円になるお札の組み合わせは複数ある。
# ので、万札→五千円札→千円札の順にできるだけ多くいれるように
# 合計金額がY円になるお札の枚数の組み合わせを順番に考えていく。
# その組み合わせについて、お札の枚数が合計でN枚になっているかをチェックする。
# 合計枚数がN枚になっていれば問題の答えなのでそれを出力。
# 最後まで見つからなければ、その組み合わせが存在しないので、NGパターンの答えを出力
# (このパターンでは、合計枚数が一番少ないパターンから順番に考えていくことになる)

# 万札→五千円札→千円札の順に枚数を多くするように考えているが、
# 千円札が一番多くなるように・・・などすれば、入力値によって
# 別の組み合わせが先に見つかるので、回答は複数存在する。
# そのため、問題も複数ある回答候補のうち何を出力してもいいようになっている。

def main():
    # 入力値をintに変換しながら取得
    N,Y = map(int, input().split())
        
    # 万札は最大で何枚入れられるか
    m_man = Y // 10000
    for x in range(m_man, -1, -1):
        # 万札がx枚入っている時に五千円札が最大で何枚入れられるか
        m_gosen = (Y - 10000*x) // 5000

        for y in range(m_gosen, -1, -1):
            # 万札がx枚、五千円札がy枚のときに千円札が何枚必要か
            z = (Y - 10000*x - 5000*y) // 1000
            
            # 合計金額がY円になる組み合わせが見つかったので、
            # 合計枚数がN枚であるかを確認する
            if x + y + z == N:
                # 答えを出力
                print('{} {} {}'.format(x, y, z))
                quit()
                
            # ループが進むにつれて、袋にいれる枚数が増えていく一方なので、
            # このソースをいれると若干処理が早く終わる。（万札が減れば全体の札数は増える）
            # 今回はそこまで必要ないので、コメントアウトで記載する。
            # if x + y + z > N:
            #     print('-1 -1 -1')
            #     quit()
            
    # NG パターンの回答を出力
    print('-1 -1 -1')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;


int main(){
   ll n;cin >>n;
   ll lcm=1;
    for (int i = 0; i < n; ++i) {
        ll t;cin>>t;
        ll g=__gcd(t,lcm);
        lcm=lcm/g*t;
    }
    cout <<lcm<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int A[200005];

int main() {
    int a,n;
    cin>>n;
    for(int i=0;i<n;++i) {
        scanf("%d",&A[i]);
        A[i]-=i+1;
    }
    sort(A,A+n);
    long long x=0;
    for(int i=0;i<n;++i) {
        x+=abs(A[i]-A[n/2]);
    }
    cout<<x;
    return 0;
}


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

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

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; }}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; }}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M; cin >> N >> M;
    if (N == M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 384
s = input()
sum = 0

for bit in range(1<<(len(s)-1)):
  f = s[0]
  
  
  for i in range(len(s)-1):
    if bit & (1<<i):
      f += "+"
      
    f += s[i+1]
   
    
  sum += eval(f)
  
print(sum)

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

using namespace std;

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

const double PI=3.14159265358979323846;

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

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

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

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep (i, n) cin >> s[i];
    sort(s.begin(), s.end());

    rep (i, n)
    {
        cout << s[i];
    }
    cout << "\n";

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
double plus( double a, double b ){return a + b;}
double minus( double a, double b ){return a - b;}
double product( double a, double b ){return a * b;}
double divide( double a, double b ){return a / b;}
double (*calculation[4])(double,double) = {plus, minus, product, divide};
void rpn( const char *t, double stack[], int *stack_ptr )
{
	char* strOperator[] = {"+","-","*","/"};
	int i;
	for( i = 0;i < 4;i++ ) if( strcmp( strOperator[i], t ) == 0 ) break;
	if( i != 4 ){
		(*stack_ptr)--;
		stack[*stack_ptr - 1] = ( *calculation[i] )( stack[*stack_ptr - 1], stack[*stack_ptr] );
	} else stack[ (*stack_ptr)++ ] = atof( t );
}
int main(void)
{
	char str[81],*t;
	double stack[81];
	int i,stack_ptr;
	while( fgets( str, 81, stdin ) ){
		for( i = 0;i < 81;i++ ) stack[i] = 0;
		for( i = 0;i < 81;i++ ) if( str[i] == '\n' ){ str[i] = '\0'; break; }
		stack_ptr = 0;
		t = strtok( str, " " );
		rpn( t, stack, &stack_ptr );
		while( ( t = strtok( NULL, " ") ) != NULL ) rpn( t, stack, &stack_ptr );
		printf("%f\n", stack[0] );
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 1e6;

int x;
int main()
{
	while(scanf("%d", &x) != EOF)
	{
		int ans = 0;
		for(int i = 1; ; i++)
		{
			ans += i;
			if(ans >= x)
			{
				printf("%d\n", i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

    cout << ans << endl;

    return 0;
}
    

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

constexpr ll INF = 1e15;

constexpr ll mod = 1e9 + 7;

template<typename T>
void cmpmax(T& reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void cmpmin(T& reference, T value) {
	reference = min(reference, value);
}

int main() {
	ll a, b, h, m;
	cin >> a >> b >> h >> m;
	double r1 = 2 * M_PI * (360.0 / 12 * h + 360.0 / 12 / 60 * m) / 360.0;
	double r2 = 2 * M_PI * (360.0 / 60 * m) / 360.0;
	double x1 = a * cos(r1);
	double y1 = a * sin(r1);
	double x2 = b * cos(r2);
	double y2 = b * sin(r2);
	double dx = x1 - x2;
	double dy = y1 - y2;
	double d = sqrt(dx * dx + dy * dy);
	cout << setprecision(10) << d << endl;
	return 0;
}



Measured memory_bytes: 4164
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

s = gets.chomp
puts (s[2] == s[3] and s[4] == s[5])? "Yes" : "No"


Measured memory_bytes: 1788
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto M = readln.chomp.to!int;
    long r, n = -1;
    foreach (_; 0..M) {
        auto dc = readln.split.to!(long[]);
        auto d = dc[0];
        auto c = dc[1];
        if (n == -1) {
            --c;
            n = d;
        }
        while (c) {
            if (c % 2 == 1) {
                ++r;
                n += d;
                if (n >= 10) {
                    ++r;
                    n = 1 + n%10;
                }
            }
            c /= 2;
            switch (d) {
                case 0: r += c; break;
                case 1: r += c; d = 2; break;
                case 2: r += c; d = 4; break;
                case 3: r += c; d = 6; break;
                case 4: r += c; d = 8; break;
                case 5: r += c*2; d = 1; break;
                case 6: r += c*2; d = 3; break;
                case 7: r += c*2; d = 5; break;
                case 8: r += c*2; d = 7; break;
                case 9: r += c*2; d = 9; break;
                default:
            }
        }
    }
    writeln(r);
}

Measured memory_bytes: 1276
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;}

/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[500005];
bool used[500005];
char s[500005],t[500005];
bool flag,dame;

void dfs(ll node){
	used[node] = true;
	for(int i=0;i<G[node].size();i++){
		ll newnode = G[node][i];
		if(used[newnode])continue;
		dfs(newnode);
	}
	return;
}


int main(){
	cin >> n >> m;
	for(i=0;i<m;i++){
		cin >> a >> b >> c;
		G[a].pb(b);
		G[b].pb(a);
	}
	for(i=1;i<=n;i++){
		if(!used[i]){
			ans++;
			dfs(i);
		}
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 30976
#include<iostream>
#include<iomanip>

using namespace std;

int main() {
  int n,m;
  double ans;

  cin>>n>>m;
  
  for (int i=1;i<=n;++i) {
	double x=1.0/n;
    int hoge=i;
    while(hoge<m) {
		hoge*=2;x/=2;
	}
    ans+=x;
  }
  
  cout<<fixed<<setprecision(10)<<ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define int long long
#define swap(x,y) (x^=y^=x^=y)

#define debug1(a) cerr<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

using namespace std;

#define mod 1000000007
long long modexpo(long long x, long long p){
    int res = 1;x = x%mod;
    while(p){
        if(p%2)res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

// int max(int a,int b){return (a>b?a:b);} 
// int min(int a,int b){return (a<b?a:b);}


struct compare{
    bool operator() (const pair<int,int> a, const pair<int,int> b) const{
        return a.first < b.first;
    }
};

int32_t main(){
    IOS
    int n;
    cin >> n;
    int arr[n];
    int cur = 0;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        if(i%2 == 0){
            cur += arr[i];
        }
        else{
            cur -= arr[i];
        }
    }
    cur /= 2;
    int ans[n];
    for(int i = 0; i < n; i++){
        ans[i] = cur*2;
        cur = arr[i] - cur;
    }
    for(int i : ans){
        cout << i << " " ;
    }
    cout << endl;
} 

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

int main()
{
	stack<int> stack1;
	stack<pair<int, int> >stack2;
	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++)
	{
		if (ch == '\\')stack1.push(i);
		else if (ch == '/' && stack1.size() > 0)
		{
			int j = stack1.top(); 
			stack1.pop();
			sum += i - j;
			int a = i - j;
			while (stack2.size() > 0 &&  stack2.top().first > j)
			{
				a += stack2.top().second; 
				stack2.pop();
			}
			stack2.push(make_pair(j, a));
		}
	}
	
	vector<int> ans;
	while (stack2.size() > 0) {
		ans.push_back(stack2.top().second);
		stack2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++)
	{
		cout << " ";
		cout << ans[i];
	}

	cout << endl;
	return 0;
}


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

#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()


signed main(){
    int k; cin >> k;
    //priority_queue<int,vector<int>,greater<int>> que;
    queue<int> que;
    for(int i=1; i<=9; i++){
        que.push(i);
    }
    int x;
    //while(true){
    for(int i=0; i<k; i++){
        x=que.front();
        que.pop();
        
        if(x%10==0){
            que.push(x*10+x%10);
            que.push(x*10+x%10+1);
        //}else if(x%9==0){
        }else if(x%10==9){
            que.push(x*10+x%10-1);
            que.push(x*10+x%10);
        }else{
            que.push(x*10+x%10-1);
            que.push(x*10+x%10);
            que.push(x*10+x%10+1);
        }
    }
    cout<<x<<endl;
}


Measured memory_bytes: 1792