akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "4", "1 3 4 2" ].parse.expand.solve == 20 );
	assert( [ "6", "5 5 6 1 1 1" ].parse.expand.solve == 58 );
	assert( [ "6", "8 6 9 1 2 1" ].parse.expand.solve == 85 );
	
	assert( [ "4", "10 10 10 1" ].parse.expand.solve == 62 );		// 追加ケース
	assert( [ "3", "10 10 1" ].parse.expand.solve == 31 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// dp[ 左からl番目まで確定済 ][ 右からr番目まで確定済 ] = うれしさの合計
	auto dp = new long[][]( 1 + as.length, 1 + as.length );
	foreach( i, a, p; zip( as, iota( as.length.signed ) ).array.sort!( ( x, y ) => y < x ).enumerate( 0L ) )
	{
		for( auto l = 0L, r = i; 0 <= r; l++, r-- )
		{
			dp[ l + 1 ][ r ] = max( dp[ l + 1 ][ r ], dp[ l ][ r ] + a * abs( p - l ) );
			dp[ l ][ r + 1 ] = max( dp[ l ][ r + 1 ], dp[ l ][ r ] + a * abs( as.length.signed - 1 - r - p ) );
		}
	}
	
	auto ans = 0L;
	for( auto l = 0L, r = dp[ 0 ].length.signed - 1; 0 <= r; l++, r-- )
	{
		ans = max( ans, dp[ l ][ r ] );
	}
	return ans;
}


Measured memory_bytes: 35140
#include <iostream>
#include <cstdio>

const int MIN_R = 2;
const int MAX_R = 5;
const int MIN_D = 1;
const int MAX_D = 100;
const int MAX_X2000 = 200;

// int getX_i_1(int r, int xi, d) {
//   return (r * xi - d);
// }

int main() {
  int r, d , x[11];

  scanf("%d %d %d", &r, &d, &x[0]);
  for (int i=1; i < 11; i++) {
    x[i] = r * x[i-1] - d;
    //printf("i=%d xi=%d\n", i, x[i]);
    printf("%d\n", x[i]);
  }
  //printf("%d %d %d ", r, d, x);

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define NIL -1
#define MAX 4100005
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int n;
int root;
int *p = new int[MAX];       //    p---|  Unit
int *left2 = new  int[MAX]; // left2 --|--------> T
int *right2 = new int[MAX]; //right2---|
int *key = new int[MAX];     // key----|

 
void Init(){
  rep(i,MAX){
    p[i]=left2[i]=right2[i]=key[i]=NIL;
  }
}

int TREE_MINIMUM(int x){
  while(left2[x] != NIL){
    x = left2[x];
  }
  return x;
}


int TREE_SUCCESSOR(int x){
  if(right2[x] != NIL)return TREE_MINIMUM(right2[x]);
  int y = p[x];
  while(y != NIL && x == right2[y]){
    x = y;
    y = p[y];
  }
  return y;
}
 
void TREE_DELETE(int z){
  int y,x;
  if(left2[z] == NIL || right2[z] == NIL)y = z;
  else y = TREE_SUCCESSOR(z);

  if(left2[y] != NIL)x = left2[y];
  else x = right2[y];

  if(x != NIL)p[x]=p[y];
  if(p[y] == NIL)root = x;
  else if(y == left2[p[y]])left2[p[y]] = x;
  else right2[p[y]] = x;

  if(y != z)key[z] = key[y];

}


bool SEARCH(int x,int k){
  if(k == key[x])return true;
  if(x == NIL)return false;
  if(k < key[x])return SEARCH(left2[x],k);
  else return SEARCH(right2[x],k);
}

 
void TREE_INSERT(int z){
  int y = NIL;  
  int x = root;
 
  while(x != NIL){
    y = x;
    if(key[z] < key[x]){
      x = left2[x];
    }
    else x = right2[x];
  }
  p[z]=y;
  if(y == NIL){
    root = z;
  }
  else if(key[z] < key[y]){
    left2[y] = z;
  }else{
    right2[y] = z;
  }
 
}

int IndexSearch(int x){
  for(int i=0;i<MAX;i++){
    if(key[i] == x)return i;
  }
  return -1;
} 


void InorderTreeWalk(int x){
  if(x != NIL){
    InorderTreeWalk(left2[x]);
    printf(" %d",key[x]);
    InorderTreeWalk(right2[x]);
  }
}
 
void PreorderTreeWalk(int x){
  if(x != NIL){
    printf(" %d",key[x]);
    PreorderTreeWalk(left2[x]);
    PreorderTreeWalk(right2[x]);
  }
}
 
 
int main(){
  int val;
  string op;
  long long zr;                     

 
  scanf("%d",&n);
  Init();  
  root = -1;
  zr=0;
  while(n-- > 0){
    cin >> op;
    if(op == "insert"){
      scanf("%d",&val);
      key[zr]=val;         
      TREE_INSERT(zr);
      zr++;
    }else if(op == "print"){
      InorderTreeWalk(root);
      printf("\n");
      PreorderTreeWalk(root);
      printf("\n");
    }
    else if(op == "find"){
      scanf("%d",&val);
      if(SEARCH(root,val)){
	printf("yes\n");
      }else{
    printf("no\n");
      }
       
 
    }
    else if(op == "delete"){
      scanf("%d",&val);
      int inthis = IndexSearch(val);
      if(inthis != -1){
      TREE_DELETE(inthis);
      }
    }

  }
 
  delete [] p;
  delete [] left2;
  delete [] right2;
  delete [] key;

  return 0;
}

Measured memory_bytes: 63000
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, K int
	// P := 1000
	fmt.Scan(&N, &K)
	exceptedValues := make([]float64, N+1)
	var exceptedValue float64
	input := 0
	var res float64
	// execptedValueMemo := make([]float64, 1001)

	// var x float64
	for i := 0; i < N; i++ {
		fmt.Scan(&input)
		exceptedValue = getExceptedValue(input)

		if i == 0 {
			exceptedValues[i] = exceptedValue
		} else {
			exceptedValues[i] = exceptedValue + exceptedValues[i-1]
		}
		if i+1 >= K {
			// fmt.Println(i, K)
			if i+1-K != 0 {
				res = math.Max(res, exceptedValues[i]-exceptedValues[i-K])
			} else {
				res = math.Max(res, exceptedValues[i])
			}
			// fmt.Println(exceptedValues[i], exceptedValues[i-K+1])
		}
		// fmt.Println(res)
	}
	fmt.Println(res)
	// fmt.Println(exceptedValues)

}

func getExceptedValue(N int) float64 {
	cont := 0
	for i := 0; i < N; i++ {
		cont += i + 1
	}
	res := float64(cont) / float64(N)
	return res
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int n,l,r,mid,ans;
int a[200005];
struct node{
	int u,l,r;
};

int check(int x){
	stack<node> f;
	f.push((node){1,1,a[1]});
	for(int i=2;i<=n;i++){
		if(a[i]>a[i-1]) f.push((node){1,a[i-1]+1,a[i]});
		else{
			int p;
			while(!f.empty()){
				node v=f.top();
				if(v.l>a[i]) f.pop();
				else{
					p=v.u;f.pop();
					if(v.l<a[i]) f.push((node){p,v.l,a[i]-1});
					break;
				}
			}
			if(p<x) f.push((node){p+1,a[i],a[i]});
			else{
				while(!f.empty()){
					node v=f.top();
					p=v.u;f.pop();
					if(p<x){
						if(v.l!=v.r) f.push((node){p,v.l,v.r-1});
						f.push((node){p+1,v.r,v.r});
						f.push((node){1,v.r+1,a[i]});
						break;
					}
				}
				if(p>=x) return 0;
			}
		}
	}
	return 1;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	l=1,r=1e9,ans=1e9+1;
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)) ans=min(ans,mid),r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 3504
li = list(input())
li1 = li[:]

flag = 'No'
for i in range(1,4):
    if li[0]==li[i]:
        del li1[i],li1[0]
        if li1[0] == li1[1]:
            flag = 'Yes'
            break
        break
if li[0]==li1[0]:
    flag = 'No'

print(flag)




Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()
 
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

constexpr long long inf = 1ll << 60;

int main() {

    int N;
    std::cin >> N;
    std::vector<std::pair<int, int>> balls(N);
    rep (i, N) {
        int x, y;
        std::cin >> x >> y;
        if (x > y) std::swap(x, y);
        balls[i] = std::make_pair(x, y);
    }

    std::sort(all(balls));
    int min = balls[0].first, max = -1, pos = -1;
    rep (i, N) {
        if (chmax(max, balls[i].second)) {
            pos = i;
        }
    }

    long long answer = inf;
    // min, max を両方赤で塗る
    if (pos != 0) [&] {
        long long red = max - min;
        long long base_min, base_max;
        std::tie(base_min, base_max) = std::minmax(balls[0].second, balls[pos].first);
        if (N == 2) {
            chmin(answer, red * (base_max - base_min));
            return;
        }
        std::vector<long long> use1, use2;
        rep (i, N) {
            if (i == 0 || i == pos) continue;
            use1.push_back(balls[i].first);
            use2.push_back(balls[i].second);
        }
        chmin(answer, red * (std::max(base_max, use1.back()) - std::min(base_min, use1.front())));
        rep (i, N - 3) {
            chmin(base_min, use2[i]);
            chmax(base_max, use2[i]);
            chmin(answer, red * (std::max(base_max, use1.back()) - std::min(base_min, use1[i + 1])));
        }
        chmin(answer, red * (std::max(base_max, use2.back()) - std::min(base_min, use2.back())));
    } ();
    // min を赤, max を青で塗る
    [&] {
        long long red_min = min, red_max = balls[pos].first;
        long long blue_min = balls[0].second, blue_max = max;
        rep (i, N) {
            chmax(red_max, balls[i].first);
            chmin(blue_min, balls[i].second);
        }
        chmin(answer, (red_max - red_min) * (blue_max - blue_min));
    } ();

    std::cout << answer << '\n';
    return 0;

}


Measured memory_bytes: 5220
#include<stdio.h>
#define MAX 100000
#define NIL -1
int n;
typedef struct{
  int parent,left,right;
}tree;
tree T[MAX];

void preparse(int u){
  if( u == NIL)return;
  printf(" %d",u);
  preparse(T[u].left);
  preparse(T[u].right);
}

void inorder(int u){
  if( u == NIL)return;
  inorder(T[u].left);
  printf(" %d",u);
  inorder(T[u].right);
}

void postorder(int u){
  if( u == NIL)return;
  postorder(T[u].left);
  postorder(T[u].right);
  printf(" %d",u);
}

int main(){
  int i,id,l,r,root;
  
  scanf("%d",&n);

  for(i=0; i<n; i++){
    T[i].parent = NIL;
  }
  
  for(i=0; i<n; i++){
    scanf("%d %d %d",&id, &l, &r);
    T[id].left = l;
    T[id].right = r;
    if(l != NIL) T[l].parent = id ;
    if(r != NIL) T[r].parent = id ;
  }

  for(i=0; i<n; i++) if(T[i].parent == NIL)
		       root =i;

  printf("Preorder\n");
  preparse(root);
  printf("\n");
    
  printf("Inorder\n");
  inorder(root);
  printf("\n");
    
  printf("Postorder\n");
  postorder(root);
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=100100;
int par[sz], ran[sz];

void init(int n)
{
    for(int i=0;i<=n;i++) ran[i]=1,par[i]=i;
}

int Find(int p)
{
    if(par[p]==p)return p;
    else return (par[p]=Find(par[p]));
}

void ADD(int x,int y)
{
    int p=Find(x);
    int q=Find(y);
    if(p==q) return ;
    
    if(ran[p]>ran[q]) par[q]=p, ran[p]+=ran[q];
    else par[p]=q, ran[q]+=ran[p];
}


int main()
{
    Go_
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;

    cin>>n>>m;
    init(n);

    for(i=1;i<=m;i++)
    {
        cin>>p>>q;
        ADD(p,q);
    }

    ct=0;
    for(int i=2;i<=n;i++){
        if(Find(1) != Find(i)) ADD(1,i), ++ct;
    }

    cout<<ct<<'\n';
    
    
}

Measured memory_bytes: 4428
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long h = scan.nextLong();
		int n = scan.nextInt();

		long sum = 0;
		int i;
		for(i = 0; i < n; i++)
			sum += scan.nextLong();

		if(sum >= h)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 45580
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N, K;
	cin >> N >> K;
	vector<int>V(200100, 0);
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		V[a]++;
	}
	sort(V.begin(), V.end(), greater<int>());
	int count = 0;
	for (int i = 0; i < K; ++i) {
		count += V[i];
	}
	cout << N - count << endl;
    return 0;
}

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

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

    int max_f = 1000000;
    ll fac[max_f];
    fac[0] = 1;
    rep(i, 1, max_f)
        fac[i] = (fac[i - 1] * i) % MOD;

    ll c = 0;
    if (n == m) c = 2;
    else if (abs(n - m) == 1) c = 1;
    cout << (c * fac[n] * fac[m]) % MOD << endl;
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M){
	if (N==M) cout << YES << "\n";
	else cout << NO << "\n";
}

// 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)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;
int S[100010];
int main(void){
    int n,q,t,ans=0;

    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&S[i]);

    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&t);
        int Min=0,Max=n-1,center=0;

        for(int j=0;j<17;j++){
            center=(Max+Min)/2;
            if(t>S[center]){
                Min=center;
            }else{
                Max=center;
            }
        }

        if(S[Max]==t)ans++;

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1596
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;


void solve() {
	int N; cin >> N;
	map<int, int>mp;
	REP(i, N) {
		int x; cin >> x;
		if (mp.count(x)) {
			print("NO"); return;
		}
		mp[x]++;
	}
	print("YES");
}

signed main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}

Measured memory_bytes: 12800
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX 1000005
int dp1[MAX+5];
int dp2[MAX + 5];
signed main(void)
{
	int i, j, k;
	rep(i, MAX) {
		dp1[i] = INT_MAX;
	}
	dp1[0] = 0;
	rep(i, MAX) {
		rep(j, MAX) {
			int now = j*(j + 1)*(j + 2)/6;
			if (i + now > MAX) break;
			if (dp1[i] < dp1[i + now]) {
				dp1[i + now] = dp1[i] + 1;
			}
		}
	}
	
	rep(i, MAX) {
		dp2[i] = INT_MAX;
	}
	dp2[0] = 0;
	rep(i, MAX) {
		for(j=1;;j+=2) {
			int now = j*(j + 1)*(j + 2) / 6;
			if (i + now > MAX) break;
			if (now % 2 == 0) continue;
			if (dp2[i] < dp2[i + now]) {
				dp2[i + now] = dp2[i] + 1;
			}
		}
	}
	//rep(i, 43) {
	//	printf("dp2[%d] = %d\n",i, dp2[i]);
	//}
	while (1) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		writerLn(dp1[n], dp2[n]);
	}
	return 0;
}

Measured memory_bytes: 10944
def rating(n):
	if(n < 600):
		print(8)
	elif(n < 800):
		print(7)
	elif(n < 1000):
		print(6)
	elif(n < 1200):
		print(5)
	elif(n < 1400):
		print(4)
	elif(n < 1600):
		print(3)
	elif(n < 1800):
		print(2)
	elif(n < 2000):
		print(1)
a = int(input())
rating(a)

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i=(a); i<(n); i++)

int main() {
    string s;
    cin >> s;

    int ans = 0;
    rep(i, s.size()) {
        REP(j, i, s.size()) {
            bool is_acgt = true;
            REP(k, i, j+1) is_acgt &= s[k] == 'A' || s[k] == 'C' || s[k] == 'G' || s[k] == 'T';
            if(is_acgt) ans = max(ans, j-i+1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
# ABC084 C - Special Trains
N = int(input())

C = []
S = []
F = []

for i in range(N-1):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N):
    ans = 0
    for j in range(i,N-1):
        if j == i:
            ans += S[i]
        if S[j] > ans:
            ans = S[j]
        elif ans%F[j]==0:
            pass
        else:
            ans += F[j] - ans%F[j]
        ans += C[j]
    print(ans)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    LL A, B, K;
    cin >> A >> B >> K;
    LL A2 = max(0LL, A - K);
    K = max(0LL, K - A);
    B = max(0LL, B - K);
    std::cout << A2 << " " << B << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
struct Node {
	int key;
	Node *p, *l, *r;
};
Node *root;
void insert(int key_) {
	Node *x = root, *y = 0, *z;
	z = (Node*)malloc(sizeof(Node));
	z->key = key_, z->l = 0, z->r = 0;
	while (x) y = x, x = (z->key < x->key) ? x->l : x->r;
	z->p = y;
	if (!y) root = z;
	else if (z->key < y->key) y->l = z;
	else y->r = z;
}
void walk1(Node *x) { if (!x) return; walk1(x->l); printf(" %d", x->key); walk1(x->r); }
void walk2(Node *x) { if (!x) return; printf(" %d", x->key); walk2(x->l); walk2(x->r); }
int n, v; char c[8];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", &c);
		if (c[0] == 'i') scanf("%d", &v), insert(v);
		else walk1(root), printf("\n"), walk2(root), printf("\n");
	}
}

Measured memory_bytes: 26132
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(b%a == 0)
      System.out.println(a+b);
    else
      System.out.println(b-a);
  }
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n; cin>>n; cout<<180*(n-2)<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
    int t;
    cin>>t;
    for(int T=0;T<t;T++){
        int n,ans=0;
        cin>>n;
 
        priority_queue<pair<int,int>> lx,rx;
        priority_queue<int> que;
        int k,l,r;
        for(int i=0;i<n;i++){
            cin>>k>>l>>r;
            ans+=min(l,r);
            if(l>r){
              lx.push({k,l-r});
            }
            if(l<r){
              rx.push({-k,r-l});
            }

        }
        int lp=lx.size();
        for(int i=lp-1;i>=0;i--){
            while(!lx.empty()&&lx.top().first>i){
                que.push(lx.top().second);
                lx.pop();
            }
            if(!que.empty()){
                ans+=que.top();
                que.pop();
            }
        }
        while(!que.empty())que.pop();
        for(int i=lp;i<n;i++){
            while(!rx.empty()&&-rx.top().first<=i){
                que.push(rx.top().second);
                rx.pop();
            }
            if(!que.empty()){
                ans+=que.top();
                que.pop();
            }
        }
        cout<<ans<<endl;
    }

     }


 


 






    





      

        


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/11  Problem: ABC 089 D / Link: http://abc089.contest.atcoder.jp/tasks/abc089_d  ----- */

struct Cumusum {
	vector<LL>csum;

	Cumusum(vector<LL>&a) {
		csum.assign((int)a.size() + 1, 0);
		for (int i = 0; i < (int)a.size(); i++) {
			csum[i + 1] = csum[i] + a[i];
		}
	}
	LL query(int l, int r) {
		return csum[r] - csum[l];
	}
};
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL H, W, D; cin >> H >> W >> D;
	vector<vector<LL>> a(H, vector<LL>(W));
	vector<PII>reva(H*W);
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> a[i][j];
			a[i][j]--;
			reva[a[i][j]] = PII(i, j);
		}
	}
	// L<=R
	vector<Cumusum> cumvec;
	auto f = [&](int s, int t) {
		LL x = reva[s].first - reva[t].first;
		LL y = reva[s].second - reva[t].second;
		LL c = abs(x) + abs(y);
		return c;
	};
	FOR(i, 0, D) {
		vector<LL>cost;
		for (int j = i; j + D < H * W; j += D) {
			int nx = j + D;
			cost.push_back(f(j, nx));
		}
		cost.push_back(0);
		cumvec.push_back(Cumusum(cost));
	}
	int Q; cin >> Q;

	FOR(_, 0, Q) {
		LL L, R; cin >> L >> R;
		L--, R--;
		LL ans = cumvec[L%D].query(L / D, R / D);
		cout << (ans) << "\n";
	}




	return 0;
}


Measured memory_bytes: 7476
H, W = map(int, input().split())
maze = []
maze.append('-'*(W+2))
for _ in range(H):
    S = input()
    maze.append('-'+S+'-')
maze.append('-'*(W+2))
# print(maze)

new_maze = [['' for _ in range(W)] for _ in range(H)]
for i in range(1, H+1):
    for j in range(1, W+1):
        if maze[i][j] == '.':
            count = 0
            for k in [-1, 0, 1]:
                for l in [-1, 0, 1]:
                    if k == 0 and l == 0:
                        continue
                    if maze[i+k][j+l] == '#':
                        count += 1
            new_maze[i-1][j-1] = str(count)
        else:
            new_maze[i-1][j-1] = '#'
    print(*new_maze[i-1], sep='')
# print(new_maze)


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;
void Sol1()
{
	int x1, x2, x3, x4, x5;
	cin >> x1 >> x2 >> x3 >> x4 >> x5;

	int res = 0;
	if (x1 == 0)
		res = 1;
	else if (x2 == 0)
		res = 2;
	else if (x3 == 0)
		res = 3;
	else if (x4 == 0)
		res = 4;
	else if (x5 == 0)
		res = 5;
	cout << res << endl;

}
int main()
{
    Sol1();
    //Sol2();
    //Sol3();
    //Sol4();
    //Sol5();
    //Sol6();
}

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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	map<int,int>m;
	int a,b,c;
	cin >> a >> b >> c;
	m[a]++ , m[b]++ , m[c]++;
	cout << m.size();
}







Measured memory_bytes: 256
package main
import . "fmt"
func main() {
  var n,a,b,s,u int
  Scan(&n,&a,&b)
  s = 0
  u = 1 + n/1000
  if n == 10000 { u = 10 }
  for i:=0;i<u;i++ {
    if i > b { break }
    mi := 1000*i
    for j:=0;j<10;j++ {
      if i+j > b { break }
      mj := mi + 100*j
      if mj > n { break }
      for k:=0;k<10;k++ {
        if i+j+k > b { break }
        mk := mj + 10*k
        if mk > n { break }
        for l:=0;l<10;l++ {
          if i+j+k+l > b { break }
          if i+j+k+l < a { continue }
          ml := mk + l
          if ml <= n { s+= ml }
        }
      }
    }
  }
  if n == 10000 && a == 1 { s+= 10000 }
  Println(s)
}

Measured memory_bytes: 512
#include<stdio.h>

int main (void){
    int n,i,roop;
    int gyou,plus,basyo;
    int hairetu[100][100];//???????????????
    
    
    //????????°n????????????
    scanf("%d",&n);
    
    //0??£??\
    for(i=0;i<n;i++){
        for(roop=0;roop<n;roop++){
            hairetu[i][roop]=0;
        }
    }

    for(i=0;i<n;i++){
        //????????????[1]?????°
        scanf("%d %d",&gyou,&plus);
        gyou=gyou-1;//???????????????1????????????
        
        //1???????????´???
        for(roop=0;roop<plus;roop++){
            scanf("%d",&basyo);
            basyo=basyo-1;//???????????????1????????????
            hairetu[gyou][basyo]=1;
        }
    }
    
    //printf
    for(i=0;i<n;i++){
        for(roop=0;roop<n;roop++){
            printf("%d",hairetu[i][roop]);
            if(roop<n-1){
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e5+10;
typedef long long LL;

vector<int> v[N];
int a[N];
int b[N];

int dp[1<<15];

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>a[i];
        int c;
        cin>>c;
        for(int j=1;j<=c;j++)   
        {
            int u;
            cin>>u;
            u--;
            b[i]|=(1<<u);
        }
        //cout<<b[i]<<endl;
    }


    for(int i=1;i<=m;i++)
    {
        int u=b[i];

        for(int j=0;j<(1<<n);j++)
        {
            if(j==0||dp[j])
            {
                if(dp[u|j])
                {
                    dp[u|j]=min(dp[u|j],dp[j]+a[i]);
                }
                else
                {
                    dp[u|j]=dp[j]+a[i];
                }
            }
        }
    }

    if(dp[(1<<n)-1])
        cout<<dp[(1<<n)-1]<<endl;
    else
        cout<<-1<<endl;
    

    
    //system("pause");
}

Measured memory_bytes: 6012
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
long x,h;
while(cin>>x){
cin>>h;
if(x==0)break;
printf("%.6f\n",x*x+x*sqrt(x*x+4*h*h));
}
return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A;
  vector<bool> Result(1000001, true);
  vector<int> Result_int(1000001, 0);
  set<int> check;
  int tmp=0;
  for(int i=0; i<N; i++){
    cin >> tmp;
    A.push_back(tmp);
    check.insert(tmp);
  }
  sort(A.begin(), A.end());
  int ans=0;
  for(int i=0; i<N; i++){
    if(Result.at(A.at(i))){
      for(int j=1; A.at(i)*j<1000001; j++){
        Result.at(A.at(i)*j) = false;
        Result_int.at(A.at(i)*j)++;
      }
    }else{
      Result_int.at(A.at(i))++;
    }
  }
  for(auto value : check){
    if(Result_int.at(value) == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 17500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)100100100;

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
int main() {
    ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    
    int di=GetDigit(N);
    int sum=0;
    if(di>1)sum+=9;
    if(di>3)sum+=900;
  	if(di>5)sum+=90000;
    if(di==1 || di==3 || di==5){
        sum+=N-pow(10,di-1)+1;
    }
    cout << sum;
}

/*



 */



Measured memory_bytes: 512
<?php
list($n, $m) = explode(" ", trim(fgets(STDIN)));

$a = array();
$b = array();

for ($i = 0; $i < $n; $i++)
  $a[$i] = explode(" ", trim(fgets(STDIN)));

for ($i = 0; $i < $m; $i++)
  $b[$i] = trim(fgets(STDIN));

for ($i = 0; $i < $n; $i++) {
  $c = 0;
  for ($j = 0; $j < $m; $j++)
    $c += ($a[$i][$j] * $b[$j]);
  echo "$c\n";
}



Measured memory_bytes: 10968
import std.stdio, std.array, std.conv, std.string, std.algorithm;

void main() {
  int[] mountain = new int[10];

  for (int i = 0; i < 10; i++) {
    mountain[i] = readln.chomp.to!int;
  }

  mountain.sort!("a > b")[0..3].map!(to!string).join("\n").writeln;
}

Measured memory_bytes: 1068
import numpy as np
n=int(input())
l=list(map(int,input().split()))


arr=np.array(l)
arr2=np.append(np.hstack((0,arr)),0)

dif=np.diff(arr2).tolist()
differ=np.sum(np.abs(dif))
for i in range(1,n+1):
    difference=abs(dif[i]+dif[i-1])-abs(dif[i])-abs(dif[i-1])
    print(differ+difference)

   


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

int main()
{
  string s,t;
  cin >> s;
  cin >> t;
  long long int count=0;
  for(long long int i=0;i<s.length();i++)
  {
    if(s[i]==t[i])
    {
      count++;
    }
  }
  cout << count << endl;
}

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

int main(){
    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    set<int> s(a.begin(),a.end());
    int k=s.size();
    if((n-k)%2==0) cout<<k<<endl;
    else cout<<k-1<<endl;
}

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

using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    int n1 = s.length(), n2 = t.length();
    int ans = 10001;
    for(int i = 0; i <= n1 - n2; ++i){
        int k = 0;
        for(int j = i; j < n2 + i; ++j)
            if(s[j] != t[j - i])
                ++k;
        if(k < ans)
            ans = k;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    lint n; cin>>n;
    vector<string> s(n);
    REP(i,n) cin>>s[i];
    lint a1= 0, b1=0, ans = 0;
    bool flag = true;
    REP(i,n){
        if(s[i][0]=='B') {
            b1++;  
        } 
        if(s[i][s[i].length()-1]=='A'){
            a1++; 
        }
        if(s[i][0]=='B' && s[i][s[i].length()-1]!='A'){
            flag = false;
        } else if(s[i][0]!='B' && s[i][s[i].length()-1]=='A'){
            flag = false;
        }
        REP(j,s[i].length()){
                if(j!=s[i].length()&&s[i][j]=='A'&&s[i][j+1]=='B') ans++; 
        }
    }
    if(a1!=0&&b1!=0&&flag == true){
        ans += min(a1,b1)-1;
    } else {
        ans+= min(a1,b1);
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#define ll long long
using namespace std;

int main(void){
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    ll cnt = b - a;
    for(int i = 0; i < n; i++){
        ll cc = n - 1 - i;
        ll mi = (i - cc) * c + cc * (c - d);
        ll mx = (i - cc) * c + i * (d - c);
        if(cnt <= mx && cnt >= mi){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  string a[N];
  string b[M];
  for(int i=0;i<N;i++) cin >> a[i];
  for(int i=0;i<M;i++) cin >> b[i];

  for(int i=0;i<=N-M;i++){
    for(int j=0;j<=N-M;j++){
      bool check = true;
      for(int k=0;k<M;k++){
        for(int l=0;l<M;l++){
          if(a[i+k][j+l] != b[k][l]) check = false;
        }
      }
      if(check){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int M = in.nextInt();
        List<Integer>[] adj = new ArrayList[N+1];
        for(int i = 0; i < N+1; i++) {
            adj[i] = new ArrayList<>();
        }
        for(int i = 0; i < M; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            adj[a].add(b);
            adj[b].add(a);
        }
        int[] parent = new int[N+1];
        Queue<Integer> myq = new ArrayDeque<>();
        myq.offer(1);
        while(myq.size() > 0) {
            int top = myq.poll();
            for(int i : adj[top]) {
                if(parent[i] == 0) {
                    parent[i] = top;
                    myq.add(i);
                }
            }
        }

        System.out.println("Yes");
        for(int i = 2; i < N+1; i++) {
            System.out.println(parent[i]);
        }
    }
}

Measured memory_bytes: 77452
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double P(int x, int K){
  int n = 0;
  while (x < K){
    n++;
    x *= 2;
  }
  return 1.0 / (double)pow(2, n);
}

int main(){
  int N, K;
  cin >> N >> K;
  double prob = 0;
  for (int i=1; i<=N; i++){
    prob += (1.0/(double)N) * P(i, K);
  }
  
  cout << fixed << setprecision(10) << prob << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

inv_A=A[::-1]

b = [0]*N
b[0]=inv_A[0]
for i in range(1,N):
    b[i] = (b[i-1]+inv_A[i])%mod
inv_b = b[::-1]

print( sum(A[i]*inv_b[i+1]%mod for i in range(0,N-1))%mod )

Measured memory_bytes: 94140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

//ここから

void solve(){
  int n;
  cin>>n;
  vector<ll>a(n);
  ll sum=0,minv=1e9;
  int cnt=0;
  rep(i,n){
    cin>>a[i];
    sum+=abs(a[i]);
    if(a[i]<0)++cnt;
    chmin(minv,abs(a[i]));
  }
  if(cnt%2==0)cout<<sum;
  else cout<<sum-2*minv;
}

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


Measured memory_bytes: 1024
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())printf("%d ",v[_]);cout<<"\n";}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n=4;
	vi in(n);
	rep(i,n)cin>>in[i];
	vi t={1,4,7,9};
	sort(all(in));
	if(in==t)yes;
	else no;
}









Measured memory_bytes: 256
#[allow(dead_code)]
fn main() {
    let (k, t) = (i::u(), i::u());
    let mut a = i::iv(t);

    if t == 1 {
        println!("{}", k - 1);
        return;
    }

    a.sort();
    a.reverse();

    let first = a[0];
    let rest = a.iter().sum::<i64>() - first;
    println!("{}", max(0, first - rest - 1));
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
x, y = map(int, input().split())
# 文字列の入力
if x+y == 2:
  prize = 1000000
else:
  prize = sum([100000 * (4-rank) if rank < 4 else 0 for rank in [x,y]])
# 出力
print("{}".format(prize))

Measured memory_bytes: 2940
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846
#ifdef LOCAL
#include <sys/types.h>
#include <sys/timeb.h>
#include <intrin.h> 
#include <thread>
#else
#include <sys/time.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int h[100000];

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	REP(i, n)scanf("%d", h + i);
	sort(h, h + n);
	int ans = 2000000000;
	REP(i, n - k + 1) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
int a[100005];
//ll t[100005];
int main()
{
   cin>>n>>k;
   for(int i=0;i<n;i++)
   {
    cin>>a[i];
   }
   int ans=(int)1e9+5;
   for(int i=0;i<n-k+1;i++)
   {
       int l=i;
       int r=i+k-1;
       ans=min(ans,min(abs(a[l])+abs(a[r]-a[l]),abs(a[r])+abs(a[r]-a[l])));
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int arr[100001];
int p[100001];
int find(int a){
if(a==p[a])
    return a;
else
    return p[a]=find(p[a]);


}
void uni(int a,int b){
a=find(a);
b=find(b);
if(a==b)return;
p[b]=a;

}
int main(void){
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++){
    cin >> arr[i];
    p[i]=i;
}
for(int i=1;i<=m;i++){
    int a,b;
    cin >> a >> b;
    uni(a,b);
}
int res=0;
for(int i=1;i<=n;i++){
    if(find(i)==find(arr[i]))
        res++;
}
cout << res;
}

Measured memory_bytes: 1024
x,y = gets.chomp.split(" ").map(&:to_i)
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

if a.include?(x) && a.include?(y)
  puts "Yes"
elsif b.include?(x) && b.include?(y)
  puts "Yes"
elsif x == 2 && y == 2
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
 
    vector<int> cnt(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a, --b;
        ++cnt[a];
        ++cnt[b];
    }
 
    bool ok = true;
    for (int i = 0; i < n; ++i) {
        ok &= !(cnt[i] & 1);
    }
 
    if (ok) {
        puts("YES");
    } else {
        puts("NO");
    }
}


Measured memory_bytes: 640