akhauriyash/Code-Regression huggingface dataset:
import itertools
import math
n = int(input())
L = []
R = []
for i in range(n):
  L.append(list(map(int, input().split())))

R = list(itertools.permutations(range(n), n))
out = 0
N = math.factorial(n)
for case in R:
  for i in range(1, n):
    out += math.sqrt((L[case[i]][0] - L[case[i-1]][0])**2 
                     + (L[case[i]][1] - L[case[i-1]][1])**2)
print(out/N)    

Measured memory_bytes: 7972
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,v = 0;
	cin>>n;
	int p[n];
	for(int i = 0;i<n;i++){
		cin>>p[i];
	}
	for(int i = 1;i<=n;i++){
		int k = 0;
		for(int j = 0;j<n;j++){
			if(i<=p[j]){
				k++;
			}
		}
		if(i <= k){

			v = i;
		}
	}
	cout<<v<<endl;
	return 0;
}


Measured memory_bytes: 3136
package main

import "fmt"

func main() {
	var d, t, s int
	fmt.Scan(&d, &t, &s)
	if (d%s ==0 && d/s <= t) || d/s+1 <= t {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1768
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br =
			new BufferedReader(new InputStreamReader(System.in));

			String[] line = br.readLine().split(" ");
			int[] list = new int[3];
			list[0] = Integer.parseInt(line[0]);
			list[1] = Integer.parseInt(line[1]);
			list[2] = Integer.parseInt(line[2]);

			boolean isSorted = false;
			while(!isSorted) {
				for(int i = 0; i < list.length - 1; i++) {
					int temp;
					if(list[i] > list[i+1]) {
						temp = list[i+1];
						list [i+1] = list [i];
						list [i] = temp;
					}
				}
				if(list[0] <=  list[1] && list[1] <= list[2]) {
					isSorted = true;
				}
			} 
			System.out.println(list[0] + " " + list[1] + " " + list[2]);
	}
}

Measured memory_bytes: 24156
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for(int i=0;i<n;i++){
    vector<int> Z(s.size());
    Z[0]=(int)s.size();
    int p=1,q=0;
    while(p<s.size()){
      while(p+q<s.size() and s[q]==s[p+q]) q++;
      Z[p]=q;
      if(q==0){
        p++;
        continue;
      }
      int r=1;
      while(r<q and r+Z[r]<q){
        Z[p+r]=Z[r];
        r++;
      }
      p+=r;
      q-=r;
    }
    for(int j=0;j<s.size();j++){
      ans=max(ans,min(j,Z[j]));
    }
    s=s.substr(1,(int)s.size()-1);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3592
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N, A, B, C, D;
map <ll, ll> MP;

ll Solve(ll num){
  if (num <= 0) return 0;
  if (num == 1) return MP[num] = D;
  if (MP[num] > 0) return MP[num];

  ll ans = INF;
  for (ll i = -3; i <= 3; i++){
    ll now = num - i;
    if (now < 0) continue;
    if (now % 2 == 0 && now / 2 < num){
      ans = min(ans, Solve(now / 2) + A + abs(i) * D);
      ll Lim = (INF - Solve(now / 2)) / D;
      ll deg = abs(now / 2 - num);
      if (deg <= Lim){
        ans = min(ans, Solve(now / 2) + deg * D);
      }
    }
    if (now % 3 == 0 && now / 3 < num){
      ans = min(ans, Solve(now / 3) + B + abs(i) * D);
      ll Lim = (INF - Solve(now / 3)) / D;
      ll deg = abs(now / 3 - num);
      if (deg <= Lim){
        ans = min(ans, Solve(now / 3) + deg * D);
      }
    }
    if (now % 5 == 0 && now / 5 < num){
      ans = min(ans, Solve(now / 5) + C + abs(i) * D);
      ll Lim = (INF - Solve(now / 5)) / D;
      ll deg = abs(now / 5 - num);
      if (deg <= Lim){
        ans = min(ans, Solve(now / 5) + deg * D);
      }
    }
    if (MP[now] > 0) ans = min(ans, MP[now] + abs(i) * D);
  }
  return MP[num] = ans;
}

int Ans(){
  MP = {};
  cin >> N >> A >> B >> C >> D;
  MP[1] = D;
  cout << Solve(N) << endl;
  return 0;
}

int main(){
  int T; cin >> T;
  for (int i = 0; i < T; i++) Ans();
  return 0;
}


Measured memory_bytes: 7820
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

typedef long long ll;

const int Maxn = 100005;

int n;
vector <int> neigh[Maxn];
char col[Maxn];
int has[Maxn];
ll res;
ll best;

void Count(int v, int p = 0)
{
	has[v] = col[v] == 'W';
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (u == p) continue;
		Count(u, v); 
		has[v] += has[u] > 0;
	}
}

int Cost(char col, int ch)
{
	if (col == 'W') {
		ch--;
		return ch + (ch % 2 == 0);
	}
	return ch + ch % 2;
}

int Solve(int v, int p, int tp)
{
	res += Cost(col[v], has[v] + tp);
	ll val = Cost(col[v], has[v] + tp) - Cost(col[v], has[v] + tp - 1); 
	ll mx1 = 0, mx2 = 0;
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (u == p || has[u] == 0) continue;
		int got = Solve(u, v, (tp + has[v] - (has[u] > 0)) > 0);
		if (got > mx1) mx2 = mx1, mx1 = got;
		else if (got > mx2) mx2 = got;
	}
	best = max(best, mx1 + val + mx2);
	return mx1 + val;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(b);
		neigh[b].push_back(a);
	}
	int whites = 0;
	for (int i = 1; i <= n; i++) {
		scanf(" %c", &col[i]);
		whites += col[i] == 'W';
	}
	if (whites <= 1) { printf("%d\n", whites); return 0; }
	int root = 1;
	while (col[root] != 'W') root++;
	Count(root);
	Solve(root, 0, 0);
	cout << res - best << endl;
	return 0;
}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint H, W; cin >> H >> W;
    vec<string> grid(H);
    range(i, 0, H) cin >> grid.at(i);
    lint cur_col = 0;
    range(r, 0, H) {
        range(c, 0, cur_col - 1) if (grid.at(r).at(c) == '#') {
            cout << "Impossible" << "\n";
            return 0;
        }
        while (cur_col < W and grid.at(r).at(cur_col) == '#') cur_col += 1;
        range(c, cur_col, W) if (grid.at(r).at(c) == '#') {
            cout << "Impossible" << "\n";
            return 0;
        }
    }
    cout << "Possible" << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include <queue>

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ft first
#define sd second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef queue<int> QI;

const LL mod=1000000007;
LL powmod(LL a,LL b) {LL res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int n,d[2333];
bool f[2333];

int main(){while(~scanf("%d",&n)){memset(d,0,sizeof(d));memset(f,false,sizeof(f));
    rep(i,0,n)scanf("%d",&d[i]);
    rep(i,0,n){
        f[d[i]]=true;
        if(i<n-1)f[d[i]*10+d[i+1]]=true;
        if(i<n-2)f[d[i]*100+d[i+1]*10+d[i+2]]=true;
    }
    rep(i,0,2333){
        if(!f[i]){cout<<i<<endl;break;}
    }
}
	return 0;
}

Measured memory_bytes: 3244
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import Counter


def main():
    N = int(input())
    S = [input() for _ in range(N)]

    aar = ["AC", "WA", "TLE", "RE"]

    cnt = Counter(S)

    for value in aar:
        if value in cnt.keys():
            print(value, cnt[value], sep=" x ")
        else:
            print(value, 0, sep=" x ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 16392
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	ll q, h, s, d; cin >> q >> h >> s >> d;
	s = min({q*4, h*2, s});
	d = min({s*2, d});
	ll n; cin >> n;
	cout << (n%2)*s + (n/2)*d << endl; 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;string f(int n){string s;for(int t,m;n;s.push_back('0'+m))m=n%-10,t=n/-10,(m<0?m+=10,t++:0),n=t;reverse(s.begin(),s.end());return s;}int main(){for(int n;cin>>n,n;cout<<f(n)<<endl);}

Measured memory_bytes: 1196
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  cout << (n * n * n);
}
#endif


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100005

ll sum,n;
vector<int> a;

int main(void)
{
	cin>>n;
	a.resize(3*n);
	for (int i = 0; i < 3*n; i++) {
		cin>>a[i];
	}
	sort(a.begin(),a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		sum+=a[2*i+1];
	}
	cout<<sum<<endl;
	return 0;
}


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

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

    sort(S.begin(), S.end());
    sort(T.rbegin(), T.rend());

    if(S < T){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
let rec f x=function|(0,0)->1|(n,_)when n<=0->0|(n,m)->(let rec(^)i a=if i>m||i>9then a else(i+1)^(a+f(i+1)(n-1,m-i))in x^0)and q()=Scanf.scanf"%d %d
"(fun n s->if n<>0||s<>0then q(Printf.printf"%d
"(f 0(n,s))))
;;try q()with _->()

Measured memory_bytes: 2708
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var n = Number(lines[0]);
 var v = lines[1].split(' ');
 v = v.map(function(str) { return Number(str)});

 for(i=0; i<n-1; i++){
   var min1 = v.sort((a, b)=> a - b)[0];
   v.splice(0,1);
   var min2 = v[0];
   v.splice(0,1);
   var a = (min1 + min2)/2;
   if(v.length == 0){
     break;
   }
   v.push(a);
 }
 console.log(a);
});

Measured memory_bytes: 7756
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    int Apos = 0, Zpos = 0;
    rep(i, S.size()) {
        if(S[i] == 'A') {
            Apos = i;
            break;
        }
    }
    for(int i = S.size() - 1; i >= 0; i--) {
        if(S[i] == 'Z') {
            Zpos = i;
            break;
        }
    }
    cout << Zpos - Apos + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
main()
{
    long long int i,a,b,d,c=0,n;
    cin>>n;
    long long int z[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>z[i];
    }
for(i=1;i<=n;i+=2)
{
    if(z[i]%2!=0)
    {
        c++;
    }
}
cout<<c<<endl;
}


Measured memory_bytes: 3632
import sys
a, b = map(int, raw_input().split())
s = raw_input()


if s[a] == '-' and a + b + 1 == len(s):
    for i in range(len(s)):
        asc = ord(s[i])
        if a == i:
            continue
        if asc < 48 or asc > 57:
            print "No"
            sys.exit()
    print "Yes"
else:
    print "No"

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

int main(){
    int k,a,b,kw;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);
    kw=k;
    while(kw<=b){
        if(a<=kw){printf("OK\n");return 0;}
        kw+=k;
    }
    printf("NG\n");
}

Measured memory_bytes: 3732
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(),y = sc.nextInt();
        int sum = 0;

        if(x==1) {
            sum += 300000;
        } else if(x==2){
            sum += 200000;
        } else if(x==3){
            sum += 100000;
        }

        if(y==1) {
            sum += 300000;
        } else if(y==2){
            sum += 200000;
        } else if(y==3){
            sum += 100000;
        }

        if(x==1 && y==1) {
            sum += 400000;
        }

        System.out.println(sum);

    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 998244353
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>tr;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
P p[300000];
int c[4][300000];
int main(){
	int n;scanf("%d",&n);
	vector<int>xs,ys;
	rep(i,n){
		scanf("%d%d",&p[i].first,&p[i].second);
		xs.push_back(p[i].first);
		ys.push_back(p[i].second);
	}
	sort(xs.begin(),xs.end());
	sort(ys.begin(),ys.end());
	sort(p,p+n,[](P a,P b){return a.first<b.first;});
	tr.clear();
	rep(i,n){
		c[0][i]=tr.order_of_key(p[i].second);
		c[1][i]=i-c[0][i];
		tr.insert(p[i].second);
	}
	tr.clear();
	for(int i=n-1;i>=0;i--){
		int C=n-i-1;
		c[3][i]=tr.order_of_key(p[i].second);
		c[2][i]=C-c[3][i];
		tr.insert(p[i].second);
	}
	ll ans=0;
	rep(i,n){
		ll U=ppow(2,n-1);
		rep(j,4){
			(U+=MOD-ppow(2,n-1-c[j][i]-c[(j+1)%4][i]))%=MOD;
			(U+=ppow(2,c[j][i]))%=MOD;
		}
		(U+=MOD-1)%=MOD;
		(ans+=ppow(2,n-1)+U)%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 18284
#include<iostream>
#include<vector>
#include<string>

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

using namespace std;

int main(){
  int N; string S;
  cin>>N>>S;
  int count=0;
  while(S.find("ABC")!=string::npos){
    S.erase( S.find("ABC"),3 );
    count ++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int deg[5];
main(){
    for (int i=0; i<6; i++){
        int a; cin >> a;
        deg[a]++;
    }
    bool ok = 1;
    for (int i=0; i<6; i++){
        if (deg[i]>=3) ok = 0;
    }
    if (ok) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
a,b,k = map(int,input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
    
al = make_divisors(a)
bl = make_divisors(b)

abl = sorted(list(set(al) & set(bl)), reverse=True)
print(abl[k-1])

Measured memory_bytes: 38640
#include <cstdio>


int W, H;
char Maps[120][120];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
void dfs(int x, int y);
int ans;

int main(void) {
    while (scanf("%d %d\n", &H, &W)!=EOF) {
        if (H*W==0) break;
        
        for (int i = 0; i<H; i++) {
            for (int j = 0; j<W; j++)
                scanf("%c", &Maps[i][j]);
            getchar();
        }
        
        for (int i = 0; i<H; i++)
            for (int j = 0; j<W; j++)
                if (Maps[i][j]!=' ') {
                    dfs(i, j);
                    ans++;
                }
        
        printf("%d\n", ans);
        ans = 0;
    }
    return 0;
}

void dfs(int x, int y) {
    char tmp = Maps[x][y];
    Maps[x][y] = ' ';
    for (int i = 0; i<4; i++) {
        int nx = x+dx[i], ny = y+dy[i];
        if (nx>=0 && nx<H && ny>=0 && ny<W && Maps[nx][ny]==tmp) dfs(nx, ny);
    }
}

Measured memory_bytes: 1516
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int main() {
    int N;
    cin >> N;
    vector<double> p(N);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
    }
    vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));
    dp[0][0] = 1.0;
    for (int i = 1; i <= N; ++i) {
        dp[i][0] = (1.0 - p[i - 1]) * dp[i - 1][0];
        for (int j = 1; j <= N; ++j) {
            dp[i][j] = p[i - 1] * dp[i - 1][j - 1] + (1.0 - p[i - 1]) * dp[i - 1][j];
        }
    }
    double ret = 0.0;
    for (int i = N / 2 + 1; i <= N; ++i) {
        ret += dp[N][i];
    }
    cout << fixed << setprecision(10) << ret << endl;
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  cout << S.at(0) << S.at(1) << S.at(2) << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n), pg(n), sg(n);
    for(int i = 0; i < n; ++i)cin >> a[i];
    pg[0] = a[0];
    sg[n-1] = a[n-1];
    for(int i = 1; i < n; ++i)pg[i] = __gcd(pg[i-1], a[i]);
    for(int i = n-2; i>=0; --i)sg[i] = __gcd(sg[i+1], a[i]);
    int x = 1;
    for(int i = 0; i <n; ++i){
        if(i == 0){
            x = max(x, sg[1]);
        }
        else if(i == n-1){
            x = max(x, pg[n-2]);
        }
        else {
            x = max(x, __gcd(sg[i+1], pg[i-1]));
        }
    }
    
    cout << x << '\n';
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
  #define N 50000005
  #define INF 1000000000000
  #define eps 1e-6


  int32_t main()
  {         


    IOS

    int h,a;
    cin >> h >> a;

    int ans = h/a;
    if(h%a !=0)
    {
      ans++;
    }

    cout << ans;

    return 0; 
}

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

int main(){
  int n;
  cin>>n;
  ll vec[n][3];
  ll zero=0;
  for(int i=0;i<n;i++){
    cin>>vec[i][0]>>vec[i][1]>>vec[i][2];
  }
  for(ll x=0;x<=100;x++){
    for(ll y=0;y<=100;y++){
      for(int z=0;z<n;z++){
        ll h=vec[z][2]+abs(vec[z][0]-x)+abs(vec[z][1]-y);
        int t=0;
        for(int i=0;i<n;i++){
          if(i==z){
            continue;
          }
          if(max(h-abs(x-vec[i][0])-abs(y-vec[i][1]),zero)!=vec[i][2]){
            t++;
          }
        }
        if(t==0){
          if(h>0){
            cout<<x<<" "<<y<<" "<<h<<endl;
            return 0;
          }
        }
      }
    }
  }
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <queue>

#define rep(i,n) for (int i=0; i < (n); ++i)
using ll = long long ;
using namespace std;
const int INF = 1001001001;

int main() {

    int n ;
    cin >> n ;
    if(n==0)
        cout << 1 << endl ;
    else
        cout << 0 << endl ;

    return 0 ;
}

Measured memory_bytes: 3632
#include <stdio.h>
int len1,len2,len3;
int main(){
    char A[15],B[15],C[15];
    scanf("%s",A);
    len1=strlen(A);
    getchar();
    scanf("%s",B);
    len2=strlen(B);
    getchar();
    scanf("%s",C);
    len3=strlen(C);
    if(A[len1-1]==B[0]&&B[len2-1]==C[0]){
        printf("YES");
    }
    else printf("NO");
    return 0;
}

Measured memory_bytes: 128
#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;

int main()
{
	int x;
	cin >> x;
	cout << (x+1) % 2 << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int num[200005],a[200005],b[200005];
int main()
{
    int n,m,biao;
    while(scanf("%d%d",&n,&m)==2)
    {
        biao=0;
        memset(num,0,sizeof(num));
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            if(a[i]==1)
            {
                num[b[i]]++;
            }
            if(b[i]==n)
            {
                num[a[i]]++;
            }
        }
        //printf("000");
        for(int i=2;i<n;i++)
        {
            if(num[i]>=2)
            {
                printf("POSSIBLE\n");
                biao=1;
                break;
            }
        }
        if(biao==1)continue;
        printf("IMPOSSIBLE\n");
    }
}


Measured memory_bytes: 2560
#include <stdio.h>

int main() {
	int a,b;
	scanf("%d %d",&a, &b);
	if(a > b && b != 1 || a == 1 && a != b) {
		printf("Alice\n");	
	} else if(a < b && a != 1 || b == 1 && a != b) {
		printf("Bob\n");
	} else if(a == b) {
		printf("Draw\n");
	}  
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define M 2010
#define LL long long
#define MOD 1000000007
#define rep(i, x, y) for(int i = (x); i <= (y); i ++)
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	} while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	} return x * f;
}
int f[M][M];
int fac[M*M], inv[M*M];
inline void init(int n) {
	fac[0] = 1;
	rep(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % MOD;
	inv[0] = inv[1] = 1;
	rep(i, 2, n) inv[i] = 1ll * inv[MOD % i] * (MOD - MOD / i) % MOD;
	rep(i, 1, n) inv[i] = 1ll * inv[i - 1] * inv[i] % MOD;
}
inline int C(int n, int m) {
//	if(n < 0 || m < 0) return 1;
	return 1ll * fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
int main() {
	int n = read(), k = read();
	if(k == 1) return puts("1"), 0;
	f[0][0] = 1; init(n*k);
	rep(i, 1, n) {
		for(int j = i; j >= 0; j --) {
			f[i][j] = f[i][j + 1];
			if(j) (f[i][j] += 1ll * f[i - 1][j - 1] * C(i*k-j-1,k-2) % MOD) %= MOD;
		}
	} printf("%d\n", 1ll * f[n][0] * fac[n] % MOD);
	return 0;
}



Measured memory_bytes: 47488
N, Q = map(int, input().split())
s = str(input())

t = []
d = []

for _ in range(Q):
    ti, di = input().split()
    t.append(ti)
    d.append(di)
    
LEFT_DIE = -1
RIGHT_DIE = N

def is_dead(i):
    for ti, di in zip(t, d):
        if s[i] == ti:
            if di == 'L':
                i -= 1
            if di == 'R':
                i += 1
            if i == LEFT_DIE:
                return LEFT_DIE
            if i == RIGHT_DIE:
                return RIGHT_DIE
    return 0

low = -1
high = N;
# LEFT
while high - low > 1:
    mid = (low + high) // 2;
    if is_dead(mid) == LEFT_DIE:
        low = mid
    else:
        high = mid
left_edge = high

low = -1
high = N;
# RIGHT
while high - low > 1:
    mid = (low + high) // 2;
    if is_dead(mid) == RIGHT_DIE:
        high = mid
    else:
        low = mid
right_edge = low

#print(left_edge, right_edge)
ans_s = s[left_edge:right_edge+1]
#print(ans_s)
ans = len(ans_s)
print(ans)

        
        
        
        
        
        

Measured memory_bytes: 6736
#include <stdio.h>

typedef long long ll;

int main(void)
{
	ll n, k, i, ans = 0;

	scanf("%lld %lld", &n, &k);

	for (i = k; i <= n + 1; i++)
	{
		ll add = (n * (n + 1) / 2 - (n - i) * (n - i + 1) / 2) - (i - 1) * i / 2 + 1;
		ans = (ans + add) % 1000000007;
	}

	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;


int main(){
    int a, b;
    cin >> a >> b;
    if(a * b % 2 == 0){
        cout << "Even";
    }else{
        cout << "Odd";
    }
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, '%s', $string);
fscanf(STDIN, '%d', $n);

$chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);

for ($i = 0; $i < $n; $i++) {
    $line = trim(fgets(STDIN));

    $ops = preg_split('/ /', $line);

    if ('replace' === $ops[0]) {
        $chars = replace($chars, $ops[1], $ops[2], $ops[3]);
    }

    if ('reverse' === $ops[0]) {
        $chars = reverse($chars, $ops[1], $ops[2]);
    }

    if ('print' === $ops[0]) {
        print_chars($chars, $ops[1], $ops[2]);
    }
}

function replace($chars, $from, $to, $replace)
{
    if (is_array($replace)) {
        $replaces = $replace;
    }
    else {
        $replaces = preg_split('//', $replace, -1, PREG_SPLIT_NO_EMPTY);
    }

    for ($i = $from, $j =0; $i <= $to; $i++, $j++) {
        $chars[$i] = $replaces[$j];
    }

    return $chars;
}

function reverse($chars, $from, $to)
{
    $reverse_chars = array();
    for ($i = $from; $i <= $to; $i++) {
        $reverse_chars[] = $chars[$i];
    }
    $reverse_chars = reverse_all($reverse_chars);

    return replace($chars, $from, $to, $reverse_chars);
}

function reverse_all($chars)
{
    $reversed = array();

    for ($i = count($chars) - 1; $i >= 0; $i--) {
        $reversed[] = $chars[$i];
    }

    return $reversed;
}

function print_chars($chars, $from, $to)
{
    for ($i = $from; $i <= $to; $i++) {
        echo $chars[$i];
    }
    echo "\n";
}

Measured memory_bytes: 7184
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  vector<vector<ll>> a(3, vector<ll>(3));
  loop(i,3)loop(j,3)cin>>a[i][j];
  ll n;
  cin>>n;
  vec d(n);
  loop(i,n)cin>>d[i];
  vector<vector<bool>> check(3, vector<bool>(3));
  loop(i,3)loop(j,3)check[i][j]=false;
  loop(i,n){
    ll num=d[i];
    loop(j,3){
      loop(k,3){
        if(a[j][k]==num)check[j][k]=true;
      }
    }
  }
  bool ans=false;
  if(check[0][0]&&check[1][0]&&check[2][0])ans=true;
  if(check[0][1]&&check[1][1]&&check[2][1])ans=true;
  if(check[0][2]&&check[1][2]&&check[2][2])ans=true;
  if(check[0][0]&&check[0][1]&&check[0][2])ans=true;
  if(check[1][0]&&check[1][1]&&check[1][2])ans=true;
  if(check[2][0]&&check[2][1]&&check[2][2])ans=true;
  if(check[0][0]&&check[1][1]&&check[2][2])ans=true;
  if(check[2][0]&&check[1][1]&&check[0][2])ans=true;
  if(ans)putout("Yes");
  else putout("No");
  
  
  
}

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

using namespace std;

int main(){
	int n, h, ans = 0;
	cin >> n >> h;
	vector<pair<int, int>> a(n);
	int max_a = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i].first >> a[i].second;
		max_a = max(max_a, a[i].first);
	}
	sort(a.begin(), a.end(),
		[](auto& x, auto& y){return (x.second > y.second); });
	for(int i = 0; i < n; i++){
		if(h > 0 && a[i].second > max_a){
			h -= a[i].second;
			ans++;
		}else{
			break;
		}
	}
	h = max(h, 0);
	ans += (h + max_a - 1) / max_a;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

int main() {
  intmax_t A, B, C, K;
  std::cin >> A >> B >> C >> K;
  intmax_t mx = std::max({A, B, C});
  intmax_t ans = A + B + C - mx;
  ans += mx * std::pow(2, K);
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 512
w = input()
letterlist = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
numletter = []
for i in range(len(letterlist)) :
    numletter += [w.count(letterlist[i])]
i = 0
while i < len(numletter) :
    num = numletter[i]
    if num % 2 == 1 :
        print("No")
        break
    i += 1
else :
    print("Yes")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
long N,A[2<<17],ans;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	int i=0;
	while(i<N)
	{
		while(i+1<N&&A[i]+1==A[i+1])i++;
		if(A[i]>i||i+1<N&&A[i]+1<A[i+1])
		{
			cout<<-1<<endl;
			return 0;
		}
		ans+=A[i];
		i++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//


int32_t main()
{
    io;
    int n;
    cin>>n;
    int cnt = 0;
    for(int i = 1; i<=n; i++)
    {
        int x;
        cin>>x;
        cnt += ((x&1) && (i&1));
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;

int main() {
 string s;
  int q;
  cin>>s>>q;
  vector<tuple<int,int,char>> t(q);
  
  rep(i,q){
    int a;
   cin>>a;
  if(a==2){
      int b;
      char c;
      cin>>b>>c;
     t[i]=make_tuple(a,b,c);
    }
    else{
     t[i]=make_tuple(a,-1,'$'); 
    }
  }
  ///////////////
  int n=s.size();
  deque<char> ans;
  rep(i,n){
    ans.push_back(s[i]);
  }
  int hanntenn=0;
  rep(i,q){
   if(get<0>(t[i])==1){
     hanntenn++;
   }
   else{
     if(get<1>(t[i])==1&&hanntenn%2==0 ||get<1>(t[i])==2&&hanntenn%2==1 ){
      ans.push_front(get<2>(t[i]));
     }
     else{
       ans.push_back(get<2>(t[i]));
     }
   }
    
  }
  if(hanntenn%2==1) reverse(all(ans));
  while(!ans.empty()){
  cout<<ans.front();
    ans.pop_front();
  }
  cout<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define MAX_AR 300

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

ll a1, a2, tot = 0;

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

    int n;
    cin >> n;
    ll t;
    for (int ctr1 = 0; ctr1 < n; ++ctr1) {
        cin >> t;
        if (ctr1 == 0)
            a1 = t;
        else if (ctr1 == 1)
            a2 = t;
        else tot ^= t;
    }

    ll s = a1 + a2;
    ll aib = (s - tot);
    if (aib & 1) {
        cout << "-1\n";
        return 0;
    }
    aib /= 2;
    if (aib < 0 || a1 < aib || (aib & tot)) {
        cout << "-1\n";
    } else {
        ll rez = aib;
        for (int ctr1 = 40; ctr1 >= 0; --ctr1) {
            if (tot & (1LL << ctr1)) {
                if ((rez | (1LL << ctr1)) <= a1)
                    rez |= (1LL << ctr1);
            }
        }
        if (rez == 0) {
            cout << "-1\n";
        } else {
            cout << a1 - rez << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
void swap(int *a,int *b){
  int work;
  work=*a;
  *a=*b;
  *b=work;
}

int gcd(a,b){
  int r;
  if(a<b)
    swap(&a,&b);
      while(b>0){
	r=a%b;
	a=b;
	b=r;
      }
  return a;
}

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  printf("%d\n",gcd(a,b));
  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <iomanip>
using namespace std;

typedef long long ll;

int main()
{
    ll N,K;
    cin >> N >> K;
    vector<ll> p(N);
    for(int i=0; i<N; i++){
        cin >> p[i];
        p[i]++;
    }
    ll ans=0;
    for(int i=0; i<K; i++){
        ans+=p[i];
    }
    ll now=ans;
    for(int i=0; i<N-K; i++){
        now-=p[i];
        now+=p[i+K];
        if(ans<now) ans=now;
    }
    double out=ans/2.0;
    cout << setprecision(10)<< out << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;

int main(){
  string s,t;
  for(cin>>s;cin>>s;cout<<atoi(s.c_str())-atoi(t.c_str())<<endl)
    t=s,sort(t.begin(),t.end()),sort(s.begin(),s.end(),greater<int>());
}

Measured memory_bytes: 0
/*
                    author         : TAPAN SAVANI 
                    codeforces     : savanitapan2001
                    codechef       : savanitapan17
*/

/*
------------------------------------------------------------------------

░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░
 
------------------------------------------------------------------------
*/

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

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

int main()
{
    HAPPY_CODING;

    int n;
    cin >> n;

    int a[n][3], dp[n][3];

    FOR(i, 0, n)
    FOR(j, 0, 3)
    cin >> a[i][j];

    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    FOR(i, 1, n)
    FOR(j, 0, 3)
    {
        if (j == 0)
            dp[i][j] = a[i][j] + max(dp[i - 1][1], dp[i - 1][2]);

        else if (j == 1)
            dp[i][j] = a[i][j] + max(dp[i - 1][0], dp[i - 1][2]);

        else
            dp[i][j] = a[i][j] + max(dp[i - 1][0], dp[i - 1][1]);
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n";

    return 0;
}


Measured memory_bytes: 5984
#include <bits/stdc++.h>
#include <inttypes.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;
 
template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}
 
struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int n; scan(n);
      puts(n / 10 == 9 or n % 10 == 9 ? "Yes" : "No");
   }
};
 
int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}
 

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
ll mod=pow(10,9)+7;
mat G(100010);
vec black(100010),white(100010);
void DFS(int s,int p){
    ll W=1,B=1;
    for(auto t:G[s]){
        if(t==p) continue;
        DFS(t,s);
        W=(W*(white[t]+black[t])%mod)%mod;
        B=(B*white[t])%mod;
    }
    black[s]=B;white[s]=W;
    return;
}

int main(){
    int N;scanf("%d",&N);
    for(int i=0;i<N-1;i++){
        int x,y; scanf("%d %d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    DFS(1,0);
    cout<<(white[1]+black[1])%mod<<endl;
    return 0;
}

Measured memory_bytes: 14208
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
int n;
int vis[40010],id[100010],depth[100010*2],vs[100010*2];ll ans[100010];
int dp[100010*2][30];
struct node1
{
    int b,c;
};
vector<node1> vec[100010],node[100010];
void rmq_init(int len)
{
    for(int i=0; i<=len; i++)
        dp[i][0]=i;
    for(int j=1; (1<<j)<=len; j++)
        for(int i=1; i+(1<<j)-1<=len; i++)
        {
            int a=dp[i][j-1],b=dp[i+(1<<(j-1))][j-1];
            dp[i][j]=depth[a]<depth[b]?a:b;
        }
}
int rmq(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)
        k++;
    int a=dp[l][k],b=dp[r-(1<<k)+1][k];
    return depth[a]<depth[b]?a:b;
}
int lca(int u,int v)
{
    int x=id[u];
    int y=id[v];
    if(x>y)
        swap(x,y);
    return vs[rmq(x,y)];
}
void dfs(int v,int p,int d,int &k)
{
    id[v]=k;
    vs[k]=v;
    depth[k++]=d;
    for(int i=0; i<vec[v].size(); i++)
    {
        node1 pp=vec[v][i];
        if(pp.b!=p)
        {
            ans[pp.b]=ans[v]+pp.c;
            dfs(pp.b,v,d+1,k);
            vs[k]=v;
            depth[k++]=d;
        }
    }
}
void init(int x)
{
    int k=0;
    dfs(x,-1,0,k);
    rmq_init(n*2-1);
}
int main()
{
        memset(ans,0,sizeof(ans));
        int nn;
        scanf("%d",&n);
        nn=n-1;
        int a,b,c;
        while(nn--)
        {
            scanf("%d%d%d",&a,&b,&c);
            node1 p1,p2;
            p1.b=b,p1.c=c;
            p2.b=a,p2.c=c;
            vec[a].push_back(p1);
            vec[b].push_back(p2);
            vis[b]=1;
        }
        int q,keep;
        scanf("%d%d",&q,&keep);
        ans[keep]=0;
        init(keep);
        for(int i=0; i<q; i++)
        {
            scanf("%d%d",&a,&b);
            int v=lca(a,b);
            if(v==keep)
                printf("%lld\n",ans[a]+ans[b]-2*ans[v]);
            else
                printf("%lld\n",ans[a]+ans[b]);
        }
    return 0;
}


Measured memory_bytes: 43776
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = (list(map(int, input().split())) for _ in range(n))
ans = 0
for aa in a:
  if sum(x * y for x, y in zip(aa, b)) + c > 0:
    ans += 1
print(ans)


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

template<typename T>
class CumulativeSum{
public:
  int n;
  vector<T> sum;
  vector<T> A;
  int added;
  CumulativeSum():n(-1),added(0){}
  CumulativeSum(int n):n(n), sum(n+1), A(n+1),added(0){}
  CumulativeSum(const vector<T> &B):n(B.size()), sum(n+1), A(n+1),added(0){
    for(int i=1;i<=n;i++) sum[i] = sum[i-1] + B[i-1];
  }

  void apply(){
    for(int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(int i=1;i<=n;i++) sum[i] = sum[i] + A[i-1];
    added = 0; A.clear(); A.resize(n+1);
  }

  //[l, r)にxを加算
  void add(int l, int r, T x){
    added = 1;
    assert(l <= r && 0 <= l && r <= n);
    A[l] = A[l] + x;
    A[r] = A[r] - x;
  }

  //[l, r)の和を得る
  T get(int l,int r){
    assert(l<=r && 0<=l && r<=n);
    if(added) apply();
    return sum[r] - sum[l];
  }
};


signed main(){
  
  int N;
  string S;
  
  cin>>N>>S;
  
  CumulativeSum<int> C[3];
  
  for(int i=0;i<3;i++) C[i] = CumulativeSum<int>( N );
  
  int ctoi[300];
  ctoi['R'] = 0;
  ctoi['G'] = 1;
  ctoi['B'] = 2;
  
  for(int i=0;i<N;i++){
    C[ctoi[S[i]]].add(i,i+1,1);
  }
  
  for(int i=0;i<3;i++) C[i].apply();
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      
      if( S[i] == S[j] ) continue;
      
      int Sk;
      
      for(int k=0;k<3;k++){
	if( ctoi[S[i]] != k && ctoi[S[j]] != k ) Sk = k;
      }
      
      int add = C[Sk].get( j+1, N );
      
      int k = j + ( j - i );
      
      if( k < N && ctoi[S[k]] == Sk ) add--;

      ans += add;
      
    }
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3704