akhauriyash/Code-Regression huggingface dataset:
#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() {
    string s;
    cin >> s;
    int zero=0;
    int one = 0;
    int n=s.length();
    rep(i,n){//0スタート01010101...
        if(i%2==0 and s[i]=='1')zero++;//奇数文字目のとき
        else if (i%2==1 && s[i] == '0'){
            zero++;
        }
    }
    rep(i,n){//1start:1010101....
        if(i%2==0 && s[i]=='0')one++;
        else if (i%2==1 && s[i] == '1'){
            one++;
        }
    }
    cout << min(zero,one) << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[26],ans[26];
int main() {
	string s;
	cin>>s;
	for(ll i=0;i<26;i++){
		ans[i]=a[i]=-1;
	}
	for(ll i=0;i<s.size();i++){
		ll now=s[i]-'a';
		ans[now]=max(i-a[now],ans[now]);
		a[now]=i;
	}
	for(ll i=0;i<26;i++){
		if(ans[i]!=-1){
			ans[i]=max(ans[i],ll(s.size()-a[i]));
		}
	}
	ll Ans=inf;
	for(ll i=0;i<26;i++){
		if(ans[i]!=-1){
			Ans=min(Ans,ans[i]);
		}
	}
	cout <<Ans-1;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter

val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

//ABC129_C
fun func() {
    val (N, M) = listOfInt()
    var A = IntArray(M, { nextInt() })
    var K = BooleanArray(N + 1, { true })
    A.forEach { K[it] = false }
    var dp = IntArray(N + 1); dp[0] = 1
    val MOD = 1000000007
    for (n in 0 until N - 1) {
        if (K[n + 1]) dp[n + 1] = (dp[n + 1] + dp[n]) % MOD
        if (K[n + 2]) dp[n + 2] = (dp[n + 2] + dp[n]) % MOD
    }
    dp[N] = (dp[N] + dp[N - 1]) % MOD
    println("${dp[N]}")
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) } //{ it.toInt() }


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

int main() {
    int N;
    int a;
    set<int> paper;

    cin >> N;
    for (int i=0; i<N; i++) {
        cin >> a;
        if (paper.find(a) == paper.end()) paper.insert(a);
        else paper.erase(a);
    }

    cout << paper.size() << endl;
 
    return 0;
}

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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;


void solve()
{
	int r, g, b, k;
	cin >> r >> g >> b >> k;
	int cnt = 0;
	while (g <= r)
	{
		cnt++;
		g *= 2;
	}
	while (b <= g)
	{
		cnt++;
		b *= 2;
	}
	if (cnt <= k) cout << "Yes" << endl;
	else cout << "No" << endl;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cmath>
#define PI 3.141592653589
using namespace std;

int main() {
  int d, a;
  double angle = 0.0, x = 0.0, y = 0.0;
  while (true) {
    scanf("%d,%d", &d, &a);
    if (d == 0 && a == 0) break;
    double rad = angle * PI / 180.0;
    x += d * sin(rad);
    y += d * cos(rad);
    angle += a;
  }
  printf("%d\n%d\n", (int)x, (int)y);
}


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

int main(){
  int n;
  cin >> n;
  if(n >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string n;
	int ans=0;
	cin >>n;
	rep(i,19){
		if(n[i]==','){
			cout<<" ";
		}else{
			cout<<n[i];
		}
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,a[100005],ans;
int main()
{
	scanf("%d%d",&m,&n);
	for(int i=0;i<n;i++)
	  scanf("%d",&a[i]);
	sort(a,a+n);
	for(int i=n-1;i>=1;i--)
	  a[i]-=a[i-1];
	n--;
	sort(a+1,a+n+1);
	for(int i=1;i<=n-m+1;i++)
	  ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
N = gets.to_i
arr = N.times.map{ gets.to_i }

sort_arr = arr.sort
max_num = sort_arr[arr.count - 1]
next_max_num = sort_arr[arr.count - 2]

arr.each do |i|
  if i == max_num
    puts next_max_num
  else
    puts max_num
  end
end

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

int main(void) {
  int A, B;
  cin >> A >> B;

  for (int C = 1; C <= 3; ++C) {
    if ((A * B * C) % 2 != 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
 
  return 0;
}

Measured memory_bytes: 3584
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int v=sc.nextInt();
		int b=sc.nextInt();
		int w=sc.nextInt();
        int t=sc.nextInt();
  		long c=0;
  		int ans=0;
  		if(v<=w){
        ans=1;
        }else{
        c=v-w;
        c*=t;
        if(c>=Math.abs(b-a)){
        	ans=0;
        }else{
        	ans=1;
        }
        }
		
    
 	if(ans==0){
    		System.out.println("YES");
    	}else{
     		System.out.println("NO");
   	 }

    }
}

Measured memory_bytes: 35764
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200005;
int n,m,ans,a[N],sum1[N],sum2[N];
signed main(){
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++)sum1[i]=sum1[i-1]+max(a[i],0LL),sum2[i]=sum2[i-1]+a[i];
	for (int i=0;i<=n-m;i++)
		ans=max(ans,max(0LL,sum2[i+m]-sum2[i])+sum1[n]-(sum1[i+m]-sum1[i]));
	printf("%lld",ans);	
}

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

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

using namespace std;

string q(int i){
  cout<<i<<endl;
  string t;cin>>t;
  return t;
}

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

  int min=0, max=n-1, mid=0;
  string c=q(0);
  if(c=="Vacant"){ cout<<0;return 0; }

//cout<<max<<' '<<min;

  while(max-min>1){
    mid=(min+max)/2;
    string mc;
    mc = q(mid);
    if(mc=="Vacant")return 0;
    // 偶数位置に0indexと異なる性別の人間が座っている
    // もしくは奇数位置に0indexと同じ性別の人間が座っている
    // つまりmidよりも前に空席が存在して順番をずらしている
    if(mid%2==0 && mc!=c || mid%2==1 && mc==c) max=mid;
    else min=mid;
//cout<<max<<' '<<min<<' '<<mid<<endl;
  }
  q(mid-1);
  q(mid+1);

  
cout<<"###"<<endl;
  return 0;
}

Measured memory_bytes: 852
#pragma region Include
#include <bits/stdc++.h>
// #include <algorithm>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <iostream>
// #include <iterator>
// #include <map>
// #include <queue>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <unordered_map>
// #include <unordered_set>
// #include <vector>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define newl "\n"
#define out(x) cout << (x) << newl
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << newl
template <class T>
using VV = vector<vector<T>>;
#define Uni(v) (v).erase(unique((v).begin(), (v).end()), (v).end());

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;

string tostring(int i, int digit) {
  auto cur = cout.flags();
  stringstream ss;
  ss << setw(4) << setfill('0') << i;
  string ret = ss.str();
  cout.flags(cur);
  return ret;
}

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

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

#pragma endregion

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  rep2(i, 1, 10) {
    rep2(j, 1, 10) {
      if (i * j == N) {
        out("Yes");
        return 0;
      }
    }
  }
  out("No");

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println((a-1) * (b-1));
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long 
using namespace std;
const int N = 1e5+10;
const int M = 1e9+7;
int dp[100005];
vector <int> v[100005];
int fun(int i)
{
	if(dp[i]!=0)
	{
		return dp[i];
	}
	else
	{
		int ans = 0;
		for (int j = 0; j < v[i].size(); ++j)
		{
			ans = max(fun(v[i][j]),ans);
		}
		if(v[i].size()==0)
			dp[i] = ans;
		else
			dp[i] = ans+1;
		return dp[i];
	}
}
int main(){
	FIO;
	int n,m,a,b,ans = 0;
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b;
		v[a].push_back(b);
	}
	for (int i = 1; i <= n; ++i)
	{
		ans = max(ans,fun(i));
		// cout << fun(i) << " ";
	}
	cout << ans << "\n";
	return 0;  
}

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

string S;
int A, B, C, D;

string to_line_board(string s){
    string t = "";
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'b')
            t += 'b';
        else{
            for(int j=0; j<s[i]-'0'; j++)
                t += '.';
        }
    }
    return t;
}

vector<string> to_board(){
    vector<string> vec;
    
    string s = "";
    for(int i=0; i<S.size(); i++){
        if(S[i] == '/'){
            vec.push_back(to_line_board(s));
            s = "";
        }else{
            s += S[i];
        }
    }
    vec.push_back(to_line_board(s));
    
    return vec;
}

string to_string(vector<string> board){
    vector<string> vec;
    
    for(auto s: board){
        string t = "";
        
        int n = s.size();
        for(int i=0; i<n;){
            if(s[i] == 'b'){
                t += 'b';
                i++;
            }else{
                int cnt = 0;
                for(;i<n && s[i]=='.'; i++){
                    cnt++;
                }
                t += '0'+cnt;
            }
        }
        vec.push_back(t);
    }
    
    string res = "";
    for(int i=0; i<vec.size(); i++){
        res += vec[i];
        if(i != vec.size()-1)
            res += '/';
    }
    return res;
}

int main(){
    while(cin >> S, S!="#"){
        cin >> A >> B >> C >> D;
        A--; B--; C--; D--;
        
        auto board = to_board();
        swap(board[A][B], board[C][D]);
        cout << to_string(board) << endl;
    }
    
}

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

const ll mod = 1e9 + 7;

long long gcd(ll x, ll y){
	if(x > y) swap(x, y);
	while(x != 0){ y %= x; swap(x, y); }
	return y;
}

ll mpow(ll x, ll r){
	if(r == 0) return 1;
	if(r % 2 == 1){ return x * mpow(x, r-1) % mod; }
	else{ ll aa = mpow(x, r/2); return aa*aa%mod; }
}

long double pi = 3.14159265358979;
int num[200010];


int main(){
	int N; cin >> N;
	rep(i, N-1){
		int a; cin >> a;
		a--;
		num[a]++;
	}
	rep(i, N) cout << num[i] << endl;
	return 0;
}

Measured memory_bytes: 4376
#include<stdio.h>
#define MOJI 1200
  
int main()
{
  char str[MOJI];
  int i, count=0;
  
  while(1){
    scanf("%c", &str[count]);
  
    if('A' <= str[count] && str[count] <= 'Z'){
      str[count] += 'a' - 'A';
    }
    else if('a' <= str[count] && str[count] <= 'z'){
      str[count] -= 'a' - 'A';
    }
  
    if(str[count] == '\n')break;
    count++;
  }
  
  for(i=0; i < count ;i++)
    printf("%c",str[i]);
  printf("\n");
  return 0;
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int n, k, cnt = 0;
    cin >> n >> k;
    while (n > 0) {
        n /= k;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  string S;
  cin >> S;
  string target;
  target = "keyence";
  if(S == target){
    cout << "YES" << endl;
    return 0;
  }
  for(int i=0; i<S.size(); i++){
    for(int j=i; j<S.size(); j++){
      string s;
      s = "";
      for(int k=0; k<S.size(); k++){
        if(i<=k && k<=j){
          continue;
        }else{
          s.push_back(S[k]);
        }
      }
      if(s == target){
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[][] dp = new int[10][10];
    for (int i = 1; i <= n; i++) {
      int j = i;
      int trailing = j % 10;
      if (trailing == 0) continue;
      while (j / 10 > 0) {
        j /= 10;
      }
      int head = j;
      dp[head][trailing]++;
    }
    long count = 0;
    for (int i = 1; i <= 9; i++) {
      for (int j = i; j <= 9; j++) {
        if (i == j) count += dp[i][j] * dp[j][i];
        else count += 2 * dp[i][j] * dp[j][i];
      }
    }
    System.out.println(count);
  }
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int p[2000];
int main(){
	int x,n;cin>>x>>n;
	set<int>se;
	rep(i,n)scanf("%d",&p[i]),se.insert(p[i]);
	int A=x,B=x;
	while(1){
		if(!se.count(A))break;
		A--;
	}
	while(1){
		if(!se.count(B))break;
		B++;
	}
	if(abs(x-A)<=abs(x-B)){
		cout<<A<<endl;
	}
	else cout<<B<<endl;
}

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

using namespace std;

const int MaxN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;

pair <double, double> p[MaxN];
pair <double, char> all[MaxN];
int n, k;

bool can(double rad) {
  int res = 1;
  for (int i = 1; i <= n && res < k; ++i) {
    int c = 1, sz = 0;
    for (int j = 1; j <= n; ++j) {
      if (i == j) {
        continue;
      }
      double d = hypot(p[i].first - p[j].first, p[i].second - p[j].second);
      if (d / 2 > rad) {
        continue;
      }
      pair < double, double > v = make_pair((p[j].first - p[i].first) / d, (p[j].second - p[i].second) / d);
      double l1 = d / 2;
      double l2 = sqrt(rad * rad - l1 * l1);
      l1 /= rad;
      l2 /= rad;
      pair < double, double > p1 = make_pair(v.first * l1 + v.second * l2, v.second * l1 - v.first * l2);
      pair < double, double > p2 = make_pair(v.first * l1 - v.second * l2, v.second * l1 + v.first * l2);
      double ang1 = atan2(p1.second, p1.first);
      double ang2 = atan2(p2.second, p2.first);
      if (ang1 > ang2) {
        c++;
      }
      all[sz++] = make_pair(ang1, 1);
      all[sz++] = make_pair(ang2 + 1e-10, -1);
    }
    sort(all, all + sz);
    for (int j = 0; j < sz; ++j) {
      c += all[j].second;
      if (res < c) {
        res = c;
      }
    }
  }
  return res >= k;
}

int main() {
    cin >> n;
    k = n;
    for (int i = 1; i <= n; ++i) cin >> p[i].first >> p[i].second;
    random_shuffle(p + 1, p + n + 1);
    double l = 0, r = 1e4;
    for (int it = 0; it < 100; ++it){
        double m = (l + r) / 2;
        if (can(m)) r = m; else l = m;
    }
    cout.precision(20);
    cout << fixed << (l + r) / 2.0 << '\n';
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int mod){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%mod;Rac[n-1]=modInv(Fac[n-1],mod);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int n;
V<int> v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    int a;
    cin >> a;
    v.pb(a);
  }
  uniq(v);
  cout << (sz(v)==n ? "YES" : "NO") << endl;;
}

Measured memory_bytes: 1400
#include<stdio.h>
 
int main(void)
{
    int num;
    char str[100];
    int k;
    
    scanf("%d", &num);
    scanf("%s", str);
    scanf("%d",&k);
    
    
    for(int i=0;i<num;i++){
        if(str[i]!=str[k-1])
            printf("*");
        else
            printf("%c",str[i]);
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int

struct edge
{
  int to, cost;
};
typedef std::vector<std::vector<edge>> graph;
const ll MOD = 1000000007;
using namespace std;

int main()
{
  int n;
  cin >> n;
  pair<ll, ll> p[200000];
  REP(i, n)
  {
    ll a, b;
    cin >> a >> b;
    p[i] = make_pair(b, a);
  }

  sort(p, p + n);

  ll t = 0;
  REP(i, n)
  {
    if (t + p[i].second <= p[i].first)
    {
      t += p[i].second;
    }
    else
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3328
n,k=map(int,input().split())
hps=list(map(int,input().split()))
hps.sort()
if k>n:
  print(0)
elif k==n:
  print(0)
else:
  ans=0
  for i in range(k):
    hps.pop()
  ans+=sum(hps)
  print(ans)

Measured memory_bytes: 26024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string A ;
  string tg = "{3}";
  smatch m;
  cin >> A;
  for (int i = 0; i < A.size(); i++){
    regex re(A[i]+tg);
    if (regex_search(A, m, re)){
    cout << "Yes" << endl;
      return 0;
    }
  }
      cout << "No" << endl;

}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}
int main(){
    ll n;cin >> n;
    ll x=inf;
    ll sum=0;
    rep(i,n){
        ll a,b;cin >> a >> b;
        sum+=b;
        if(a>b)chmin(x,b);
    }
    if(x==inf)cout << 0 <<endl;
    else cout << sum-x <<endl;
} 

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int A,B,ans=0;
    cin>>A>>B;
    for(int i=A;i<=B;i++){
        string z=to_string(i),x=to_string(i);
        reverse(x.begin(),x.end());
        if(z==x)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val h = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    var cnt = 0
    for (i in 0 until n) {
        if (i != n - 1 && h[i] >= h[i+1]) {
            cnt++
        }
        if (i == n - 1 || h[i] < h[i+1]) {
            if (ans < cnt) {
                ans = cnt
            }
            cnt = 0
        }
    }
    println(ans)
}


Measured memory_bytes: 59652
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}

//ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int main() {
    int D, N;
    cin >> D >> N;
    if (D == 0) {
        if (N != 100) {
            cout << N << endl;
        }
        else cout << 101 << endl;
    }
    else if (D == 1) {
        if (N != 100) {
            cout << N * 100 << endl;
        }
        else cout << 10100 << endl;
    }
    else if (D == 2) {
        if (N != 100) {
            cout << N * 10000 << endl;
        }
        else cout << 1010000 << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
main()
{
	int A, B, C, D, i, s;
	int a[110];
    while(scanf("%d%d%d%d",&A,&B,&C,&D)!=EOF)
    {
    	s=0;
    	for(i=0;i<110;i++)
    	a[i]=0;
    	for(i=0;i<110;i++)
    	{
    	if(i>=A&&i<B)
    	a[i]++;
    	if(i>=C&&i<D)
    	a[i]++;	
        }
    	for(i=0;i<110;i++)
    	{
    	if(a[i]==2)
    	s++;
        }
    	printf("%d\n",s);
					
	}
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
  
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
  
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
  
using namespace std;
//using namespace __gnu_pbds;
         
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using pld = pair <ld, ld>;
 
/*
const ll MAX_MEM = 5e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
 
*/
 
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
         
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
         
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
         
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
         
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("circlecover.in", "r", stdin);
    //freopen("circlecover.out", "w", stdout);
}
 
signed main()
{
    Start();
    int ans = 0;
    int a, b;
    cin >> a >> b;
    ans += a;
    a = a - b;
    if (a < b)
        swap(a, b);
    while (b != 0)
    {
        int cur = a / b;
        ans += cur * (b + b);
        a %= b;
        swap(a, b);
    }
    cout << ans - a;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
p = 0
for i in range(n):
    if a[i]<=b[i]:
        ans += a[i]
        if a[i+1]<=b[i]-a[i]:
            ans += a[i+1]
            a[i+1] = 0
        else:
            a[i+1] -= b[i]-a[i]
            ans += b[i]-a[i]
    else:
        ans += b[i]
print(ans)


Measured memory_bytes: 18624
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        boolean[][] map = new boolean[h][w];
        Deque<Point> q = new ArrayDeque<Point>();
        for(int i = 0; i < h; i++){
            String s = sc.next();
            int j = 0;
            for(char c : s.toCharArray()){
                if(c == '#'){
                    map[i][j] = true;
                    q.add(new Point(0,j,i));
                }
                j++;
            }
        }
        int ans = 0;
        int[] gx = {-1,0,0,1};
        int[] gy = {0,-1,1,0}; 
        while(q.size() > 0){
            Point p = q.poll();
            int cnt = p.cnt;
            int x = p.x;
            int y = p.y;
            for(int i = 0; i < 4; i++){
                int nx = x + gx[i];
                int ny = y + gy[i];
                if(check(nx,ny,w,h,map)){
                    map[ny][nx] = true;
                    q.add(new Point(cnt+1,nx,ny));
                }
            }
            ans = Math.max(ans,cnt);
        }
        System.out.println(ans);
    }
    
    public static boolean check(int x, int y, int w, int h, boolean[][] map){
        return (x >= 0 && x < w && y >= 0 && y < h && !map[y][x]);
    }
}

class Point{
    int cnt,x,y;
    public Point(int cnt, int x, int y){
        this.cnt = cnt;
        this.x = x;
        this.y = y;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 67440
#include <iostream>

using namespace std;

int main()
{
    int n, m, x, a, l_cost = 0;

    cin >> n >> m >> x;
    for (int i = 0; i < m; i++) {
        cin >> a;
        if (a < x) l_cost++;
    }
    cout << (l_cost < m-l_cost ? l_cost : m-l_cost) << endl;
}

Measured memory_bytes: 256
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pair<ll,ll> >   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pair<int,int> >   vpi;
typedef    vector<pair<double,double> >   vpd;
typedef    pair<double,double>   pd;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define all(x) x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
const    ld   PI=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}


int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{

ll r,d,x;
cin>>r>>d>>x;

for(int i=0;i<10;i++)
{
cout<<r*x-d<<"\n";
x=r*x-d	;
}









}return 0;}

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

template<typename T> vector<int> z_algorithm(const int len, const T& in) {
  vector<int> res(len, 0);
  int c = 0;
  for (int i = 1; i < len; ++i) {
    if (i + res[i - c] < c + res[c]) {
      res[i] = res[i - c];
    } else {
      int j = max(0, c + res[c] - i);
      while (i + j < len && in[j] == in[i + j]) j++;
      res[i] = j;
      c = i;
    }
  }
  res[0] = len;
  return res;
}

template<typename T> vector<int> z_algorithm(const T& in) {
  return z_algorithm((int) in.size(), in);
}

template<typename T> vector<int> z_algorithm(const T& in_first, const T& in_second) {
  T combined = T();
  combined.append(in_first);
  combined.append(in_second);
  int n = (int) in_first.size(), m = (int) in_second.size();
  vector<int> v = z_algorithm(n + m, combined);
  vector<int> res(m);
  for (int i = 0; i < m; i++) {
    res[i] = min(n, v[i + n]);
  }
  return res;
}

class UnionFind {
private:
  int siz;
  vector<int> a;

public:
  UnionFind(int x) : siz(x), a(x, -1) {}

  int root(int x) {
    return a[x] < 0 ? x : a[x] = root(a[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    siz--;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] =x;
    return true;
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -a[root(x)];
  }
  
  int conneted_component() {
  	return siz;
  }
};

signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = (int) s.size(), m = (int) t.size();
  s += s;
  s += s;
  while ((int) t.size() * 2 > (int) s.size()) s += s;
  vector<int> v = z_algorithm(t, s);
  UnionFind uf(n);
  for (int i = 0; i < n; i++) {
    if (v[i] == m && v[i + m] == m) {
      if (!uf.unite(i, (i + m) % n)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == m) ans = max(ans, uf.size(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 24284
## import

## function definition 

## main process
if __name__ == '__main__':
    
    N, M = map(int,input().split())
    HEIGHT_LIST = list(map(int,input().split())) 
    
    ans = [1] * N
    for j in range(M):
        a, b = map(int,input().split())
        a -= 1
        b -= 1
        height_a = HEIGHT_LIST[a]
        height_b = HEIGHT_LIST[b]

        if height_a < height_b:
            ans[a] = 0
        elif height_a > height_b:
            ans[b] = 0
        else:
            ans[a] = 0
            ans[b] = 0

    print(sum(ans))

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


int main() {
	string S;
	cin >> S;
	string a = "";
	string b = "";
	for(int i = 0; i < S.size(); i++){
		if(i % 2 == 0){
			a += "1";
		}
		else{
			a += "0";
		}
	}
	for(int i = 0; i < S.size(); i++){
		if(i % 2 == 0){
			b += "0";
		}
		else{
			b += "1";
		}
	}
	int ans1 = 0;
	int ans2 = 0;
	for(int i = 0; i < S.size(); i++){
		if(S[i] != a[i]){
			ans1++;
		}
		if(S[i] != b[i]){
			ans2++;
		}
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N, C, a, cake = 0;
	cin >> N >> C;
	for (int i = 0; i < C; i++) {
		cin >> a;
		cake += a;
	}
	N++;
	if (cake % N != 0) {
		cout << cake / N + 1 << endl;
	}
	else {
		cout << cake / N << endl;
	}
}


Measured memory_bytes: 3108
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,a[200005],b[200005],sum;
bool vis[200005];
bool cmp(int a,int b){
	if((a&1)!=(b&1)) return (a&1)>(b&1);
	return a>b;
}
int main(){
	scanf("%d%d",&n,&m);
	int tot=0;
	for(int i=1;i<=m;i++){
		scanf("%d",&a[i]);
		if(a[i]&1) tot++;
	}
	if(tot>2) return puts("Impossible"),0;
	if(m==1){
		if(n>1)printf("%d\n2\n%d %d\n",n,n-1,1);
		else printf("1\n1\n1");
		return 0;
	}
	sort(a+1,a+m+1,cmp);
	tot=0;
	if(a[2]&1) swap(a[2],a[m]);
	for(int i=1;i<=m;i++) printf("%d ",a[i]);
	puts("");
	b[++sum]=a[1]-1;
	if(a[1]==1) sum=0;
	for(int i=2;i<m;i++){
		b[++sum]=a[i];
	}
	if(m>1) b[++sum]=a[m]+1;
	printf("%d\n",sum);
	for(int i=1;i<=sum;i++) printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
 os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os << "(" << P.first << "," << P.second << ")";}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif


#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
const ll INF = 1e16;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	ll n;
	cin>>n;ll i,j;
	multiset<ll> s,s1,s2;
	ll p1,p2,p;p=p2=p1=0;
	vll v(3*n+1);
	for(i=1;i<=3*n;i++){
		cin>>v[i];
		if(i<=n)s.I(v[i]),p+=v[i];
		else s1.I(v[i]),p1+=v[i];
	}
	for(i=0;i<n;i++){
		ll a = *(--s1.end());s2.I(a);p2+=a;
		s1.erase(s1.find(a));p1 -=a;
	}
	ll ans = p-p1;
	for(i=n+1;i<=2*n;i++){
		ll a = v[i];
		s.I(a);p+=a;
		ll b = *s.begin();s.erase(s.find(b));p-=b;
		if(s2.find(a)!=s2.end()){
			s2.erase(s2.find(a));p2-=a;
		}
		else{
			s1.erase(s1.find(a));p1-=a;
			b = *s2.begin();s2.erase(s2.find(b));p2-=b;
			p1+=b;s1.I(b);
		}
		ans = max(ans,p-p1);
	}
	cout<<ans;
}


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

#define _   int v, int tl, int tr, int l, int r
#define tm  (tl + tr >> 1)
#define sol v+v, tl, tm, l, r
#define sag v+v+1, tm+1, tr, l, r
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 1e5 + 5;

int A[N];

signed main(){
    int n,k;
    cin >> n >> k;
	int ans = mod;
    for(int i=1; i<=n; i++){
		int b;
        scanf("%d", &b);
        A[i] = b;
    	if(i >= k){
            int a = A[i-k+1];
            if(b < 0) ans = min(ans , -a);
        	else{
                if(a > 0) ans = min(ans , b);
                else ans = min(ans , b-a + min(-a,b));
            }
        }
    }
    
    cout << ans;
    return 0;
}

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

using namespace std;


typedef long long ll;
typedef long double ld;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll n,a[1000],i;
	bool ans=true;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]%2==0)
		{
			if(a[i]%3!=0 && a[i]%5!=0)
			{
				ans=false;
				}
		}
	}
	if(ans)
	{
		cout<<"APPROVED"<<endl;
		}
	else
	{
		cout<<"DENIED"<<endl;
		}
	
	
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define lld long double
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	ll n, m, k;
	cin >> n >> m >> k;
	if(n==1||m==1)
	{
		cout << "Yes" << endl;
		return 0;
	}
	set<ll> st;
	st.insert(0);
	REP(i, n+1) REP(j, m+1)
	{
		ll tmp = i*m;
		tmp -= i*j;
		tmp += j*(n - i);
		st.insert(tmp);
	}
	if (st.count(k)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 13056
#include <cstdio>

using namespace std;

const int nmax = 8;
bool graph[nmax][nmax];
int n;


int dfs(int v, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < n; i++) {
        if (visited[i] == false)
            all_visited = false;
    }

    if (all_visited)
        return 1;

    int ret = 0;

    for (int i = 0; i < n; i++) {
        if (graph[v][i] == false)
            continue;
        if (visited[i])
            continue;
        
        visited[i] = true;
        ret += dfs(i, visited);
        visited[i] = false;
    }   

    return ret;
}

int main(void)
{
    int m;
    scanf("%d%d", &n, &m);

    for (int i = 0; i < m; i++) {
        int A, B;
        scanf("%d%d", &A, &B);
        graph[A-1][B-1] = graph[B-1][A-1] = true;
    }

    bool visited[nmax];
    for (int i = 0; i < n; i++)
        visited[i] = false;

    visited[0] = true;
    printf("%d\n", dfs(0, visited));
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define LL long long
#define mod 1000000007
#define maxn 200010
using namespace std;
LL fact[maxn],inv[maxn];
int n,head[maxn],cnt,sz[maxn];//sz[u]是以u为根的子树的节点数
LL pre[maxn],ans[maxn],tp[maxn];//pre[u]是以u为根的子树的安排方式数
struct node{
	int to,next;
}e[maxn<<1];
void add_edge(int u,int v){//邻接表
	cnt++,e[cnt].to=v,e[cnt].next=head[u],head[u]=cnt;
}
LL quick_pow(LL a,LL b){//快速幂
	LL ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(){
	int i,u,v;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);//无向图
	}
	fact[0]=1;
	for(i=1;i<=n;i++)fact[i]=fact[i-1]*i%mod;
	inv[n]=quick_pow(fact[n],mod-2);
	for(i=n-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
}
LL C(int a,int b){//组合数计算
	return fact[a]*inv[a-b]%mod*inv[b]%mod;
}
void dfs1(int u,int fa){
	int b,v;
	sz[u]=1,pre[u]=1;
	for(b=head[u];b;b=e[b].next){
		v=e[b].to;
		if(v==fa)continue;
		dfs1(v,u);
		sz[u]+=sz[v];
		pre[u]=pre[v]*pre[u]%mod*C(sz[u]-1,sz[v])%mod;
	}
}
void dfs2(int u,int fa){//换根dp
	int b,v;
	ans[u]=tp[u]*pre[u]%mod*C(n-1,n-sz[u])%mod;
	for(b=head[u];b;b=e[b].next){
		v=e[b].to;
		if(v==fa)continue;
		tp[v]=ans[u]*quick_pow(pre[v]*C(n-1,sz[v])%mod,mod-2)%mod;//v是下一次搜索的根,u是当前的根,tp[v]代表在以v为根时,pre[u]的值。
		dfs2(v,u);
	}
}
int main(){
	init();
	dfs1(1,0);
	tp[1]=1;
	dfs2(1,0);
	for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 14720