akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
int main() {
	int N;
	int  sum = 0, ans = 0;
	scanf("%d", &N);
	int *A = (int *)malloc(sizeof(int)*(N + 2));
	A[0] = 0;
	A[N + 1] = 0;
	for (int i = 1; i < N + 1; i++)
	{
		scanf("%d", &A[i]);
	}
	for (int i = 1; i < N + 2; i++)
	{
		sum += abs(A[i] - A[i - 1]);
	}

	for (int i = 1; i < N + 1; i++)
	{
		ans = sum - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]);
		printf("%d\n", ans);
		ans = 0;
	}

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define PI acos(-1)
typedef long long ll;
using namespace std;
template<class Int>
Int gcd(Int a, Int b)
{
    return (b == 0 ? abs(a) : gcd(b, a % b));
}
int main()
{
    cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif
    int n;
    ll ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            for(int k = 1; k <= n; k++)
                ans += gcd(gcd(i, j), k);
    cout << ans;
}

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


int main() {
  int n, a=0, w=0, t=0, r=0;  cin >> n;

  rep (i, n) {
    string s;  cin >> s;
    if (s == "AC") ++a;
    if (s == "WA") ++w;
    if (s == "TLE") ++t;
    if (s == "RE") ++r;
  }

  printf ("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", a, w, t, r);
}

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main ()
{
    int N;
    cin >> N;
    vector<int> L;
    int temp;
    int max;
    int sum=0;
    for(int i=0;i<N;i++){
        cin >> temp;
        L.push_back(temp);
    }
    sort(L.begin(),L.end() );
    max =L.back();
    for(int i=0;i<N-1;i++){
        sum+=L.at(i);
    }
    string output;
    if(max<sum){
        output="Yes";
    }else{
        output="No";
    }
    cout << output << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
typedef long long int ll;
typedef long double ld;
const ll N = 1e5+9;
// const ll m = 1e9 + 7;
// const ll inf= 1e14;
const ll mod =998244353;
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define pld pair<ld,ld>
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
ll a[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
    int t = 1;
    // cin>>t;
    while(t--){
        ll n;cin>>n;
        for(int i = 0;i<n;i++){
            cin>>a[i];
        }
        ll su = 0,ans = 0;
        for(int i = 0;i<n;i++){
            if(a[i]==0){
                ans+=(su/2);
                su = 0;

            }
            else{
                su+=a[i];
            }
        }
        if(su){
            ans+=su/2;
        }
        cout<<ans<<'\n';
    }
}

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

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

  int ans = 0, cnt = 0, r = 0;
  ll tmp = n;
  while (tmp > 0) {
    r = tmp % 10;
    ans += r;
    tmp /= 10;
    ++cnt;
  }
  ans = max(ans, --r + 9 * --cnt);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<queue>
#define N 3005
using namespace std;
vector<int> G[N];
int n,a[N],sg[N],mex[N],d[N],dfn[N],m;
void topsort()
{
	int i,x; queue<int> Q;
	for(i=1;i<=n;i++)
		if(!d[i]) Q.push(i);
	while(!Q.empty()){
		x=Q.front(),Q.pop(),dfn[++m]=x;
		for(i=0;i<G[x].size();i++)
			if(!(--d[G[x][i]]))
				Q.push(G[x][i]);
	  }
}
int main()
{
	int i,j,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<n;i++){
		scanf("%d %d",&x,&y);
		if(a[x]>a[y]) G[x].push_back(y),d[y]++;
		if(a[y]>a[x]) G[y].push_back(x),d[x]++;
	  }
	topsort();
	for(i=n;i>=1;i--){
		for(j=0;j<G[dfn[i]].size();j++)
			mex[sg[G[dfn[i]][j]]]=i;
		for(j=0;mex[j]==i;j++);
		sg[dfn[i]]=j;
	  }
	for(i=1;i<=n;i++)
		if(sg[i]) printf("%d ",i);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
int MOD=1000000007;
int f[]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597};
signed main(){
    int h,w,k;cin>>h>>w>>k;
    vector<vector<int>> dp(h+5,vector<int>(w+5,0));
    dp[0][1]=1;
    rep1(i,h){
        rep1(j,w){
            //dp[i][j]=dp[i-1][j]+dp[i-1][j-1]+dp[i-1][j+1];
            if(j==1){
                dp[i][j]+=(f[w-1])*dp[i-1][j+1]+dp[i-1][j]*(f[w]);
            }
            else if(j==w){
                dp[i][j]+=(f[w-1])*dp[i-1][j-1]+dp[i-1][j]*(f[w]);
            }
            else{
                dp[i][j]+=dp[i-1][j]*f[j]*f[w-j+1];
                dp[i][j]%=MOD;
                dp[i][j]+=dp[i-1][j-1]*f[j-1]*f[w-j+1];
                dp[i][j]%=MOD;
                dp[i][j]+=dp[i-1][j+1]*f[j]*f[w-j];
            }
            dp[i][j]%=MOD;
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    cout<<dp[h][k]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N, M;
  cin >> N >> M;
  if(N == M) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return num
}

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

func isTarget(i, j, dx int) int {
	if dx == i+j {
		return 1
	}
	return 0
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	l := make([]int, n)
	r := map[int]int{}
	for i := 0; i < n; i++ {
		a := nextInt()
		l[i] = i + a
		if i > a {
			r[i-a]++
		}
	}

	count := 0
	for i := 0; i < n; i++ {
		v, ok := r[l[i]]
		if ok {
			count += v
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 14288
#include <iostream>
#include <unordered_map>
using namespace std;
#define ll long long
const ll N = 2e5+507;
ll n,k,i,ratie,rotiri,y,salt,x,k1,p,a[N],b[N],c[N];
unordered_map <ll,ll> m;
int main()
{
    cin>>n>>k;
    for (i=1;i<=n;++i)
        cin>>a[i];
    b[++k1]=1;
    m[1]=1;
    x=a[1];
    salt=2;
    m[x]=salt;
    while (1)
    {
        b[++k1]=x;
        x=a[x];
        salt++;
        if (m[x])
        {
            y=x;
            ratie=salt-m[x];
            break;
        }
        else m[x]=salt;
    }
    if (k<=m[y]-1) cout<<b[k+1]<<"\n";
    else
    {
        for (i=m[y];i<=k1;++i)
             c[++p]=b[i];
        k=k-(m[y]-1);
        rotiri=k/ratie;
        cout<<c[k-ratie*rotiri+1]<<"\n";
    }
}


Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<>());
    deque<lint> q;
    q.push_back(a[1]);
    lint ret = a[0];
    for (int i = 2; i < n; ++i) {
        q.push_back(a[i]);
        ret += q.front();
        if (i % 2 == 1)
            q.pop_front();
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 5508
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        long B = sc.nextLong();
        long N = sc.nextLong();

        System.out.println(solve(A, B, N));
    }

    private static long solve(int A, long B, long N) {
        long x=Math.min(B-1, N);

        double val = Math.floor(A*x);

        return (long)(A*x/B) -  A*((long)(x/B));
    }
}

Measured memory_bytes: 35756
import java.util.*;
public class Main {
	private static int ans[];
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	String s = sc.next();
    	int q = sc.nextInt();

    	TreeSet[] segs = new TreeSet[26];
    	char[] d = s.toCharArray();
    	for (int i=0;i<26;i++){
    		segs[i]=new TreeSet();
    		segs[i].add(510000);
    	}
    	for (int i=0;i<n;i++){
    		segs[(int)d[i]-'a'].add(i);
    	}
    	for (int i=0;i<q;i++) {
    		int a = sc.nextInt();
    		if (a==1) {
    			int index = sc.nextInt()-1;
    			char oldc = d[index];
    			char newc = sc.next().toCharArray()[0];
    			if (oldc == newc) continue;
    			d[index]=newc;
    			segs[(int)oldc-'a'].remove(index);
    			segs[(int)newc-'a'].add(index);
    			continue;
    		}else{
	            int l = sc.nextInt()-1;
	            int r = sc.nextInt()-1;
	            int ans = 0;
	            for (int j = 0; j < 26; j++) {
	                if ((int)segs[j].ceiling(l) <= r) {
	                    ans += 1;
	                }
	            }
	            System.out.println(ans);
    		}
    	}
    }
} 



Measured memory_bytes: 105804
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int a, b;
	char op;
	cin >> a >> op >> b;

	cout << ((op == '+') ? a + b : a - b) << endl;

	return 0;
}

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

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

void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
}


ll x= 1e18;
std::vector<ll> v;
int main(int argc, char const *argv[])
{
    //file();
    fast();

    v.push_back(100);
    
    for (int i = 0;v.back() < x; ++i)
    {
        v.push_back(v.back() + (v.back() / 100));
    }
    ll n; cin>>n;

    cout<<lower_bound(v.begin(), v.end(), n)-v.begin();
  
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;

int N;
vector<int> A, F;

bool isOK(ll x, ll key) {
    ll k = 0;
    for(int i = 0; i < N; ++i)
        k += max(A[i] - x / F[i], (ll)0);
    return (k <= key ? true : false);
}

ll bn_search(ll key) {
    ll ok = 1e12 + 1;
    ll ng = -1;

    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if(isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

int main() {
    ll K;
    cin >> N >> K;
    A.resize(N), F.resize(N);
    for(int i = 0; i < N; ++i)
        cin >> A[i];
    for(int i = 0; i < N; ++i)
        cin >> F[i];

    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<int>());

    cout << bn_search(K) << endl;
    return 0;
}


Measured memory_bytes: 1792
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!T;r.popFront;}}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);
  int[] b; readA(n, b);
  int[] c; readA(n, c);

  auto as = a.sort(), cs = c.sort();

  auto r = 0L;
  foreach (bi; b)
    r += as.lowerBound(bi).length * cs.upperBound(bi).length;

  writeln(r);
}


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

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];
    sort(s.begin(), s.end());
    string ans = "";
    for (int i = 0; i < n; i++)
        ans += s[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    H = list(map(int, input().split()))

    INF = 10**4+10
    dp = [INF]*(N+10)
    dp[0] = 0
    dp[1] = abs(H[1] - H[0])
    for i in range(2, N):
        dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))
    
    print(dp[N-1])


if __name__ == "__main__":
    solve()

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int A, B, C, D, E, F;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> A >> B >> C >> D >> E >> F;
    int w, s;
    int ans_w = INF, ans_s = 0;
    double concentration = -1.0;
    rep(a, 0, 31) {
        rep(b, 0, 31) {
            if (a == 0 && b == 0) continue;
            w = 100*A*a + 100*B*b;
            rep(c, 0, 101) {
                rep(d, 0, 101) {
                    s = C*c + D*d;
                    if (s + w <= F) {
                        if (E * w >= s * 100) {
                            if (((double)s)/((double)s+(double)w) > concentration) {
                                concentration = ((double)s)/((double)s+(double)w);
                                ans_w = w;
                                ans_s = s;
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans_w + ans_s << " " << ans_s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------
ll xx[100010], yy[100010];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    for (ll i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    for (ll i = 0; i < m; i++)
    {
        cin >> y[i];
    }
    vector<ll> rx(n - 1, 0), ry(m - 1, 0);
    for (ll i = 0; i < n - 1; i++)
    {
        rx[i] = (x[i + 1] - x[i]) % MOD;
    }
    for (ll i = 0; i < m - 1; i++)
    {
        ry[i] = (y[i + 1] - y[i]) % MOD;
    }
    xx[0] = rx[0];
    yy[0] = ry[0];
    for (ll i = 1; i < n - 1; i++)
    {
        (xx[i] += (xx[i - 1] + (rx[i] * (i + 1) % MOD)) % MOD) %= MOD;
    }
    for (ll i = 1; i < m - 1; i++)
    {
        (yy[i] += (yy[i - 1] + (ry[i] * (i + 1) % MOD)) % MOD) %= MOD;
    }
    ll sum_x = 0, sum_y = 0;
    for (ll i = 0; i < n - 1; i++)
    {
        (sum_x += xx[i]) %= MOD;
    }
    for (ll i = 0; i < m - 1; i++)
    {
        (sum_y += yy[i]) %= MOD;
    }
    cout << sum_x * sum_y % MOD << endl;
}


Measured memory_bytes: 4992
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef  long long LL;
typedef  vector<int> VI;
typedef  vector<double> VD;
typedef  string STR;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define MK make_pair
#define PB push_back
#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 COUT(a) cout<<a<<endl
#define POW2(a) pow(a, 2.0)
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(c) REP(i,SZ(c))cerr<<#c<<i<<"="<<(c[i])<<endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int MOD = 1000000007;
int main()
{

	int n;
	while (cin >> n)
	{
	int count=0;
	REP(a, 10)
	{
		REP(b, 10)
		{
			REP(c, 10)
			{
				REP(d, 10)
				{
					if ((a + b + c + d) == n)count++;
				}
			}
		}
	}
	COUT(count);
	}
#ifdef _DEBUG
	while(1);
#endif // _DEBUG

	return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>

int min(int a, int b) {
    return a < b ? a : b;
}

int main() {
    int n, k;
    int s = 1;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++) {
        s = min(2 * s, s + k);
    }
    printf("%d", s);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    string s;
    cin>>s;
    vector<string> v={"maerd","remaerd","esare","resare"};
    reverse(All(s));
    int n = s.size();
    string a="";
    for(int i=0;i<n;i++){
        a+=s[i];
        for(string d:v){
            if(a==d){
                a="";
            }
        }
    }
    if(a==""){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

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

  VI ans(n,0);
  int tmp;
  REP(i, n - 1) {
    cin >> tmp;
    ans[tmp - 1]++;
  }

  REP(i,n){
    ANS(ans[i]);
  }

  return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int main()
{
    int a,b,c,d,e;
    cin>>a>>b;
    for(int i=0;i<=a;i++)
    {
        if((b-2*i)%4==0&&(b-2*i)/4+i==a)
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>

int main (void) {
    int faces[6], q;
    int input[2];
    int top, front, right;
    int sheet[6][5] = {{2, 3, 5, 4, 2},
                       {1, 4, 6, 3, 1},
                       {1, 2, 6, 5, 1},
                       {1, 5, 6, 2, 1},
                       {1, 3, 6, 4, 1},
                       {2, 4, 5, 3, 2}};

    for (int i=0; i<6; i++) {
        scanf ("%d", faces+i);
    }
    scanf ("%d", &q);

    for (int i=0; i<q; i++) {
        scanf ("%d %d", input, input+1);
        for (int j=0; j<6; j++) {
            if (faces[j]==input[0]) top=j+1;
            else if (faces[j]==input[1]) front=j+1;
        }
        for (int j=0; j<5; j++) {
            if (sheet[top-1][j]==front) {
                right = sheet[top-1][j+1];
                break;
            }
        }

        printf ("%d\n", faces[right-1]);
    }

    return 0;
}




Measured memory_bytes: 2044
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b;
        n--;
        
        while (n-- > 0) {
            b = sc.nextLong();
            a = lcm(a, b);
        }
        
        System.out.println(a);
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) return a;
        
        return gcd(b, a % b);
    }
}

Measured memory_bytes: 23892
from itertools import accumulate
import bisect

N = int(input())
l = list(accumulate(range(1, 20)))
ans = 0

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

p = prime_decomposition(N)
dic = {}
for v in p:
    if not v in dic:
        dic[v] = 0
    dic[v] += 1

for v in dic.values():
    i = bisect.bisect_right(l, v)
    ans += i

print(ans)

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int>> g(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a].pb(b); g[b].pb(a);
  }
  
  vector<int> near(n,-2);
  queue<int> que;
  
  que.push(0);
  near[0]=-1;
  
  while(!que.empty()){
    int x=que.front();
    que.pop();
    
    for(auto nx:g[x]){
      if(near[nx]!=-2) continue;
      que.push(nx);
      near[nx]=x;
    }
  }
  cout<<"Yes"<<endl;
  rep(i,n-1) cout<<near[i+1]+1<<endl;
}


Measured memory_bytes: 10188
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define NUM 1000000010
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<int> x(n),y(n);
    rep(i,n) cin>>x[i]>>y[i];
    ld sum=0,dist;
    rep(i,n){
        repi(j,i+1,n){
            dist=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
            sum+=sqrt(dist);
        }
    }
    cout<<fixed<<setprecision(8)<<sum*2/n;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main(){
    int K, X;
    cin >> K >> X;
    if(K*500>=X) Yes;
    else No;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, A[10], B[10];
//---------------------------------------------------------------------------------------------------
map<vector<int>, int> solve(vector<int> v) {
    map<vector<int>, int> res;

    res[v] = 0;
    queue<vector<int>> que;
    que.push(v);

    rep(i, 0, 4) {
        queue<vector<int>> que2;
        while (!que.empty()) {
            auto w = que.front();
            que.pop();

            rep(L, 0, N) rep(R, L + 2, N + 1) {
                vector<int> ww(all(w));
                reverse(ww.begin() + L, ww.begin() + R);
                if (res.count(ww)) continue;

                res[ww] = res[w] + 1;
                que2.push(ww);
            }
        }
        swap(que, que2);
    }

    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) A[i]--;
    rep(i, 0, N) B[i] = i;

    auto a = solve(vector<int>(A, A + N));
    auto b = solve(vector<int>(B, B + N));

    int ans = N - 1;
    fore(p, a) if (b.count(p.first)) chmin(ans, p.second + b[p.first]);
    cout << ans << endl;
}


Measured memory_bytes: 83128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int n;cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    h[0]--;
    for (int i = 1; i < n; i++) {
        if(h[i]<h[i-1]){
            puts("No");
            return 0;
        }
        else if(h[i]==h[i-1]){
        }
        else{
            h[i]--;
        }
    }
    puts("Yes");
    return 0;
}


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

//#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define setbit(x) __builtin_popcount(x)
#define setbitl(x) __builtin_popcountll(x)
#define endl '\n'
#define mod 1000000007
#define INF64 1e18

void solve(){
  int n ;cin>>n;
  bool c[n][n];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>c[i][j];
  int tot=1<<n;
  vi dp(tot);
  dp[0]=1;
  for(int mask=0;mask<tot;mask++){
    for(int w=0;w<n;w++){
      if((mask&(1<<w))==0){
        dp[mask|(1<<w)]+=c[__builtin_popcount(mask)][w]*dp[mask];
        dp[mask|(1<<w)]%=mod;
      }
    }
  }
  cout<<dp[tot-1];
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}

Measured memory_bytes: 11388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

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

  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> M;
  ll ans = 0;

  repr(i, N, 0) {
    cin >> A[i];
  }

  ll idx = N / 2;
  if (N % 2 == 1) idx ++;
  sortd(A);
  for (int i = 0; i < idx; ++i) {
    if (i != idx - 1) ans += A[i];
    M.push_back(A[i]);
  }
  M.push_back(inf<int>);

  ll now = 0;
  for (ll i = idx; i < N; ++i) {
    ans += min(M[now], M[now+1]);
    now += 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 5828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    int n;
    cin >> n;
    vector<int> b(n);
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    vector<int> ans;
    for(int i = 0; i < n; i++){
        int index = -1;
        for(int j = 0; j < b.size(); j++){
            if(j+1 == b[j]){
                index = j;
            }
        }
        if(index == -1){
            cout << -1 << endl;
            return 0;
        }else{
            ans.push_back(b[index]);
            b.erase(b.begin() + index);
        }
    }

    for(int i = 0; i < n; i++){
        cout << ans[n-1-i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define pb     push_back
#define inf     2e18
#define low     -2e18
#define PI        acos(-1.0)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
const int sz = 1e5+9;

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    k = 0;
    cin>>n>>m;
    m  =m*m;
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        x = x*x;
        y = y*y;
        if(x+y<=m)
            k++;
    }
    cout<<k<<endl;
    return 0;
}



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


int main(){
      int n;
    cin>>n;
    string s;
    cin>>s;
    int c=0;
   for(int i=0;s[i];i++){
    if(s[i]=='R') c++;
   }
   int ans = c;
    for(int i=0;i<c;i++){
           if(s[i]=='R') ans--;
    }
    cout<<ans<<endl;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  string s;
  cin >> s;

  char p = s[0];
  ll ans = 0;
  REP1(i, n){
    if(s[i] != p){
      ans++;
      p = s[i];
    }
  }
  ans++;
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int c = N/1000;
    if(N%1000==0) cout << 0 << "\n";
    else cout << (c+1)*1000-N << "\n";
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    rep(a,A+1)rep(b,B+1)rep(c,C+1){
        if(500*a + 100*b + 50*c == X)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;
using ld=long double;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int mod = TEN(9)+7;

int H, W, K;
int a[305][305];
int ans[305][305];
bool yet[305];

signed main()
{
	cin >> H >> W >> K;
	rep(i, H) rep(j, W) {
		char c; cin >> c;
		a[i][j] = (c == '.') ? 0 : 1;
	}

	int p = 1;

	rep(i, H) {
		int counter = 0;
		rep(j, W) {
			counter += a[i][j];
		}

		if (counter == 0) {
			yet[i] = true;
			continue;
		}

		rep(j, W) {
			ans[i][j] = p;
			if (a[i][j] == 1) {
				counter--;
				if (counter > 0) p++;
			}
		}
		p++;
	}

	rep(i, H) {
		if (yet[i]) {
			rep(j, W) {
				bool ok = false;
				range(k, i, H) {
					if (ans[k][j] != 0) {
						ans[i][j] = ans[k][j];
						ok = true;
						break;
					}
				}
				
				if (ok) continue;

				rrange(k, 0, i + 1) {
					if (ans[k][j] != 0) {
						ans[i][j] = ans[k][j];
						ok = true;
						break;
					}
				}
			}
		}
	}

	rep(i, H) {
		rep(j, W) printf("%lld%c", ans[i][j], j == W - 1 ? '\n' : ' ');
	}
}




Measured memory_bytes: 2176
import java.util.*;
import java.util.regex.*;

import static java.lang.Math.*;
import static java.lang.System.out;

// AOJ
public class Main {
	final Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		new Main().AOJ2012();
	}
	
	void AOJ2012(){
		while(sc.hasNext()){
			int e=sc.nextInt(), ans=Integer.MAX_VALUE;
			if(e==0)	break;
			for(int i=0; i*i*i<=e; i++){
				for(int j=0; j*j+i*i*i<=e; j++){
					int k=e-(i*i*i+j*j);
					if(i*i*i+j*j+k==e)	ans=min(ans,i+j+k);
				}
			}
			out.println(ans);
		}
	}
}

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

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t;
	t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}

void solve() {
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	long double ans = 0.5 * w * h;
	cout << ans << ' ';
	if (2 * x == w and 2 * y == h) cout << 1;
	else cout << 0;
}	
 	

Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
dp = [[0 for  j in range(2)] for i in range(n+1)]
dp[1][1] = -a[0]
dp[1][0] = a[0]
for i in range(1,n-1):
    dp[i+1][1] = max(dp[i][0]-a[i], dp[i][1]+a[i])
    dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i])
print(max(dp[n-1][1]-a[n-1], dp[n-1][0]+a[n-1]))

Measured memory_bytes: 98740
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;

    int total = +1;

    if (total >= B)
    {
        cout << 0;
        return 0;
    }
    int n = 0;
    for (n = 0; n < 100; ++n)
    {
        total -= 1;
        total += A;
        if (total >= B)
        {
            break;
        }
    }

    cout << n +1;
    return 0;
}

Measured memory_bytes: 3136
w = input()
mp = dict()
for c in w:
    if c in mp:
        mp[c] += 1
    else:
        mp[c] = 1
ok = True
for k,v in mp.items():
    if v % 2 == 1:
        ok = False
        break
if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;


int main() {
  int n; cin >> n;
  if(n>=1&&n<=1000) cout << 1000-n<< endl;
  else if(n>1000&&n<=2000) cout << 2000-n<< endl;
  else if(n>2000&&n<=3000) cout << 3000-n<< endl;
  else if(n>3000&&n<=4000) cout << 4000-n<< endl;
  else if(n>4000&&n<=5000) cout << 5000-n<< endl;
  else if(n>5000&&n<=6000) cout << 6000-n<< endl;
  else if(n>6000&&n<=7000) cout << 7000-n<< endl;
  else if(n>7000&&n<=8000) cout << 8000-n<< endl;
  else if(n>8000&&n<=9000) cout << 9000-n<< endl;
  else cout << 10000-n << endl;

  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
 
using namespace std;
 
 
int main()
{
  int N, F[50];
 
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> F[i];
  }
  sort(F, F + N);
 
  int cur[50] = {};
 
  auto getCost = [&](int idx)
  {
    int ret = 114514;
    for(int i = 0; i <= idx; i++) {
      for(int j = 0; j < i; j++) {
        ret = min(ret, min(abs(cur[i] - cur[j]), 24 - abs(cur[i] - cur[j])));
 
      }
    }
    return (ret);
  };
 
 
  memset(cur, 0, sizeof(cur));
  bool flag = true;
  for(int j = 0; j < N; j++) {
    int s = F[j], t = 24 - F[j];
 
    cur[j + 1] = s;
    int st = getCost(j + 1);
 
    cur[j + 1] = t;
    int gt = getCost(j + 1);
 
    if(st >= gt) cur[j + 1] = s;
  }
  cout << getCost(N) << endl;
}

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

using namespace std;

class inverse {
    public:
    inverse(int n, int mod);
    ~inverse();
    long long get_inv(int x);
    long long get_fact(int x);
    long long get_invfact(int x);
    long long get_comb(int x, int y);
    
    private:
    int mod;
    long long* inv;
    long long* fact;
    long long* invfact;
};

inverse::inverse(int n, int mod) : mod(mod) {
    inv = (long long *)malloc(sizeof(long long) * (n + 1));
    fact = (long long *)malloc(sizeof(long long) * (n + 1));
    invfact = (long long *)malloc(sizeof(long long) * (n + 1));
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}

inverse::~inverse() {
    free(inv);
    free(fact);
    free(invfact);
}

long long inverse::get_inv(int x) {
    return inv[x];
}

long long inverse::get_fact(int x) {
    return fact[x];
}

long long inverse::get_invfact(int x) {
    return invfact[x];
}

long long inverse::get_comb(int x, int y) {
    return fact[x] * invfact[y] % mod * invfact[x - y] % mod;
}

int main() {
    int n, m = 1000000007, i, j;
    long long ans;
    
    scanf("%d", &n);
    
    inverse inv(n, m);
    
    ans = inv.get_fact(n - 1) * (n - 1) % m;
    
    for (i = 1; i < n / 2; i++) {
        int x = n - 1 - i;
        long long p = inv.get_comb(x - 1, i) * inv.get_fact(x) % m * inv.get_fact(i) % m;
        
        ans -= p;
        if (ans < 0) ans += m;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 23680
$n=<>;
$s=<>;
@s=split//,$s;
$num = 0;
$max = 0;
foreach (@s){
	if($_ eq "I"){
    	$num++;
    }else{
    	$num--;
    }
    if($num>=$max){
    	$max=$num;
    }
}
print $max;


Measured memory_bytes: 384