akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO 1e18
#define EPS 1e-6
#define Endl '\n'
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=100005;

int main()
{
    IO;
    ld a,b;
    cin >> a >> b;
    cout<<FX(10)<<a/b<<endl;
    re 0;
}

Measured memory_bytes: 256
N = int(input())
*L, = map(int, input().split())
L.sort()
count = 0
for a in reversed(range(0, N)):
  for b in range(1, a):
    range_c = L[:b]
    key = L[a] - L[b]
    left = -1
    right = len(range_c)
    while right - left > 1:
      mid = int((left + right) / 2)
      if range_c[mid] > key:
        right = mid
      else:
        left = mid
    count += len(range_c)-right
print(count)

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

int const MOD = 1e9+5;

#define  pi acos(-1.00)
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define newLine printf("\n")
#define start_p int main()
#define end_p return 0
#define test_IO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<char> vc;


start_p{
    #ifndef ONLINE_JUDGE
    //test_IO;
    #endif // ONLINE_JUDGE
    ll n; cin>>n;
    map<ll, ll> m;
    for(int i = 1; i<n; i++)
    {
        ll t; cin>>t;
        m[t]++;
    }
    for(int i = 1; i<= n; i++)
        cout<<m[i]<<endl;


    end_p;
}



Measured memory_bytes: 16140
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
double P[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	
	for(i=1;i<=max(N,K);i++) {
		x=i;
		P[i]=1;
		while(x<K) x*=2, P[i]*=0.5;
	}
	
	double ret=0;
	for(i=1;i<=N;i++) ret+=P[i];
	_P("%.12lf\n",ret/N);
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main() {
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<set<int>> is(26);
  rep(i, n) is[s[i] - 'a'].insert(i);
  rep(qi, q) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      --i;
      is[s[i] - 'a'].erase(i);
      s[i] = c;
      is[s[i] - 'a'].insert(i);
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      int ans = 0;
      rep(i, 26) {
        auto it = is[i].lower_bound(l);
        if (it != is[i].end() && *it < r) ++ans;
      }
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 24196
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define _rep(i,ra,re) for((i)=ra;(i)>(re);(i)--)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define _rep_(i,ra,re) for((i)=ra;(i)>=(re);(i)--)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define pu(n) cout << n;
#define mod 1000000007
int i,j,k,l;
static const int MAX_N=10e5;

int main(void){
	int K,X;
		cin >> K >> X;
	swap(K,X);
	rep_(i,max(K-X+1,-1000000),K){
		put(i);
	}rep_(i,K+1,min(K+X-1,1000000)){
		put(i);
	}puts("");
	return 0;
}


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

int main() {

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    long long int ue = 10000000000;
    long long int shita = -10000000000;

    bool f = true;

    long long int b;
    long long int k = 10000000000;

    for ( long long int i = 0; i < n; i++ ) {

      string in;
      cin >> in;

      if ( in != "x" ) {
	k = 0;
	for ( long long int j = 0; j < in.size(); j++ ) {
	  if ( in[j] == '-' ) continue;
	  k = k * 10 + in[j] - '0';
	}
	if ( in[0] == '-' ) k = -k;
	if ( i > 0 ) {
	  if ( b == 10000000000 ) {
	    if ( ( i % 2 ) == 0 ) {
	      shita = max( shita, k + 1 );
	    }else {
	      ue = min( ue, k - 1 );
	    }
	  }else {
	    if ( ( i % 2 ) == 0 ) {
	      if ( b <= k ) f = false;
	    }else {
	      if ( b >= k ) f = false;
	    }
	  }
	}
      }else {
	k = 10000000000;
	if ( i > 0 ) {
	  if ( b == 10000000000 ) {
	    f = false;
	  }else {
	    if ( ( i % 2 ) == 0 ) {
	      ue = min( ue, b - 1 );
	    }else {
	      shita = max( shita, b + 1 );
	    }
	  }
	}
      }

      b = k;

    }

    if ( f == false || ue < shita ) {
      cout << "none" << endl;
    }else if ( ue == shita ) {
      cout << ue << endl;
    }else {
      cout << "ambiguous" << endl;
    }

  }

  return 0;

}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,K;cin>>n>>K;
    vector<ll> x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    ll ans = 4*INF;
    rep(i,n)rep(j,n)rep(k,n)rep(l,n){
        ll lx=x[i],rx=x[j],ly=y[k],ry=y[l];
        if(lx>rx||ly>ry)continue;
        int cnt = 0;
        for(int m=0; m<n&&cnt<K; m++){
            if(lx<=x[m]&&x[m]<=rx&&ly<=y[m]&&y[m]<=ry)cnt++;
        }
        if(cnt==K)ans=min(ans,(lx-rx)*(ly-ry));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>

std::vector<int> G;
long long cnt = 0;

void insert_sort(int A[], int N, int g) {
    for (int i = g; i<N;i++){
        int j=i-g;
        int key=A[i];
        while (j>=0 && A[j] > key) {
            A[j+g]=A[j];
            j-=g;
            cnt++;
        }
        A[j+g]=key;
    }
}

void shell_sort(int A[], int N) {
    for (int i=G.size()-1;i>=0;i--) {
        insert_sort(A, N, G[i]);
    }
} 

int main() {
    int N, A[1000000+1];
    scanf("%d", &N);
    for(int i=0;i<N;i++) {
        scanf("%d", &A[i]);
    }
    int g=1;
    while(g<=N) {
        G.push_back(g);
        g=5*g+2;
    }
    printf("%ld\n", G.size());
    for(int i=G.size()-1;i>=0;i--){
        printf("%d%c", G[i], i==0?'\n':' ');
    }
    shell_sort(A,N);
    printf("%lld\n", cnt);
    for(int i=0;i<N;i++) {
        printf("%d\n",A[i]);
    }
    return 0;
}



Measured memory_bytes: 6560
#include <stdio.h>
#include <math.h>

double z(double x) {
	int p = (int)(x*1000), q = (int)(x*10000)%10;
	if(q>=5) {
		return (p+1) / 1000.;
	}else {
		return p / 1000.;
	}
}
int main() {
double a,b,c,d,e,f;
while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)==6){
printf("%.3f %.3f\n", z((c*e-b*f)/(a*e-b*d)), z((c*d-a*f)/(b*d-a*e)));
}
return 0;
}

Measured memory_bytes: 652
using System;
using System.Collections.Generic;
using System.Linq;


class Program
{
    static void Main(string[] args)
    {
        var md = Console.ReadLine().Split(' ');
        var m = int.Parse(md[0]);
        var d = int.Parse(md[1]);

        var count = 0;
        for (var i = 1; i <= m; i++)
        {
            for (var j = 22; j <= d; j++)
            {
                var tmp = j.ToString().ToCharArray();
                var d1 = int.Parse(tmp[0].ToString());
                var d2 = int.Parse(tmp[1].ToString());
                if (d1 < 2 || d2 < 2) continue;
                if (d1 * d2 == i) count++;
            }
        }

        Console.Write(count);
    }
}

Measured memory_bytes: 13140
import kotlin.math.*

fun str() = readLine()!!
fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

typealias Num = Int

fun binarySearch(ok:Num,ng:Num,eps:Num,f:(Num)->Boolean):Num {
	var _ok = ok
	var _ng = ng
	while(abs(_ok-_ng)>eps) {
		val mid = (_ok+_ng)/2
		if(f(mid))
			_ok = mid
		else
			_ng = mid
	}
	return _ok
}

fun main() {
	val (n,k) = list()
	val a = list()
	println(binarySearch(1000000000,0,1) {l->
		a.map {(it+l-1)/l-1}.sum()<=k
	})
}


Measured memory_bytes: 72420
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>
#include <cfloat>
#include <array>

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int to_int(char c) {
	if (c == 'R') return 0;
	else if (c == 'G') return 1;
	else return 2;
}
int main() {
	int n; std::cin >> n;
	std::string str; std::cin >> str;
	std::vector<std::vector<int>> count(3, std::vector<int>(n, 0));
	for (auto i = 0; i < str.size(); ++i) {
		const auto c = str[i];
		count[to_int(c)][i]++;
		if (i > 0) {
			for (auto j = 0; j < 3; ++j) {
				count[j][i] += count[j][i - 1];
			}
		}
	}
	long long int result{ 0 };
	for (auto i = 1; i < str.size(); ++i) {
		for (auto j = i + 1; j < str.size(); ++j) {
			if (str[i] == str[j]) continue;
			const auto a = to_int(str[i]);
			const auto b = to_int(str[j]);
			const auto c = 3 - a - b;
			result += count[c][i - 1];
			const auto diff = j - i;
			if (i - diff >= 0 && to_int(str[i - diff]) == c) {
				--result;
			}
		}
	}
	std::cout << result << std::endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<P> xs(n);
    for (int i = 0; i < n; i++) {
        int x, l;
        cin >> x >> l;
        xs[i] = P(x + l, x - l);
    }
    sort(xs.begin(), xs.end());
    int ans = 1;
    int end = xs[0].first;
    for (int i = 1; i < xs.size(); i++) {
        if (end <= xs[i].second) {
            end = xs[i].first;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#define N 100000
using namespace std;
int main(){
  int n,k,in[N],maxv,sum,i;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    maxv=-2000000;
    sum=0;
    for(i=0;i<n;i++){
      cin >> in[i];
      sum+=in[i];
      if(i>=k){
	sum-=in[i-k];
      }
      if(i>=k-1) maxv=max(maxv,sum);
    }
    cout << maxv << endl;
  }
  return 0;
}

Measured memory_bytes: 1548
from collections import deque


def is_all_nodes_connected():
    q = deque()
    used = set()
    q.append(1)
    used.add(1)
    while len(q) > 0:
        prv_node = q.pop()
        for node in g[prv_node]:
            if node in used:
                continue
            else:
                q.append(node)
                used.add(node)
    if len(used) == N:
        return True
    else:
        return False


N, M = map(int, input().split())
g = {i: [] for i in range(1, N+1)}
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)
    AB.append([a, b])

ans = 0
for a, b in AB:
    g[a].remove(b)
    g[b].remove(a)
    if is_all_nodes_connected() is False:
        ans += 1
    g[a].append(b)
    g[b].append(a)

print(ans)


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

int main(){
    ll n;
    cin >> n;
    pair<ll,P> p[n];
    rep(i,0,n){
        cin >> p[i].sc.fs >> p[i].sc.sc >> p[i].fs;
    }
    sort(p,p+n,greater<pair<ll,P>>());

    rep(x,0,101){
        rep(y,0,101){
            ll h = p[0].fs + abs(x-p[0].sc.fs)+abs(y-p[0].sc.sc);
            bool flag = true;
            rep(i,1,n){
                if((ll)max(h-(ll)abs(x-p[i].sc.fs)-(ll)abs(y-p[i].sc.sc),0LL) != p[i].fs){
                    flag = false;
                    break;
                }
            }
            if(flag){
                cout << x << " " << y << " " << h << endl;
                return 0;
            }
        }
    }
    return 0;
}



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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int k; cin >> k;

  int even = k/2;
  int odd = (k+1)/2;
  int ans = even*odd;

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


Measured memory_bytes: 3588
let rec div2 = function 0 -> 0 | n -> if n mod 2 <> 0 then 0 else 1 + div2 (n / 2)

let () = Scanf.scanf "%d\n" @@ fun n ->
  Array.init n (fun _ -> Scanf.scanf "%d " div2)
  |> Array.fold_left min max_int
  |> Printf.printf "%d\n"

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main() {
  long long x, k, d;
  cin >> x >> k >> d;
  if (x < 0) x = -x;
  if (k <= x / d) {
    cout << x - d * k << endl;
  } else {
    k -= x / d;
    x %= d;
    if (k % 2 == 0) {
      cout << x << endl;
    } else {
      cout << d - x << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n, k;
	int x[100];
	int ans = 0;
	cin >> n >> k;
	rep(i, n) {
		cin >> x[i];
		if (x[i] * 2 <= (k - x[i]) * 2) ans += x[i] * 2;
		else ans += (k - x[i]) * 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    rep(i, K) {
        if (i % 2 == 0) {
            if (A % 2 == 1) A -= 1;
            B += A / 2;
            A /= 2;
        } else {
            if (B % 2 == 1) B -= 1;
            A += B / 2;
            B /= 2;
        }
    }
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <tuple>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end())
            cout << " ";
    }
    cout << endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    rep(i, 0, N) {
        int v = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        vecout(A);
    }
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string ans="APPROVED";
  int N; cin>>N;
  rep(i,0,N){
    int A; cin>>A;
    if(A%2==0&&A%3!=0&&A%5!=0){
      ans="DENIED";
      break;
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
R = N - K

C = [1, 1]
2.upto(N) { |i| C[i] = (C[i-1] * i) }

def comb(n, k)
  C[n] / (C[k] * C[n-k])
end

1.upto(K) do |i|
  puts comb(R+1, i) * comb(K-1, i-1) % (10**9+7)
end

Measured memory_bytes: 9596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		in.close();
		int max = 1;
		int max1 = 1;
		for (int i = n; i > 1; i-- ) {
			int n_i = calc(i);
			if (max1 <= n_i) { 
				max = i;
				max1 = n_i;
			}
		}
		System.out.println(max);
		
	}
	public static int calc(int n) {
		if (n % 2 == 0) return 1 + calc(n / 2);
		else return 0;
	}
}

Measured memory_bytes: 21844
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n,num;
		HashMap<Integer,Integer> hm;
		int[] distance;
		
		while(true){
			n = sc.nextInt();
			if(n == 0){
				break;
			}
			
			distance = new int[n];
			hm = new HashMap<Integer,Integer>();
			for(int i=0;i<n;i++){
				num = sc.nextInt();
				distance[i] = sc.nextInt()+sc.nextInt();
				hm.put(distance[i],num);
			}
			Arrays.sort(distance);
			System.out.println(hm.get(distance[n-1])+" "+distance[n-1]);
		}
	}
}

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

bool solve();

int main()
{
	if (solve()) puts("Yes");
	else puts("No");

	return 0;
}

bool solve()
{
	int A[3];
	for (auto& e: A) scanf("%d", &e);
	std::sort(A, A + 3);
	if (A[0] != A[1] && A[1] != A[2]) return false;
	if (A[0] == A[2]) return false;
	return true;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    n: usize,
    k: usize,
    p: [f64; n],
    }
    let es = (0..n).map(|x| (p[x] + 1.0) / 2.0).collect::<Vec<f64>>();
    let (mut s, mut t) = (0, k);
    let mut total = es[0..k].iter().sum::<f64>();
    let mut ans = total.clone();
    while t < n {
        total= total - es[s] + es[t];
        ans = if ans > total {ans} else{total};
        s += 1;
        t += 1;
    }
    println!("{}", ans);
}


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

#define MAXN 10010
#define ll long long
#define mod 1000000007

using namespace std;

int n, m, k, tot, ans, sum;

int a[MAXN][MAXN];
int h[MAXN], l[MAXN];
int b[MAXN];
int s[MAXN];

int count(int sta) {
	memset(b, 0, sizeof(b));
	memset(s, 0, sizeof(s));
	int now = 1, res = 0;
	for (int i = 0; i < n; i++) {
		b[i + 1] = now;
		if ((sta >> i) & 1) ++now;
	}
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) s[b[j]] += a[j][i];
		bool f = 1;
		for (int j = 1; j <= n; j++)
			if (s[b[j]] > k) {
				res++;
				f = 0;
				break;
			}
		if (!f) {
			memset(s, 0, sizeof(s));
			for (int j = 1; j <= n; j++) {
				s[b[j]] += a[j][i];
				if (s[b[j]] > k) return n + m;
			}	
		}
	}
	return res;
}

int main() {
	int t, now = 0;
	scanf("%d%d%d", &n, &m, &k);
	ans = n + m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			char c;
			cin >> c;
			a[i][j] = c - '0';
//			sum += a[i][j];
//			s[i][j] = s[i][j - 1] + a[i][j];
		}
	}
	for (int i = 0; i < (1 << (n - 1)); i++) {
		int num = 0;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1) num++;
		}
		ans = min(ans, count(i) + num);
	} 
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int dx[] = { 0,1 };
int dy[] = { 1,0 };
int main() {
	init();

	int H, W; cin >> H >> W;
	vector<string>maze(H);
	rep(i, 0, H)cin >> maze[i];
	Graph dp(H, vector<int>(W, INF));
	dp[0][0] = 0;
	if (maze[0][0] == '#')dp[0][0]++;
	rep(i, 0, H) {
		rep(j, 0, W) {
			rep(k, 0, 2) {
				int nx = j + dx[k], ny = i + dy[k];
				if (out(ny, nx, H, W))continue;
				int sum = dp[i][j];
				if (maze[i][j] == '.' && maze[ny][nx] == '#')sum++;
				chmin(dp[ny][nx], sum);
			}
		}
	}
	cout << dp[H - 1][W - 1] << "\n";

	return 0;
}

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

using namespace std;
int main() {
 int N;
  cin >> N;
 
    int s = 0;
  
  for (int i = 0; i < N; i++) {
    int l,r;
    cin >> l;
    cin >> r;
    s += (r - l + 1);
  }
        cout << s << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
 
using namespace std;
 
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
 
const double PI=3.14159265358979323846;
 
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
 
#define rep(i, N) for(int i = 0; i < N; ++i)
 
#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL
 
#define IN(l, r, x) ((l) <= (x) && (x) < (r))
 
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    vs32 cnt(9, 0);
    int n;
    cin >> n;
    int a;
    rep (i, n)
    {
        cin >> a;
        if (a >= 3200)
        {
            ++cnt[8];
        }
        else
        {
            ++cnt[a / 400];
        }
    }
 
    int sum = 0;
    rep (i, 8)
    {
        if (cnt[i] > 0)
        {
            ++sum;
        }
    }
 
    int ansm = sum;
    int ansM = sum;
    ansM = ansM + cnt[8];
    ansm = MAX(1, ansm);
 
    cout << ansm << " " << ansM << "\n";
    return 0;
}

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

int main(){
    int X,N;
    cin >> X >> N;
    int p[N];
    int i,j;
    int s;
    for(i=0; i<N; i++){
        cin >> p[i];
    }
    int ans=0;
    bool out;
    if(N==0){
        cout << X << endl;
    }else{
        for(i=X; i>=0; i--){
            out=0;
            for(s=0; s<N; s++){
                if(i==p[s]){
                    out=1;
                }
            }
            if(out==1) continue;
            else break;
        }
        for(j=X; j<=101; j++){
            out=0;
            for(s=0; s<N; s++){
                if(j==p[s]){
                    out = 1;
                }
            }
            if(out==1) continue;
            else break;
        }
        if(X-i>j-X){
            cout << j << endl;
        }else{
            cout << i << endl;
        }
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
XYZが無いものをカウントする
あるものをカウントする場合、過去に１箇所でもあったら常に遷移しないといけなくて、状態数が増える
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

mint modpow(mint a, ll n) {
	mint r=1;
	while(n) r=r*((n%2)?a:1),a=a*a,n>>=1;
	return r;
}

ll n,x,y,z;
mint dp[65537],dp2[65537],ans=0;

void decode(ll s, V<ll> &v){
	v.clear();
	bool one=false;
	int num;
	irep(j,16){
		if(1 & s>>j){
			if(one)v.push_back(num);
			one=true;
			num=1;
		}else{
			if(one)num++;
		}
	}
	if(one)v.push_back(num);
}

void init(){
	cin>>n>>x>>y>>z;
	dp[0]=1;
}

int main(void){
	init();
	rep(i,n){
		rep(s,1<<16){
			V<ll> v;
			decode(s,v);
			reg(j,1,10){  // 先頭にjが入れてもXYZが出来なければOK
				bool ok[3]={};
				ll sum=j,r=v.size()-1;
				for(;sum<z && r>=0;r--)sum+=v[r];
				if(sum==z)ok[0]=true;
				for(;sum<z+y && r>=0;r--)sum+=v[r];
				if(sum==z+y && ok[0])ok[1]=true;
				for(;sum<z+y+x && r>=0;r--)sum+=v[r];
				if(sum==z+y+x && ok[1])ok[2]=true;
				if(!ok[2])dp2[(s<<j)%(1<<16) | 1<<(j-1)]+=dp[s];
			}
		}
		rep(s,1<<16){
			dp[s]=dp2[s];
			dp2[s]=0;
		}
	}
	rep(s,1<<16)ans+=dp[s];
	cout<<(modpow(10,n)-ans).get()<<endl;
	// {
	// 	V<ll> v;
	// 	decode(0,v);
	// 	rep(i,v.size())cerr<<v[i]<<endl;
	// }
	return 0;
}

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

typedef pair<int,string> P;

bool compare(P a,P b){
    return a.first > b.first;
}

int main(){
    int n,a,b,c,t=0;
    string str;
    
    while(cin >> n,n){
        if(t) puts("");
        t++;
        vector<P> v;
        for(int i = 0 ; i < n ; i++){
            cin >> str >> a >> b >> c;
            int p = a*3+c;
            v.push_back(P(p,str));
        }
        stable_sort(v.begin(),v.end(),compare);
        
        for(int i = 0 ; i < n ; i++){
            cout << v[i].second << "," << v[i].first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
vector<int> visited;
vector<int> siz;
vector<vector<int>> ed;
int dfs(int p,int u){
    if(visited[u]==2){
        return siz[u];
    }
    if(ed[u].size()==0){
        visited[u]=2;
        siz[u]=0;
        return 0;
    }
    visited[u]=1;
    int maxi=0;
    for(auto x:ed[u]){
       maxi=max(maxi,dfs(u,x));
    }
    visited[u]=2;
    maxi=maxi+1;
    siz[u]=maxi;
    return maxi;
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n+1,0);
    visited=a;
    siz=a;
    vector<vector<int>> e(n+1);
    for(int i=0;i<m;i++){
        int c,d;
        cin>>c>>d;
        e[c].push_back(d);
    }
    int ans=0;
    ed=e;
    for(int i=1;i<=n;i++){
        if(visited[i]==0){
            int l =dfs(-1,i);
            ans=max(l,ans);
        }
    }
   // for(int i=1;i<=n;i++)cout<<siz[i]<<endl;
    cout<<ans<<endl;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin >> n;
    vector<long>p;
    p.push_back(2);
    for(long i=3;i<=1000000;i+=2){
        bool chk = true;
        for(int j=0;j<p.size()&&p[j]*p[j]<=i;j++){
            if(i%p[j]==0){
                chk=false;
                break;
            }
        }
        if(chk)p.push_back(i);
    }
    int ans = 0;
    for(int i=0;i<p.size();i++){
        long tmp = p[i];
        int cnt = 0;
        while(n % tmp == 0){
            cnt++;
            n /= tmp;
            tmp *= p[i];
            
        }
        while(n%p[i]==0)n/=p[i];
        ans += cnt;
        
    }
    if(n > 1)ans++;
    cout << ans << endl;

}

Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

vector<ll> A{1,0,-1,0};
vector<ll> B{0,1,0,-1};
vector<ll> C{-2,-1,0,1,2};
vector<ll> D{-2,-1,0,1,2};

 
int main() {
ll H,W;
  cin>>H>>W;
  ll Ch,Cw,Dh,Dw;
  cin>>Ch>>Cw>>Dh>>Dw;
  Ch--;
  Cw--;
  Dh--;
  Dw--;
  vector<string> vec(H);
  for(ll i=0;i<H;i++) {
cin>>vec[i];
  }
  
 
  deque<tuple<ll,ll,ll>> S;
  S.push_front(make_tuple(Ch,Cw,1));
  vector<vector<ll>> dist(H,vector<ll>(W,0));
  
  
  while(!S.empty()) {
    ll nh,nw;
    nh=get<0>(S.front());
    nw=get<1>(S.front());
    ll d=get<2>(S.front());
    S.pop_front();
    if(dist[nh][nw]!=0) {
continue;
    }
    dist[nh][nw]=d;
    for(ll i=0;i<4;i++) {
   ll kh,kw;
      kh=nh+A[i];
      kw=nw+B[i];
      if(kh<0||kh>H-1||kw<0||kw>W-1) {
continue;
      }
      if(vec[kh][kw]=='#') {
continue;
      }
      S.push_front(make_tuple(kh,kw,d));
                   }
                   
         for(ll i=0;i<5;i++) {
for(ll j=0;j<5;j++) {
  if(abs(C[i])+abs(D[j])<2) {
continue;
  }
  ll kh,kw;
  kh=nh+C[i];
  kw=nw+D[j];
    if(kh<0||kh>H-1||kw<0||kw>W-1) {
continue;
      }
  if(vec[kh][kw]=='#') {
continue;
      }
  S.push_back(make_tuple(kh,kw,d+1));
              }
              }
              }
              
         
if(dist[Dh][Dw]==0) {
cout<<-1<<endl;
}
  else {
cout<<dist[Dh][Dw]-1<<endl;
  }
}
  

                   
                   
      
    

  
  
  

  
  
  


Measured memory_bytes: 15808
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces289B
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ll x, ll y, ll a, ll b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(ll* a, ll n) { for ( int k = 0; k < n; k++ ){ cout << a[k] << " ";} cerr << "\n"; }

int main(){
	FASTIO;
	ll n, m; cin >> n >> m;
	ll a[n]; parseArray(a, n);
	ll s = 0; for ( int k = 0; k < n; k++ ){ s += a[k]; }
	vector<ll> div;
	for ( int k = 1; k * k <= s; k++ ){
		if (s % k == 0){
			if (s / k != k) div.pb(s / k);
			div.pb(k);
		}
	}
	sort(div.begin(), div.end()); reverse(div.begin(), div.end());
	ll ans = 0;
	for (ll e : div) {
		ll temp[n];
		ans = 0;
		for ( int k = 0; k < n; k++ ){ temp[k] = a[k] % e; }
		sort(temp, temp + n);
		ll l = 0, r = n - 1;
		while (l < r) {
			ll x = min(e - temp[r], temp[l]);
			temp[r] += x;
			temp[l] -= x;
			ans += x;
			if (temp[l] % e == 0) l++;
			if (temp[r] % e == 0) r--;
		}
		if (ans <= m) {ans = e; break;}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn modpow(mut a: i64, n:usize, m: i64) -> i64 {
    let mut res:i64 = 1;
    let mut nn = n;
    while nn > 0 {
        if nn & 1 != 0 {
            res = res * a % m;
        }
        a = a * a % m;
        nn >>= 1;
    }
    res
}

fn main() {
    input!{
        n: usize,
        x: [i64;n],
    }
    let m:i64 = 1_000_000_007;
    // inverse mod
    let mut inv = vec![0;n+1];
    let mut inv_sum = vec![0;n+1];
    let mut fact:Vec<i64> = vec![0;n+1];
    fact[0] = 1;
    for i in 0..n {
        fact[i+1] = fact[i]*(i as i64 +1)%m;
    }
    inv[1] = modpow(1, n, m);
    inv_sum[1] = inv[1];
    for i in 2..n+1 {
        inv[i] = m - inv[(m as usize)%i] * (m/(i as i64)) % m;
        inv_sum[i] = inv_sum[i-1] + inv[i];
        inv_sum[i]%=m;
    }
    // println!("{:?}", inv_sum);
    let mut res:i64 = 0;
    for i in 1..n {
        res += ((x[i] - x[i-1])%m)*inv_sum[i]%m;
        res%=m;
    }
    println!("{}", res*fact[n-1]%m);
}

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

int main()
{
  string a, b;
  cin >> a >> b;

  if(a.size() > b.size()) cout << "GREATER" << endl;

  else if(a.size() < b.size()) cout << "LESS" << endl;

  else
    {
      if(a == b) cout << "EQUAL" << endl;
      if(a > b) cout << "GREATER" << endl;
      if(a < b) cout << "LESS" << endl;

    }

  return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

char s[3]={0};
int main()
{
	scanf("%s", &s);
	if (s[2] == 0) {
		printf("%s", s);
	}
	else {
		for (int i = 2; i >= 0; i--) {
			printf("%c", s[i]);
		}
	}
}

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

const int N = 2e5 + 5;

struct node { int x, y; };

int n, k, a[N];
node b[N];
std ::queue<int> q;

inline bool cmp(node x, node y) {
    if (x.x != y.x) return x.x < y.x;
    return x.y < y.y;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i) {
        a[i] = (a[i] - 1 + k) % k;
        b[i].x = (b[i - 1].x + a[i]) % k;
        b[i].y = i;
        //printf("%d %d\n", a[i], b[i].x);
    }
    std ::sort(b, b + 1 + n, cmp);
    long long ans = 0, cur = 1;
    q.push(0);
    for (int i = 1; i <= n; ++i) {
        if (b[i].x != b[i - 1].x) {
            ans += q.size() * (q.size() - 1) / 2;
            //printf("%d\n", q.size());
            while (!q.empty()) q.pop();
            q.push(b[i].y);
            continue;
        }
        while (!q.empty() && q.front() + k <= b[i].y) {
            //printf("!!!%d\n", q.size());
            ans += q.size() - 1;
            q.pop();
        }
        q.push(b[i].y);
    }
    ans += q.size() * (q.size() - 1) / 2;
    //printf("%d\n", q.size());
    printf("%lld\n", ans);   
    return 0;
}

Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var s = new string[N];
        for (int i = 0; i < N; i++)
        {
            s[i] = ReadLine();
        }
        var M = int.Parse(ReadLine());
        var t = new string[M];
        for (int i = 0; i < M; i++)
        {
            t[i] = ReadLine();
        }
        var rs = 0;
        foreach (var item in s)
        {
            var c = s.Count(x => x == item) - t.Count(x => x == item);
            if (c > rs) rs = c;
        }
        WriteLine(rs);
    }
}

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

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
using namespace std;


int main(){
	ll n; cin >> n;
	vl ap, am;
	for (ll i = 0; i < n; ++i){
		ll temp; cin >> temp;
		if (temp >= 0) ap.push_back(temp);
		else am.push_back(-temp);
	}

	sort(ap.begin(), ap.end());
	sort(am.begin(), am.end());
	ll ans = 0;
	for (ll i = 0; i < ap.size(); ++i) ans += ap[i];
	for (ll i = 0; i < am.size(); ++i) ans += am[i];
	if (am.size() % 2 == 0){
		cout << ans << endl;
	}
	else{
		if (ap.size()>0) ans -= 2 * min(ap[0], am[0]);
		else ans -= 2 * am[0];
		cout << ans << endl;
	}
	return 0;
}

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


#define TRACE

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

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	
	string s;cin>>s;
	int cnt = 0;
	vi pref(1,0);
	trav(i,s){
		if(i=='.') cnt++;
		pref.pb(cnt);
	}
	int ans = n;
	rep(i,n+1){
		ans = min(ans,(i-pref[i])+(cnt-pref[i]));
	}
	cout<<ans;
	
	return 0;
}



Measured memory_bytes: 1680
N = int(input())
W = [input() for i in range(N)]
Flag = True
for i in range(1,N):
    if W[i-1][-1] != W[i][0]:
        Flag = False
    for j in range(i):
        if W[j] == W[i]:
            Flag = False
if Flag == True:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
class UnionFind
  def initialize(n)
    @n = n
    @par = Array.new(@n)
    @chl = Hash.new{|h, k| h[k] = []}
    @par.map!.with_index{|x, i| @chl[i]; i}
  end
  def union(a, b)
    pa, pb = [@par[a], @par[b]]
    if pa < pb then
      absorb(a, b)
    elsif pa > pb then
      absorb(b, a)
    end
  end
  def same_group?
    @par.shift
    @par.uniq.size == 1
  end
  def show
    p @par
  end
  
  private
  
  def absorb(pa, ch)
    par = @par[pa]
    chl = @par[ch]
    @chl[chl].each{|c|
	      @chl[par] << c
      @par[c] = par
    }
    @chl.delete(chl)
    @chl[par] << chl
    @par[chl] = par
  end
end

N, M = gets.chomp.split(" ").map(&:to_i)
C = []
M.times{
  C << gets.chomp.split(" ").map(&:to_i)
}

ans = 0
(0...M).each{|i|
  uf = UnionFind.new(N+1)
  C.each_with_index{|(a, b), idx|
    next if idx == i
    uf.union(a, b)
  }
  ans += 1 if not uf.same_group?
}

puts ans


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int N, ans=0;
	int A[100005];

	cin >> N;
	rep(i,N) cin >> A[i+1];
	A[0] = 0;
	A[N+1] = 0;

	ll sum = 0;
	rep(i,N+1) sum += abs(A[i] - A[i+1]);

	rep(i,N){
		int a = abs(A[i]-A[i+1]) + abs(A[i+1]-A[i+2]);
		int b = abs(A[i]-A[i+2]);
		cout << sum + b - a << endl;
	}

	return 0;
}

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

int main() {
    int N, K;
    string s;
    while (cin >> N >> K >> s) {
        int m = static_cast<int>(s.length()), result = 0;
        for (int start = 0, stop = 0, k = 0; stop < m;) {
            char last = '1';
            while (stop < m) {
                if (s[stop] == '0' && last != '0') {
                    if (k == K) {
                        break;
                    }
                    ++k;
                }
                last = s[stop++];
            }
            result = max(result, stop - start);
            while (start < stop && s[start] == '1') {
                ++start;
            }
            last = '1';
            while (start < stop && s[start] == '0') {
                if (last == '1') {
                    --k;
                }
                last = s[start++];
            }
        }
        cout << result << endl;
    }
    return 0;
}


Measured memory_bytes: 512
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

BIG = 10**18
n = inn()
rx = []
udx = []
lx = []
uy =[]
rly = []
dy = []
for i in range(n):
    x,y,d = input().split()
    x = int(x)
    y = int(y)
    if d=='R':
        rx.append(x)
        rly.append(y)
    elif d=='L':
        lx.append(x)
        rly.append(y)
    elif d=='U':
        udx.append(x)
        uy.append(y)
    elif d=='D':
        udx.append(x)
        dy.append(y)

nor = (len(rx)==0)
nol = (len(lx)==0)
nou = (len(uy)==0)
nod = (len(dy)==0)
noud = nou and nod
norl = nor and nol

if not nor:
    rx.sort()
    rmax  = rx[-1]
    rmin  = rx[0]
if not nol:
    lx.sort()
    lmax  = lx[-1]
    lmin  = lx[0]
if not nou:
    uy.sort()
    umax  = uy[-1]
    umin  = uy[0]
if not nod:
    dy.sort()
    dmax  = dy[-1]
    dmin  = dy[0]
if not noud:
    udx.sort()
    udmax  = udx[-1]
    udmin  = udx[0]
if not norl:
    rly.sort()
    rlmax  = rly[-1]
    rlmin  = rly[0]

ddprint(rx)
ddprint(udx)
ddprint(lx)
#ddprint("max: r {} l {} u {} d {}".format(rmax,lmax,umax,dmax))
#ddprint("min: r {} l {} u {} d {}".format(rmin,lmin,umin,dmin))

def foo(t):
    ddprint("foo t: {}".format(t))
    xmax = -BIG
    if not nor:
        xmax = max(xmax, rmax+t)
    if not noud:
        xmax = max(xmax, udmax)
    if not nol:
        xmax = max(xmax, lmax-t)
    xmin = BIG
    if not nor:
        xmin = min(xmin, rmin+t)
    if not noud:
        xmin = min(xmin, udmin)
    if not nol:
        xmin = min(xmin, lmin-t)

    ymax = -BIG
    if not nou:
        ymax = max(ymax, umax+t)
    if not norl:
        ymax = max(ymax, rlmax)
    if not nod:
        ymax = max(ymax, dmax-t)
    ymin = BIG
    if not nou:
        ymin = min(ymin, umin+t)
    if not norl:
        ymin = min(ymin, rlmin)
    if not nod:
        ymin = min(ymin, dmin-t)

    z = abs((xmax-xmin)*(ymax-ymin))
    ddprint("xmax {} xmin {} ymax {} ymin {} rtn {}".format(xmax,xmin,ymax,ymin,z))
    return z

ts = [0]
if not noud:
    if not nor:
        ts.append(max(0,udmax-rmax))
        ts.append(max(0,udmin-rmin))
    if not nol:
        ts.append(max(0,lmax-udmax))
        ts.append(max(0,lmin-udmin))
if not nol and not nor:
        ts.append(max(0,(lmax-rmax)/2))
        ts.append(max(0,(lmin-rmin)/2))
if not norl:
    if not nou:
        ts.append(max(0,rlmax-umax))
        ts.append(max(0,rlmin-umin))
    if not nod:
        ts.append(max(0,dmax-rlmax))
        ts.append(max(0,dmin-rlmin))
if not nod and not nou:
        ts.append(max(0,(dmax-umax)/2))
        ts.append(max(0,(dmin-umin)/2))

ts = list(set(ts))
mn = BIG
for t in ts:
    mn = min(mn, foo(t))
print(mn)


Measured memory_bytes: 57304
N,M = map(int,input().split())
A = list(map(int,input().split()))

dp = [-1 for _ in range(10010)]
dp[0] = 0            

MatchNum = [0,2,5,5,4,5,6,3,7,6]

for i in range(1,10005):
    for x in A:          
        if i-MatchNum[x] >= 0:
            tmp = dp[i-MatchNum[x]]*10 + x
            dp[i] = max(tmp,dp[i])
print(dp[N])


Measured memory_bytes: 14828
#include<stdio.h>

int main(){
  int k,a,b,ans=0;
  int i;
  scanf("%d",&k);
  scanf("%d %d",&a,&b);

  for(i=a;i<=b;i++){
    if(i%k==0)
      ans++;
  }
  if(ans==0)
    printf("NG");
  else
    printf("OK");
}

Measured memory_bytes: 1736