akhauriyash/Code-Regression huggingface dataset:
N = int(input())

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


#奇数番目を負にする場合
odd = 0
total = 0
for i in range(N):
    total += A[i]
    if i % 2 == 0: #奇数番目の場合
        if total > -1:
            odd += 1 + total
            total = -1
    else:
        if total < 1:
            odd += 1 - total
            total = 1

#偶数番目を負にする場合
even = 0
total = 0
for i in range(N):
    total += A[i]
    if i % 2 == 0: #奇数番目の場合
        if total < 1:
            even += 1 - total
            total = 1
    else:
        if total > -1:
            even += 1 + total
            total = -1


print(min(odd, even))


Measured memory_bytes: 14468
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
 
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
 
template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
 
template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}
 
template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;
 
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}
 
	return true;
}
 
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
 
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)
 
 
int main() {
	ll N;
	std::cin >> N;
	ll s = 0;
	ll e = N - 1;
	string s1,s2;
	std::cout << 0 << endl;
	std::cin >> s1;
	if (s1 == "Vacant") {
		return 0;
	}
	ll idx = 0;
	while (true) {
		ll idx = (e - s+1) / 2+s;
		std::cout << idx << endl;
		std::cin >> s2;
		if (s2 == "Vacant") {
			return 0;
		}
		else if (((idx-s)&1&&s1!=s2)||(!((idx-s)&1)&& s1 == s2)) {
			s = idx;
			s1 = s2;
		}
		else {
			e = idx;
		}
	}
 
	return 0;
}

Measured memory_bytes: 852
// Problem A

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <cassert>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <stack>

#define MAXN 1000
#define pb push_back
#define mp make_pair

using namespace std;

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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
  
  return 0;
}


Measured memory_bytes: 3572
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        var s = Console.ReadLine().Trim();
        var R = getR(n, k, c, s);
        var L = getL(n, k, c, s, R);
    }
    static int[] getR(int n, int k, int c, string s)
    {
        var a = new int[k + 1];
        var p = n - 1;
        var kc = k;
        while (p >= 0 && kc >= 1)
        {
            if (s[p] == 'o')
            {
                a[kc--] = p + 1;
                p -= c + 1;
            }
            else p--;
        }
        return a;
    }
    static int[] getL(int n, int k, int c, string s, int[] R)
    {
        var a = new int[k + 1];
        var p = 0;
        var kc = 1;
        while (p < n && kc <= k)
        {
            if (s[p] == 'o')
            {
                a[kc] = p + 1;
                if (a[kc] == R[kc]) Console.WriteLine(a[kc]);
                p += c + 1;
                kc++;
            }
            else p++;
        }
        return a;
    }
}


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

int N, K, Q;
vector<int> C;

int main(void) {
	cin >> N >> K >> Q;

	C.resize(N + 1, 0);
	for (int i = 0; i < Q; ++i) {
		int a;
		cin >> a;
		++C[a];
	}

	for (int i = 1; i <= N; ++i) {
		int p = K - Q +  C[i];
		string ans = (p > 0) ?  "Yes\n" : "No\n";
		cout << ans;
	}
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main()
{
    int N,T;
    cin >> N >> T;
    int t[200000];
    for(int i = 0; i < N; ++i) cin >> t[i];

    ll sum = 0;
    for(int i = 0; i < N-1; ++i){
        sum += min(t[i+1] - t[i], T);
    }
    sum += T;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author aps
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        KStones solver = new KStones();
        solver.solve(1, in, out);
        out.close();
    }

    static class KStones {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = in.nextInt();
            int[] dp = new int[k + 5];
            dp[0] = 0;
            for (int i = 1; i <= k; i++) {
                dp[i] = 0;
                for (int j = 0; j < n && a[j] <= i; j++) {
                    if (i >= a[j] && dp[i - a[j]] == 0) dp[i] = 1;
                }
            }
            if (dp[k] == 1) out.println("First");
            else out.println("Second");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 23764
a = [int(i) for i in input().split()]

if a[0]+a[1]<=a[2]:
    print(0,0)
elif a[0]>=a[2]:
    print(a[0]-a[2],a[1])
elif a[0]<a[2]:
    b = a[2]-a[0]
    print(0,a[1]-b)

Measured memory_bytes: 9148
s = input()
s = ''.join(list(sorted(set(s))))
a = 'abcdefghijklmnopqrstuvwxyz'
if len(s) == 26:
  print('None')
else:
  for i in range(len(s)):
    if a[i] != s[i]:
      print(a[i])
      break
    if i == len(s)-1:
      print(a[i+1])

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


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

bool dp[100000+1];
bool flag[100000+1];

/*
int search(const vll& a, const int K, vector<short int>& dp){
  if(dp[K]>=0) return dp[K];
  for(ll num : a){
    if(num <= K){
      int tmp = search(a, K-num, dp);
      if(tmp%2==0){
        return dp[K] = (tmp+1)%2;
      }
    }
  }
  return dp[K] = 0;
}
*/

int search(const vll& a, const int K){
  if(flag[K]) return dp[K];
  flag[K] = true;
  for(ll num : a){
    if(num <= K){
      bool tmp = search(a, K-num);
      if(tmp){
        return dp[K] = !tmp;
      }
    }
  }
  return dp[K] = true;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, K;
  cin >> N >> K;
  vll a(N);
  rep(i, 0, N){
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<ll>());
  //vector<short int> dp(K+1, -1);
  memset(flag, false, sizeof(flag));

  //if(search(a, K, dp)%2==1) printf("First\n");
  if(!search(a, K)) printf("First\n");
  else printf("Second\n");

  return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX=1e5+5;



int main()
{
        int n;
        cin>>n;
        int a[n],dp[n]={0};
        for(int i=0;i<n;i++)
                cin>>a[i];
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        for(int i=2;i<n;i++)
        {
                dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
        }
        cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
def reconstruct preorder, inorder
  no=inorder.size-1
  root = preorder.shift
  unless root_idx = inorder.index(root)#???
    reconstruct(preorder,inorder)
    return
  end
  if root_idx==0
  elsif root_idx==1
    $postorder << inorder[0]
  else
    reconstruct(preorder,inorder[0...root_idx])#???
  end

  if root_idx==no
  elsif root_idx==no-1
    $postorder << inorder[-1]
  else
    reconstruct(preorder,inorder[root_idx+1..-1])#???
  end
  $postorder << root
end

gets
Pre=gets.split.map &:to_i
In=gets.split.map &:to_i
$postorder=[]
reconstruct(Pre,In)
puts $postorder.join " "

Measured memory_bytes: 6120
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<queue>
#include<cstring>
using namespace std;
short rule[8][5]={{2,1,4},{3,0,2,5},{3,1,3,6},{2,2,7},
                {2,0,5},{3,1,4,6},{3,2,5,7},{2,3,6}};
short memo[16777216];
class P{
	public:
	int data[8];
	int cnt;
	P(){}
	P(int a[8],int cnt):cnt(cnt){
		for(int i = 0; i < 8; i++){
			data[i] = a[i];
		}
	}
};
int getIndex(int *a){
	int res = 0;
	int r = 1;
	for(int i = 0; i < 8; i++){
		res += a[i]*r;
		r *= 8;
	}
	return res;
}
int main(){
	memset(memo,-1,sizeof(memo));
	queue<P> Q;
	int F[]={0,1,2,3,4,5,6,7};
	Q.push(P(F,0));
	int cnt = 0;
	while( !Q.empty() ){
		P p = Q.front();Q.pop();
		int id = getIndex(p.data);
        if(memo[id] != -1)continue;
        memo[id] = p.cnt;
		int zero;
		for(int i = 0; i < 8; i++){
			if(p.data[i] == 0){zero = i;break;}
		}
		for(int i = 0; i < rule[zero][0]; i++){
			swap(p.data[zero],p.data[rule[zero][i+1]]);
			Q.push(P(p.data,p.cnt+1));
			swap(p.data[zero],p.data[rule[zero][i+1]]);
		}

	}
	int in[10];
	while(~scanf("%d%d%d%d%d%d%d%d",&in[0],&in[1],&in[2],&in[3],&in[4],&in[5],&in[6],&in[7])){
		int id = getIndex(in);
		printf("%d\n",memo[id]);
	}
	return 0;
}

Measured memory_bytes: 34116
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main(void){
  string str;
  cin >> str;
  int N[4];
  transform(begin(str), end(str), N, [](char c) {return c - '0';} );
  int i = 0;
  int flg = 0;
  while(i < 3){
	if (N[i] == N[i+1]){ flg = 1; }
    i++;
  }
  if (flg == 1) { cout << "Bad" << endl; }
  else{ cout << "Good" << endl; }
  return 0;  
}

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
 
int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
 
int main() {

    int n;
    cin>>n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n)  cin>>p[i];
    rep(i,n)  cin>>q[i];

    int a=0,b=0;
    rep(i,n){
        a+=facctorialMethod(n-i-1)*p[i];
        for(int j = i; j<n; j++) {
            if(p[j] > p[i]) p[j]--;  
        }
    }
    rep(i,n){
        b+=facctorialMethod(n-i-1)*q[i];
        for(int j = i; j<n; j++) {
            if(q[j] > q[i]) q[j]--;  
        }
    }
 
  cout<<abs(a-b)<<endl;

  return 0;
}

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

int main()
{
  string cla;
  int n, m;

  for (int i = 0; i < 9; i++){
    cin >> cla >> n >> m;
    cout << cla << " " << n + m << " " << 200 * n + 300 * m << endl;
  }
}

Measured memory_bytes: 1200
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        //スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int k = int.Parse(input[1]);
        int q = int.Parse(input[2]);

        int allsum = (n - 1) * q;

        int[] array = new int[n];
        int i = 0;
        for (i = 0; i < q; i++)
        {
            int num = int.Parse(Console.ReadLine());
            array[num-1]++;
        }
        int j = 0;
        for (j = 0; j < n; j++)
        {
            if(q-array[j] < k)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 17600
import java.util.*;
import java.lang.*;


public class Main {
    static int pow(int a, int b){
        int ans = 1;
        for(int i=0; i<b; i++) ans *= a;
        return ans;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt(16);
        int Y = sc.nextInt(16);

        if(X<Y) System.out.println("<");
        if(X==Y) System.out.println("=");
        if(X>Y) System.out.println(">");


    }
}


Measured memory_bytes: 21844
package main

import "fmt"

func report(a []int) {
	for i, l := 0, len(a); i < l; i++ {
		if i < l-1 {
			fmt.Printf("%d ", a[i])
		} else {
			fmt.Println(a[i])
		}
	}
}

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	report(a)
	for i := 1; i <= len(a)-1; i++ {
		key := a[i]
		j := i - 1
		for j >= 0 && a[j] > key {
			a[j+1] = a[j]
			j--
		}
		a[j+1] = key
		report(a)
	}

}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(x,n) for(auto& (x) : n)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;
typedef pair<int,pint> P;

int main(){
    int n;
    cin>>n;
    vint u(n),v(n),w(n);
    vector<vector<pint>> table(n);
    vint color(n);
    rep(i,n)color[i]=-1;
    rep(i,n-1){
        int p,q,r;
        cin>>p>>q>>r;
        table[p-1].pb(mp(q-1,r%2));
        table[q-1].pb(mp(p-1,r%2));
    }
    color[0]=0;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int q=que.front();
        que.pop();
        if(color[q]==-1)continue;
        forin(x,table[q]){
            if(color[x.first]==-1){
                color[x.first]=(color[q]+x.second)%2;
                que.push(x.first);
            }
        }
    }
    rep(i,n)cout<<color[i]<<endl;


    
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<' ';pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  set<int> s;
  rep(i,m) {
    int k;
    cin >> k;
    rep(j,k) {
      int x;
      R x;
      s.in(x);
    }
  }
  int ans=0;
  REP(i,1,n+1) {
    if(!s.count(i)) ans++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3624
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

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

fn main() {
    input! {
        n: usize,
        xy: [(isize,isize); n],
    }

    let xy = xy
        .into_iter()
        .map(|(x, y)| (x + y, x - y))
        .collect::<Vec<_>>();

    let mut xmx = std::isize::MIN;
    let mut xmn = std::isize::MAX;
    let mut ymx = std::isize::MIN;
    let mut ymn = std::isize::MAX;

    for (x, y) in xy {
        xmx = std::cmp::max(xmx, x);
        xmn = std::cmp::min(xmn, x);
        ymx = std::cmp::max(ymx, y);
        ymn = std::cmp::min(ymn, y);
    }

    println!("{}", std::cmp::max(xmx - xmn, ymx - ymn));
}


Measured memory_bytes: 12176
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int):
    ans=[A,B,C]
    ans.sort()
    print(YES if max(ans.count(A),ans.count(B))==2 else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<queue>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	vector<int> a(n);
	priority_queue<int> q;
	for(int i=0;i<n;i++){
		cin>>a[i];
		q.push(a[i]);
	}
	for(int i=0;i<m;i++){
		int temp=q.top();
		q.pop();
		q.push(temp/2);
	}
	long long ans=0;
	for(int i=0;i<n;i++){
		ans+=q.top();
		q.pop();
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1276
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	String s;

	void run(){
		s=sc.nextLine();
		solve();
	}

	char[] cs;
	int max;

	void solve(){
		s+="$";
		cs=s.toCharArray();
		max=-1;
		dfs(0);
		println(max+"");
	}

	void dfs(int i){
		char[] op={'0', '1', '+', '-', '*', '(', ')'};
		if(i==cs.length){
			max=max(max, calc());
			return;
		}
		if(cs[i]=='.'){
			for(char c : op){
				cs[i]=c;
				dfs(i+1);
				cs[i]='.';
			}
		}else{
			dfs(i+1);
		}
	}

	int calc(){
		Result r=E(0);
		r.good&=r.p==cs.length-1;
		if(r.good){
			int n=cs.length;
			for(int i=0; i<n; i++){
				if(cs[i]!='('){
					continue;
				}
				int left=i, right=left+1;
				int stack=0;
				boolean op=false;
				for(; cs[right]!=')'||stack!=0; right++){
					if(cs[right]=='('){
						stack++;
					}else if(cs[right]==')'){
						stack--;
					}
					if(stack==0)
						op|=cs[right]=='+'||cs[right]=='-'||cs[right]=='*';
				}
				r.good&=op;
			}
		}
		return r.good?r.value:-1;
	}

	Result E(int p){
		Result r=F(p);
		if(!r.good){
			return r;
		}
		for(; cs[r.p]=='+'||cs[r.p]=='-';){
			Result r2=F(r.p+1);
			if(!r2.good){
				return r2;
			}
			if(cs[r.p]=='+'){
				r.value+=r2.value;
			}else{
				r.value-=r2.value;
			}
			r.update();
			if(!r.good){
				return r;
			}
			r.p=r2.p;
		}
		return r;
	}

	Result F(int p){
		Result r=T(p);
		if(!r.good){
			return r;
		}
		for(; cs[r.p]=='*';){
			Result r2=T(r.p+1);
			if(!r2.good){
				return r2;
			}
			r.value*=r2.value;
			r.update();
			if(!r.good){
				return r;
			}
			r.p=r2.p;
		}
		return r;
	}

	Result T(int p){
		if(cs[p]=='('){
			Result r=E(p+1);
			if(!r.good||cs[r.p]!=')'){
				r.good=false;
				return r;
			}
			r.p++;
			return r;
		}else if(cs[p]=='0'||cs[p]=='1'){
			Result r=new Result(p, 0);
			for(; Character.isDigit(cs[r.p]); r.p++){
				r.value=r.value*2+cs[r.p]-'0';
				r.update();
			}
			return r;
		}else{
			return new Result(0, -1);
		}
	}

	class Result{
		int p, value;
		boolean good;

		Result(int p, int value){
			this.p=p;
			this.value=value;
			good=true;
			update();
		}

		void update(){
			good&=0<=value&&value<1024;
		}
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException {
		// ?¨??????????
		int result = 100000;
		// ?????????????¨??????¨???
		int roundup = 1000;
		// ??????
		double rate = 0.05;

		// ????????±??°
		int n = Integer.parseInt(new BufferedReader(new InputStreamReader(
				System.in), 64).readLine());

		// n??±???????????????????¨????
		// 0??±??????????¨????????????¨???
		if (n != 0) {
			for (int i = 0; i < n; i++) {
				result = (int) (result + (result * rate));
				if ((result % roundup) != 0) {
					result = ((int) (result / roundup) + 1) * roundup;
				}
			}
		}
		System.out.println(result);
	}
}

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

using namespace std;

int main(){
    char a[100]; cin >> a;
    int i,j;
    
    bool flag = true;
    
    for(i = 0 ; i < strlen(a) ; i++){
        for(j = i+1 ; j < strlen(a) ; j++){
            if(a[i] == a[j])
                flag = false;
        }
    }
    if(flag == false)
        cout << "no" << endl;
    
    else
        cout << "yes" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


int n;
lli dat[2005];
lli dp[2][2005];

lli Z,W;

lli inf=10000000000LL;

lli dfs(int no,int d){
	lli& x = dp[no][d];
	if(x>=0){
		return x;
	}
	lli res=abs(dat[d]-dat[n]);
	if(no==0){
		reg(j,d+1,n-1){
			res = max(res,dfs(1-no,j));
		}
	}
	else{
		reg(j,d+1,n-1){
			res = min(res,dfs(1-no,j));
		}
	}
	x = res;
	//printf("%d %d %d %lld\n",no,d,bd,res);
	return res;		
}

int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%d%lld%lld",&n,&Z,&W);
	reg(i,1,n){
		scanf("%lld",&dat[i]);
	}
	dat[0]=W;
	printf("%lld\n",dfs(0,0));
	return 0;
}




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

#define INF INT_MAX

using namespace std;

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

int main(void){
 	cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = (s[k-1] - 'A') + 'a';
    cout << s << endl;

	return 0;
}

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

int main(void) {
	
	int judge;
	string p, s;
	cin >> p >> s;
	p += p;

	judge = p.find(s);
	if (judge == -1) cout << "No" << endl;
	else            cout << "Yes" << endl;

	return 0;
}




Measured memory_bytes: 3232
l = [list(map(int,input().split())) for i in range(3)]
a,b = [list(i) for i in zip(*l)]
t = [0] * 4

for i in range(3):
    t[a[i] - 1] += 1
    t[b[i] - 1] += 1

if max(t) == 3:
    print('NO')
else:
    print('YES')

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll MOD = 1e9 + 7;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}
  mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;}
  mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;}
  mint operator+(const mint a) const {mint res(*this);return res+=a;}
  mint operator-(const mint a) const {mint res(*this);return res-=a;}
  mint operator*(const mint a) const {mint res(*this);return res*=a;}
  mint pow(ll b) const {
    mint res(1), a(*this);
    while (b) {
      if (b & 1) res *= a;
      a *= a;
      b >>= 1;
    }
    return res;
  }
  // for prime MOD
  mint inv() const {return pow(MOD-2);}
  mint& operator/=(const mint a) {return (*this) *= a.inv();}
  mint operator/(const mint a) const {mint res(*this);return res/=a;}
};
ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;}



const int SZ = 1123456;
ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}

ll P(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD;
}

int main2() {
  ll N = nextLong();
  ll M = nextLong();
  mint ans = 0;
  for (int i = 0; i <= N; i++) {
    mint val = mint(P(M-i, N-i)) * mint(choose(N, i));
    if (i % 2 == 0)
      ans += val;
    else
      ans -= val;
  }
  ans *= mint(fact[N]);
  ans *= mint(choose(M, N));
  cout << ans << endl;
  return 0;
}

int main() {
  inv[1] = 1;
  for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 30016
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from math import ceil, floor, pi
import bisect
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

def main():
    r = int(input())
    print(2 * pi * r)

if __name__ == '__main__':
    main()
 


Measured memory_bytes: 9472
const log = console.log;

const createScanFunctions = (input: string) => {
  const str = input.trim();
  const len = str.length;
  let index = 0;

  const scan = () => {
    const startIndex = index;

    while (index < len) {
      const char = str[index];

      if (char === " " || char === "\n")
        return str.substring(startIndex, index++);

      index++;
    }

    return str.substr(startIndex);
  };

  const scanInt = () => parseInt(scan());

  return { scan, scanInt };
};

const scanIntArray = (scanIntFunction: () => number, length: number) => {
  const array = new Array<number>(length);
  for (let i = 0; i < length; i++) array[i] = scanIntFunction();

  return array;
};

// ----

const sumReducer = (accumulator: number, currentValue: number) =>
  accumulator + currentValue;
const sum = (numbers: number[]) => numbers.reduce(sumReducer, 0);

// ----

function Main(input: string): void {
  const { scanInt } = createScanFunctions(input);

  const n = scanInt();
  const m = scanInt();
  const a = scanIntArray(scanInt, n).sort((a, b) => a - b);

  const operations = new Array<number[]>(m);
  for (let i = 0; i < m; i++) operations[i] = [scanInt(), scanInt()]; // [b, c]
  operations.sort((opA, opB) => opB[1] - opA[1]);

  let aIndex = 0;

  for (let opIndex = 0; opIndex < m; opIndex++) {
    const [b, c] = operations[opIndex];
    let stop = false;

    for (let i = 0; i < b; i++) {
      if (a[aIndex] >= c) {
        stop = true;
        break;
      }

      a[aIndex++] = c;

      if (aIndex >= n) {
        stop = true;
        break;
      }
    }

    if (stop) break;
  }

  log(sum(a));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 32716
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextUint64() uint64 {
	l := nextLine()
	i, e := strconv.ParseUint(l, 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextUint64()

	fmt.Printf("%d\n", ABC148E(N))
}

// ABC148E ...
func ABC148E(N uint64) (res uint64) {
	if N%2 == 1 {
		return
	}

	for i := uint64(10); i <= N; i *= 5 {
		res += N / i
	}

	return
}


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

#define mod 1000000007
#define int long long int
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define vs vector<string>
#define fi first
#define se second
#define psb push_back
#define ppb pop_back
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(v) v.begin(),v.end()
#define endl "\n"

int32_t main()
{
	int n,g;
	cin>>n>>g;
	if(n%g==0)
		cout<<n/g<<endl;
	else
		cout<<(n/g)+1<<endl;
}

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

int main(){
    int n, a, res = 1<<21;
    cin >> n;

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

        int cnt = 0;
        while(a%2 == 0){
            cnt++;
            a /= 2;
        }

        res = min(res, cnt);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::collections::HashMap;

fn main() {
    input!{
        n: usize,
        aa: [usize; n],
    };
    let mut left = HashMap::new();
    let mut right = HashMap::new();
    for (i, &a) in aa.iter().enumerate() {
        if i >= a {
            *left.entry(i - a).or_insert(0) += 1;
        }
        if i + a < n {
            *right.entry(i + a).or_insert(0) += 1;
        }
    }
    let mut ans: i64 = 0;
    for i in 0..n {
        ans += *left.get(&i).unwrap_or(&0) * *right.get(&i).unwrap_or(&0);
    }
    println!("{}", ans);
}


Measured memory_bytes: 15244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int main(){
  int x, y;
  cin >> x >> y;

  cout << x + y/2 << endl;

  return 0;
}

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

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if (U == S) {
    A--;
  } else {
    B--;
  }
  cout << A << " " << B << endl;
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
long long f[401][401];
long long a[401],sum[401];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	for(int j=1;j<n;j++)
		for(int i=1;i<=n&&i+j<=n;i++)
		{
			long long minn=numeric_limits<long long>::max();
			for(int k=i;k<i+j;k++)
				minn=min(f[i][k]+f[k+1][i+j],minn);
			f[i][i+j]=minn+sum[i+j]-sum[i-1];
		}
	printf("%lld",f[1][n]);
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    string S, T;
    cin >> S >> T;
    int N = S.length();

    map<char, char> ma;
    bool ans = true;
    for(int i = 0; i < N; i++){
        char s = S[i];
        char t = T[i];
        if(ma.find(s) != ma.end() && ma[s] != t) ans = false;
        ma[s] = t;
    }

    set<char> se;
    for(char c = 'a'; c <= 'z'; c++){
        if(ma.find(c) == ma.end()) continue;
        char t = ma[c];
        if(se.find(t) != se.end()) ans = false;
        se.insert(t);
    }

    if(ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 776
use std::io::*;
use std::str::FromStr;
// use std::collections::HashSet;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();
    let si: Vec<String> = (0..n).map(|_| read()).collect();
    // println!("{:?}", si);

    let si: Vec<String> = si.into_iter().map(|s| {
        let mut chars: Vec<char> = s.chars().collect();
        chars.sort();
        let x: String = chars.into_iter().collect();
        x
    }).collect();
    // println!("{:?}", si);

    // let uniq: HashSet<String> = si.iter().cloned().collect();
    // let mut ans = 0;
    // for u in uniq {
    //     let mut cnt = 0;
    //     for s in si.iter() {
    //         if u == *s {
    //             cnt += 1;
    //         }
    //     }
    //     ans += (1..cnt).sum();
    // }

    // for i in 0..n {
    //     let x: &String = &si[i as usize];
    //     for j in (i+1)..n {
    //         let y: &String = &si[j as usize];
    //         if *x == *y {
    //             ans += 1;
    //         }
    //     }
    //     // let cnt = si.iter().skip((i + 1) as usize).filter(|x| x == si[i as usize]).count();
    //     // ans += cnt;
    // }

    let mut map: HashMap<String, u64> = HashMap::new();
    for s in si.into_iter() {
        if map.contains_key(&s) {
            if let Some(x) = map.get_mut(&s) {
                *x += 1;
            }
        } else {
            map.insert(s, 1);
        }
    }
    let mut ans: u64 = 0;
    for (_, v) in map {
        ans += (1..v).sum();
    }

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


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

using namespace std;
int main(){
  string s;
  cin >> s;
   
  int res=0;
  for(int i=0;i<s.length()-1;i++){
   if(s.substr(i,2)=="BW"||s.substr(i,2)=="WB") res++;
  }
  
 cout << res << endl;
  
  
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int ans = c - (a - b);
        if (ans > 0) {
            System.out.println(ans);
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#define maxn 10010
#define maxe 100010
#define MAXN 10010
typedef long long ll;
using namespace std;
const double eps=1e-5;
const int inf=0x3f3f3f3f;
const double pi=2.0*asin(1.0);
typedef double T1;
const double EPS = 1e-8;
int n;
struct Point
{
    T1 x,y;
    int id;
    Point(){};
    Point(T1 a,T1 b)
    {
        x=a,y=b;
    }
    void input()
    {
        scanf("%lf%lf",&x,&y);
    }
    Point operator +(Point a)
    {
        Point b(x+a.x,y+a.y);
        return b;
    }
    Point operator -(Point a)
    {
        Point b(x-a.x,y-a.y);
        return b;
    }
    T1 operator *(Point a)
    {
        return x*a.x+y*a.y;
    }
    T1 operator ^(Point a)
    {
        return x*a.y-y*a.x;
    }
   bool operator<(const Point &another) const;
};
int tot;//凸包含有的顶点个数
Point p[MAXN], s[MAXN];//下标都从0开始，p是原来的点集，s是凸包点集
int sgn(double x)
{
    if (fabs(x) < EPS) return 0;
    if (x > 0)
        return 1;
    else
        return -1;
}
double det(const Point &a1, const Point &a2, const Point &b1, const Point &b2)//求向量a与b的叉积
{
    return ((a2.x - a1.x) * (b2.y - b1.y) - (a2.y - a1.y) * (b2.x - b1.x));
}

double dist(const Point &p1, const Point &p2)
{
    return sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y));
}

bool Point::operator<(const Point &another) const
{
    if (sgn(det(p[0], *this, p[0], another)) == 0)
        return dist(p[0], *this) < dist(p[0], another);
    else
        return det(p[0], *this, p[0], another) > 0;
}

void Graham()
{
    double min_y = p[0].y, min_x = p[0].x;
    int index = 0;
    for (int i = 1; i <= n - 1; i++) {
        if (p[i].y < min_y || (sgn(p[i].y - min_y) == 0 && p[i].x < min_x)) {
            min_y = p[i].y;
            min_x = p[i].x;
            index = i;
        }
    }
    swap(p[0], p[index]);
    sort(p + 1, p + n);
    s[0] = p[0]; s[1] = p[1];
    tot = 2;
    for (int i = 2; i <= n - 1; i++) {
        while (tot >= 2 && sgn(det(s[tot - 1], p[i], s[tot - 1], s[tot - 2])) <0) tot--;
        s[tot++] = p[i];
    }
}
double ans[maxn];
int main()
{
    while(scanf("%d",&n)==1)
    {
        for(int i=0;i<n;i++)
        {
            p[i].input();
            p[i].id=i;
        }
        Graham();
        int siz=tot;
        for(int i=0;i<siz;i++)
        {

            //printf("%f %f\n",p[i].x,p[i].y);
            int l=(i-1+siz)%siz;
            int r=(i+1)%siz;
            double aa=(s[l]-s[i])*(s[r]-s[i])/(dist(s[i],s[l])*dist(s[i],s[r]));
            double theta=acos(aa);
            ans[s[i].id]=(pi-theta)/(2*pi);
        }
        for(int i=0;i<n;i++)
        {
            printf("%.7f\n",ans[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define ll long long
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  int k,s;
  long long sum=0;
  cin>>k>>s;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if(s-i-j>=0&&s-i-j<=k)sum++;
      //cout<<i<<" "<<j<<" "<<s-i-j<<endl;
    }
  }
  cout<<sum<<endl;
  return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<ll,ll>;

ll K, X, Y;
std::vector<P> v;

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

    std::cin >> K >> X >> Y;

    bool negX = (X < 0), negY = (Y < 0);
    ll absX = std::abs(X), absY = std::abs(Y);
    ll sum = absX + absY;

    if(K % 2 == 0 && sum % 2 == 1){
        std::cout << -1 << std::endl;
        return 0;
    }

    if(sum < K){
        ll x = 0, y = 0;

        if(sum % 2 == 0){
            if(absX >= sum / 2){
                x += sum / 2;
                y -= K - sum / 2;
                v.emplace_back(x, y);
                v.emplace_back(absX, absY);
            }else{
                y += sum / 2;
                x -= K - sum / 2;
                v.emplace_back(x, y);
                v.emplace_back(absX, absY);                
            }
        }else{
            x -= (K - sum) / 2;
            y -= K - (K - sum) / 2;
            v.emplace_back(x, y);
            x -= (K - sum) / 2;
            y += K - (K - sum) / 2;
            v.emplace_back(x, y);
            v.emplace_back(absX, absY);
        }
    }else{
        ll x = 0, y = 0;
        until(x == absX && y == absY){
            ll dx = absX - x, dy = absY - y;
            ll s = dx + dy, r = s % K;

            if(r == 0){
                ll dx2 = std::min(dx, K), dy2 = K - dx2;
                x += dx2;
                y += dy2;
                v.emplace_back(x, y);

                continue;
            }

            if(K % 2 != r % 2){
                if(dx >= r){
                    x += r / 2;
                    y -= K - r / 2;
                    v.emplace_back(x, y);
                    x += r / 2;
                    y += K - r / 2;
                    v.emplace_back(x, y);
                }else{
                    y += r / 2;
                    x -= K - r / 2;
                    v.emplace_back(x, y);
                    y += r / 2;
                    x += K - r / 2;
                    v.emplace_back(x, y);                    
                }

                continue;
            }

            if(dx >= (K + r) / 2){
                x += (K + r) / 2;
                y -= (K - r) / 2;
                v.emplace_back(x, y);
            }else{
                y += (K + r) / 2;
                x -= (K - r) / 2;
                v.emplace_back(x, y);
            }
        }
    }

    std::cout << v.size() << std::endl;

    for(auto &p : v){
        ll x, y;
        std::tie(x, y) = p;

        if(negX){
            x = -x;
        }

        if(negY){
            y = -y;
        }

        std::cout << x << " " << y << std::endl;
    }
}

Measured memory_bytes: 5484
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

ll s[1100][1100],b[1100];
pair<int, int> a[1100];
int main() {
	
	int n,m,ans = 0;
	cin >> n >> m;
	REPO(i, n) REPO(j, n) {
		if (i != j) s[i][j] = INF;
		else s[i][j] = 0;
	}
	REP(i, m) {
		cin >> a[i].first >> a[i].second >> b[i];
		s[a[i].first][a[i].second] = b[i];
		s[a[i].second][a[i].first] = b[i];
	}
	REPO(k, n) REPO(i, n) REPO(j, n) s[i][j] = min(s[i][j], s[i][k] + s[k][j]);
	REP(i, m) REPO(k, n) if (s[k][a[i].first] + b[i] == s[k][a[i].second]) { ans++; break; }
	cout << m - ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
 cin >>N;
 int X,T;
 cin >>X>>T;
 if(N%X==0){
     cout << N/X*T <<endl;
 }
 else{
     cout <<(N/X+1)*T<<endl;
 }


}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int N, A, B, C, D;
int dp[101001];

int main() {

    cin >> N >> A >> B >> C;

    fill(dp, dp + 101001, 0);
    dp[A] = C;

    for (int i = 0; i < N; i++) {
        cin >> D;
        for (int j = A + B * N; j >= A; j--) {
            if (dp[j])
                dp[j + B] = max(dp[j + B], dp[j] + D);
        }
    }

    int ans = 0;
    for (int i = A; i <= A + B * N; i++) {
        ans = max(ans, dp[i] / i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3484
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		List<Double> list = new ArrayList<Double>();
		double[][] ans = new double[1001][2];
		double[] angle = new double[1001];
		ans[0][0] = 1; ans[0][1] = 0;
		for(int i = 1; i < 1001; i++){
			angle[i] = angle[i-1] + Math.atan(1/Math.sqrt(i));
			ans[i][0] = Math.cos(angle[i])*Math.sqrt(i+1);
			ans[i][1] = Math.sin(angle[i])*Math.sqrt(i+1);
		}
		int n = stdIn.nextInt();
		while( n != -1 ){
			list.add(ans[n-1][0]);
			list.add(ans[n-1][1]);
			n = stdIn.nextInt();
		}
		for(Double p : list){
			System.out.printf("%.2f%n", p);
		}
	}
}

Measured memory_bytes: 12000
package main

import ("fmt"
	    "sort")

func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

func main() {
	var N int
	fmt.Scan(&N)

	nums := scanNums(N)

	var count int 
	for i:=0;i<N-2;i++ {
		a := []int{nums[i], nums[i+1], nums[i+2]}
		sort.Ints(a)
		if a[1] == nums[i+1] {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512