akhauriyash/Code-Regression huggingface dataset:
n=int(input())
l=list(map(int,input().split()))
x=max(l)
y=min(l)
li=[]
for i in range(y,x+1):
    ans=0
    for j in range(n):
        ans+=(l[j]-i)**2
    li.append(ans)
print(min(li))
    
    

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll b = 0;
  rep(i, n) {
    cin >> a[i];
    b ^= a[i];
  }
  rep(i, n) cout << (b ^ a[i]) << endl;
}

Measured memory_bytes: 4736
n = int(input())
As = list(map(int, input().split()))

result = As[0]
if 0 in As:
    print(0)
else:
    for i in range(n-1):
        result = result*As[i+1]
        if result > 10**18 :
            print(-1)
            break
        else:
            continue
    if result <= 10**18 :
        print(result)

Measured memory_bytes: 21796
#include <iostream>
using namespace std;
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A > B) swap(A, B);
    if (A > C) swap(A, C);
    if (B > C) swap(B, C);
    cout << (C - A) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int D, N; cin >> D >> N;
	int S = 1; for (int i = 0; i < D; i++) S *= 100;
	if (N <= 99) {
		cout << S * N << endl;
	}
	else {
		cout << S * 101 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

// Nが正の数の時は桁数を、0以下の時は0を返す
int digit(long long N){
  int ret = 0;
  while(N > 0) ret++ , N /= 10;
  return ret;
}

void solve(){
  inl(N);
  int ans = inf;
  for(ll i = 1; i * i <= N; i++){
    if(N % i) continue;
    ans = min(ans , max( digit(i) , digit(N / i) ) );
  }  
  out(ans);
}



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

using namespace std;
typedef long long int ll;

#define INF (1e9)

int main() {
    int N, K;
    cin >> N >> K;

    if (N >= 2 * K - 1) {
        cout << "YES" << endl;
        return 0;
    }

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


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[101010], b[101010];
int main()
{
	int num;
	scanf("%d", &num);
	ll sa = 0, sb = 0;
	for (int i = 0; i < num; i++)scanf("%lld", &a[i]), sa += a[i];
	for (int i = 0; i < num; i++)scanf("%lld", &b[i]), sb += b[i];
	if (sa > sb)
	{
		printf("No\n");
		return 0;
	}
	ll ta = 0, tb = 0;
	for (int i = 0; i < num; i++)
	{
		if (a[i] < b[i])ta += (b[i] - a[i] + 1) / 2, tb += (b[i] - a[i]) % 2;
		else tb += a[i] - b[i];
	}
	if (ta > sb - sa || tb > sb - sa)printf("No\n");
	else printf("Yes\n");
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	long long a,b,c,d,x1,x2,y1,y2;
  	cin>>a>>b>>c>>d;
  	x1=a*c;
  	x2=a*d;
  	y1=b*c;
  	y2=b*d;
  	if(x1>x2 && x1>y1 && x1>y2)
    {
		cout<<x1;
    }
  	else if(x2>x1 && x2>y1 && x2>y2)
      cout<<x2;
  	else if(y1>x1 && y1>x2 && y1>y2 )
      cout<<y1;
  else
    cout<<y2;
   
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	string s;
	long long b, c = 0;
	
	cin >> s;
	for(int i = 0; i < s.length(); i++) {
		if(i != 0 && s[i] == 'W') {
			c += b;
			if (s[i-1] == 'W') {
				b = 0;
			} else {
				s[i] = 'B';
				b = b - 1;
			}
		}
		if(s[i] == 'B') {
			b += 1;
		}
	}
	
	cout << c << endl;
	return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    ll n;
    cin >> n;
    if(n%2 == 1) cout << 0 << endl;
    else {
        ll exp = 10, ans = 0;

        while(exp <= n) {
            ans += n/exp;
            exp *= 5;
        }
        cout << ans<< endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MAXN 50000

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

	int n, i, j, k, maxx;
	cin >> n;
	vector<int> a(n);
	maxx = 0;
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < n; i++) {
		for (j = i + 1; (j < n) && (a[j] <= a[j - 1]); j++);
		maxx = max(maxx, j - i - 1);
		i = j - 1;
	}
	cout << maxx << "\n";

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

const int N = 50005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n;
vector <int> g;

int main(){
    cin>>n;
    int x;
    for(int i=1;;i++){
        if((i * (i + 1)) / 2 >= n){
            x = i;
            break;
        }
    }
    for(int i=x;i>=1;i--){
        if(n >= i){
            n -= i;
            g.push_back(i);
        }
    }
    reverse(g.begin() , g.end());
    for(int i=0;i<(int)g.size();i++) cout<<g[i]<<endl;
    return 0;
}


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

using namespace std;

#define DIM 3009
#define INF 1e11+9
#define amen exit(0)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pairll pair<long long,long long>
#define fi first
#define se second
#define ld long double
#define MODULO 1000000007

long long i,j,k,l,n,m,res;

long long dp[DIM][DIM],pr[DIM][DIM];

string s;

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

    dp[1][1]=1;

    for(i=1;i<=n;i++)pr[1][i]=1;

    for(i=2;i<=n;i++){
        for(j=1;j<=i;j++){
            if(s[i-2]=='<')dp[i][j]=pr[i-1][j-1];
            else{
                dp[i][j]=(pr[i-1][n]-pr[i-1][j-1])%MODULO;
                if(dp[i][j]<0)dp[i][j]+=MODULO;
            }
        }
        for(j=1;j<=n;j++){
            pr[i][j]=(pr[i][j-1]+dp[i][j])%MODULO;
        }
    }

    cout<<pr[n][n]<<endl;

    return 0;
}


Measured memory_bytes: 141568
import java.io.*;
import java.util.*;
class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static char[] a;
	
    public static void main(String args[]) throws Exception
    {
		a=sc.next().toCharArray();int n=a.length;
		if(a[0]==a[n-1] && n%2==0)
		{
			out.println("First");
		}
		else if(a[0]==a[n-1] && n%2!=0)
		{
			out.println("Second");
		}
		else if(a[0]!=a[n-1] && n%2==0)
		{
			out.println("Second");
		}
		else
		{
			out.println("First");
		}
		out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) 
	{
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 11796
#include<bits/stdc++.h>
using namespace std;
int qzh[300003][2],ans=301030103;
char c[300003];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>c[i];
        qzh[i][0]=qzh[i-1][0];
        qzh[i][1]=qzh[i-1][1];
        if(c[i]=='W')
            qzh[i][0]++;
        else
            qzh[i][1]++;
    }
    for(int i=1;i<=n;i++)
        //cout<<(qzh[i-1][0]+qzh[n][1]-qzh[i][1])<<endl,
        ans=min(ans,(qzh[i-1][0]+qzh[n][1]-qzh[i][1]));
    cout<<ans;
}

Measured memory_bytes: 2944
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;

public class E512IO {
    private string[] reads;
    private int index;
    public E512IO() {
        Console.SetOut( new StreamWriter(Console.OpenStandardOutput()));
        this.reads = new string[0];
        this.index = 0;
    }
    ~E512IO() { Console.Out.Flush(); }
    private string Next () {
        this.index += 1;
        if (this.index > this.reads.Length) {
            this.reads = Console.ReadLine().Split();
            this.index = 0;
        }
        return this.reads[this.index];
    }
    private string[] NextLines () {
        this.reads = Console.ReadLine().Split();
        this.index = this.reads.Length;
        return this.reads;
    }
    
    public List<int> NextIntList() { return this.NextLines().Select(x => int.Parse(x)).ToList(); }
    public List<long> NextLongList() { return this.NextLines().Select(x => long.Parse(x)).ToList(); }
    public List<double> NextDoubleList() { return this.NextLines().Select(x => double.Parse(x)).ToList(); }
    public List<string> NextStringList() { return this.NextLines().ToList(); }
    public int NextInt() { return int.Parse(this.Next()); }
    public long NextLong() { return long.Parse(this.Next()); }
    public double NextDouble() { return double.Parse(this.Next()); }
    public string NextString() { return this.Next(); }
}

public class Program {
    static void Main (string[] args) {
        E512IO io = new E512IO();
        var n = io.NextInt();
        
        int[] a = io.NextIntList().ToArray();
        int[] t = a.ToArray();
        Array.Sort(t);
        int m = n / 2 - 1;
        for (int i = 0; i < n; ++i) {
            if (a[i] <= t[m]) {
                Console.WriteLine(t[m+1]);
            } else {
                Console.WriteLine(t[m]);
            }
        }
    }
}

Measured memory_bytes: 38108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

ll d=0;
ll nC[300010]={1};
ll comb(ll r){
  if(nC[r]==0) nC[r]=comb(r-1)*(d-r+1)/r;
  return nC[r];
}

int main(){
  ll n,a,b,v[55];
  cin>>n>>a>>b;
  fr(i,n) cin>>v[i];
  sort(v,v+n);reverse(v,v+n);
  db s=0;
  fr(i,a) s+=v[i];
  printf("%.12f\n",s/a);
  if(v[0]==v[a-1]){
    ll ans=0;
    fr(i,n) if(v[i]==v[0]) d++;
    for(int i=a;i<=min(d,b);i++) ans+=comb(i);
    cout<<ans<<endl;
  }
  else{
    int c=0;
    fr(i,n){
      if(v[i]==v[a-1]){
        if(i<a) c++;
        d++;
      }
    }
    cout<<comb(c)<<endl;
  }
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,k,x[100005]={},ans=inf;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> x[i];
  }
  for(int i=0; i<n-k+1; i++) {
    ans=min({ans,abs(x[i]-x[i+k-1])+abs(x[i]),abs(x[i]-x[i+k-1])+abs(x[i+k-1])});
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
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();
    int c=sc.nextInt();
    sc.close();
    boolean isOK=false;
    for(int i=0;i<a;i++){
      if((b*i+c)%a==0){
        isOK=true;
        break;
      }
    }
    if(isOK){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
int main()
{
    char s;
    do
    {
        int sum = 0;
        do
        {
            scanf("%c", &s);
            if (s == '\n')
            {
                break;
            }
            sum = sum + s - '0';
        } while (s != '\n');
        if (sum == 0)
        {
            break;
        }
        printf("%d\n", sum);
    } while (s != 0);
    return 0;
}


Measured memory_bytes: 2052
#include<iostream>
#include<cstdlib>
using namespace std;
int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	while(a>0&&c>0){
		c-=b;
		if(c<=0) {cout<<"Yes"<<endl; exit(0);} 
		a-=d;
		if(a<=0) {cout<<"No"<<endl;exit(0);}	
	}
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int hundiv(int x) {
    int ret = 0;
    while(x % 100 == 0) {
        x /= 100;
        ret++;
    }
    return ret;
}

int main() {
    int d, n;
    cin >> d >> n;
    int cnt = 0;
    int val = 0;
    while(cnt < n) {
        val++;
        if(hundiv(val) == d) cnt++;
    }
    cout << val << endl;
}

Measured memory_bytes: 256
import math
import collections
import itertools

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def resolve():

    N,M=map(int,input().split())
    L=[0]*M
    R=[0]*M
    Lmax=0
    Rmin=10**10
    for i in range(M):
        L[i],R[i]=map(int,input().split())
        Rmin=min(R[i],Rmin)
        Lmax=max(L[i],Lmax)

    print(max(0,Rmin-Lmax+1))

resolve()


Measured memory_bytes: 17116
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());
    int x = Integer.parseInt(sc.next());

    int a[] = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = Integer.parseInt(sc.next());
    }
    Arrays.sort(a);
    int ans = 0;
    for (int i = 0; i < N; i++) {
      x -= a[i];
      if (x >= 0) {
        ans++;
      }
      if (x < 0) {
        break;
      }
    }
    if (x > 0) {
      ans = N - 1;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
 
int main()
{
    int a[10]={0};

    int n,k;
    int ans = 0;
    int flag = 0;
    int x;
    scanf("%d %d",&n,&k);
    for(int i=0;i<k;i++)
    {
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=n;i<1000000;i++)
    {
        int t = i;
        flag = 0;
        while(t)
        {
            int p = t%10;
            if(a[p]!=0)
            {
                flag = 1;
                break;
            }
            t/=10;
        }
        if(flag==1)
            continue;
        else
        {
             ans = i;
             break;
        }
        
    }
    printf("%d",ans);
}

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())

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

edge_dic = defaultdict(int)
for n in range(N):
    edge_dic[al[n]] += 1
dic = sorted(edge_dic.items(), reverse=True)


yoko = 0
tate = 0
for v in dic:
    if yoko == 0:
        if v[1] >= 2:
            yoko = v[0]
            if v[1] >= 4:
                tate = v[0]
                break
    else:
        if v[1] >= 2:
            tate = v[0]
            break
print(yoko * tate)


Measured memory_bytes: 21412
import java.util.*;
import java.io.*;

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

        String s = sc.next();
        long k = Long.parseLong(sc.next());

        char c[] = s.toCharArray();

        char cs = '1';

        for(int i = 0; i < k; i++){
            if(c[i] != '1'){
                cs = c[i];
                break;
            }
        }

        System.out.println(cs);

        sc.close();
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
long long n,cnt,a[23333333];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n; 
	if(n==1){cout<<1;return 0;}
	for(int i=2;i<=n;i++)
	    for(int j=i;j<=n;j+=i)
	        a[j]++;
	for(int i=1;i<=n;i++)cnt+=i*(a[i]+1);
	cout<<cnt<<endl;
}

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


////////// 	Template structure for debugging

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

trace(comma+1, args...);
}

#define print(...) pr(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void pr(const char* name, Arg1&& arg1){
cout << arg1 << endl;
}
template <typename Arg1, typename... Args>
void pr(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cout << arg1 << " "; 
pr(comma+1, args...);
}

void printV(vector<int> &arr)
{
for(int i=0;i<arr.size();i++)cout << arr[i] << " \n"[ i == arr.size()-1 ];
}

///////////////// Fenwick Tree 
// void update(int index,int num){

// 	while(index<=N){
// 		arr[index] += num;
// 		index += index & (-index);
// 		//cout << index << endl;
// 	}

// }

// int sum(int index){

// 	int s = 0;
// 	while(index){
// 		s += arr[index];
// 		index -= index & (-index);
// 	}
// 	return s;
// }

//////////////////////////////////////////////

/////////////////// Type definitions
typedef long long ll;
typedef pair<int,int> pi;
#define f first
#define s second
////////////////////////////////////////////////////////////////////////////

int t;

void solve(){

	

}	

int main(){

	
	int n;
	cin >> n;
	vector<ll> arr(n),dp(n);
	for(int i=0;i<n;i++)cin >> arr[i];
	dp[1] = abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
		dp[i] = min(dp[i-1] + abs(arr[i-1]-arr[i]),dp[i-2] + abs(arr[i]-arr[i-2]));
	cout << dp[n-1] << endl;

}

Measured memory_bytes: 4848
#include<stdio.h>
main(){
  double n;
  while(scanf("%lf",&n)!=EOF){
    if(n<=48.00)printf("light fly");
    else if(n<=51.00)printf("fly");
    else if(n<=54.00)printf("bantam");
    else if(n<=57.00)printf("feather");
    else if(n<=60.00)printf("light");
    else if(n<=64.00)printf("light welter");
    else if(n<=69.00)printf("welter");
    else if(n<=75.00)printf("light middle");
    else if(n<=81.00)printf("middle");
    else if(n<=91.00)printf("light heavy");
    else printf("heavy");
 
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 616
import sys
import os
line = list(map(int, input().split()))
S = line[0] + line[1] + line[2] + line[3]

line1 = list(map(int, input().split()))
T = line1[0] + line1[1] + line1[2] + line1[3]

if S >= T:
    print(S)
else:
    print(T)


Measured memory_bytes: 5600
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [0]*(1<<n)
ans[0] = 1
mod = 10**9 + 7

def popcnt(x):
  ret = 0
  for i in range(n):
    if x & (1<<i):
      ret += 1
  return ret

for bit in range(1<<n):
  if ans[bit]:
    i = popcnt(bit)
    v = 1
    for j in range(n):
      if not bit & v and a[i][j]:
        ans[bit|v] = (ans[bit|v] + ans[bit])%mod
      v <<= 1
print(ans[-1])


Measured memory_bytes: 59740
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(i, m, n) for(int i = m; i < n; i++)
    #define rep3(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    #define COUT(N) cout<<fixed<<setprecision(N)
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;


int main(){
    int R;
    cin >> R;
    cout << M_PI*2*R;
    return 0;
}


Measured memory_bytes: 3788
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort(reverse=True)
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
for i in range(min(len(ans),c)):
  if ans[i]<=r[rcount]:
    ans[i]=r[rcount]
    rcount+=1
print(sum(ans))

Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int>shizuku(N);
    for(int i=0;i<N;i++){
        cin>>shizuku[i];
    }
    reverse(shizuku.begin(),shizuku.end());
    for(int i=0;i<N;i++){
        cout<<shizuku[i];
        if(i<N-1)cout<<" ";
        else cout<<endl;
    }
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){ 
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

int main() {
    int N, M;
    cin >> N >> M;
    cout << ((N == 0 ? 0 : N * (N - 1) / 2) + (M == 0 ? 0 : M * (M - 1) / 2)) << LN;
}


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

class Hello
{
    static void aiueo(int w,int h)
    {
        for(int i=1;i<=w;i++)
        {
            if(i%2==1)Console.WriteLine("{0}{1}",string.Concat(Enumerable.Repeat("#.",h/2).ToArray()),new string('#',h%2));
            else if(i%2==0)Console.WriteLine("{0}{1}",string.Concat(Enumerable.Repeat(".#",h/2).ToArray()),new string('.',h%2));
        }
        Console.WriteLine();
        return;
    }
    static void Main()
    {
        string [] str=Console.ReadLine().Split(' ');
        int w=int.Parse(str[0]);
        int h=int.Parse(str[1]);
        for(int i=0;w!=0||h!=0;i++)
        {
            aiueo(w,h);
            str=Console.ReadLine().Split(' ');
            w=int.Parse(str[0]);
            h=int.Parse(str[1]);
        }
    }
}



Measured memory_bytes: 18296
#include <stdio.h>
#include <string.h>
int main(void){
    char top[100001];
    int count = 0;
    int i;
    scanf("%s",top);

    int length = strlen(top);
        
    for(i=0;i<length;i++){
        if(top[i]=='p')
            count++;
    }
        
    printf("%d\n",length/2-count);
        
    return 0;
}

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

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

int main() {
    int a[4];
    rep(i,4)cin>>a[i];
    cout<<min(a[0], a[1])+min(a[2], a[3])<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int bubbleSort(int A[], int N) {
	int flag = 1;
	int sw = 0;
	int i, j, tmp;
	
	for ( i = 0; flag; i++ ) {
		flag = 0;
		for ( j = N - 1; j >= i +1; j-- ) {
			if ( A[j] < A[j - 1] ) {
				tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main() {
	int A[100];
	int N, i, sw;
	
	scanf("%d", &N);
	for ( i = 0; i < N; i++ ) {
		scanf("%d", &A[i]);
	}
	
	sw = bubbleSort(A, N);
	
	for ( i = 0; i < N; i++ ) {
		if ( i > 0 ) {
			printf(" ");
		}
		printf("%d", A[i]);
	}
	printf("\n");
	printf("%d\n", sw);
	return 0;
}

Measured memory_bytes: 604
#include<iostream>
using namespace std;
int main() {
	int num, price;
	cin >> num >> price;
	for (int i = 0; i <= num; ++i) {
		for (int n = 0; n <= num - i; ++n) {
			int bal = price - 10000 * i - 5000 * n;
			if (bal >= 0 && bal / 1000 == num - i - n) {
				cout << i << " " << n << " " << num - i - n << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    B = list(map(int, (input().split(' '))))

    move = sum(B) - sum(A)
    # A行目が大きい場合は、B行目は+１ずつしかできないので追い越せない。
    if move < 0:
        print('No')
        sys.exit()
    Amove = 0
    Bmove = 0
    # 3 4 2
    # 5 3 4
    for i in range(N):
        # A[i] = 4, B[i] = 3 -> Amove = 1
        if A[i] > B[i]:
            Amove += A[i] - B[i]
        # A[i] = 3, B[i] = 5 -> Bmove = 1
        # A[i] = 2, B[i] = 4 -> Bmove = 1
        elif A[i] < B[i]:
            Bmove += (B[i] - A[i]) // 2
    # Amove = 1, Bmove = 1
    if Amove > Bmove:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 4596
#include <iostream>
using namespace std;
int main() {
	int N, A, B;
	int sum = 0;
	cin >> N >> A >> B;
	// N:10e4, A,B <= 36
	// N = 10000a+1000b+100c+10d+e
	for (int a = 0; a < 10; ++a)
		for (int b = 0; b < 10; ++b)
			for (int c = 0; c < 10; ++c)
				for (int d = 0; d < 10; ++d)
					for (int e = 0; e < 10; ++e)
						if (10000 * a + 1000 * b + 100 * c + 10 * d + e <= N && a + b + c + d + e >= A && a + b + c + d + e <= B) 
 //                           cout << a << b << c << d << e << endl;
							sum += 10000 * a + 1000 * b + 100 * c + 10 * d + e;
						cout << sum << endl;
}

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

int n;
double x[1010], y[1010], r[1010];
double g[1010][1010];
double d[1010];

int main() {
	cin >> x[0] >> y[0] >> x[1] >> y[1];
	r[0] = r[1] = 0.0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> x[i + 2] >> y[i + 2] >> r[i + 2];
	}
	n += 2;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			g[i][j] = max(0.0, sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) - r[i] - r[j]);
		}
	}
	
	using P = pair<double, int>;
	priority_queue<P, vector<P>, greater<P>> pq;
	fill_n(d, 1010, 1e10);
	d[0] = 0.0;
	pq.emplace(0.0, 0);
	while (pq.size()){
		double sum;
		int v;
		tie(sum, v) = pq.top(), pq.pop();
		if (d[v] < sum) continue;
		for (int u = 0; u < n; u++){
			if (d[u] > d[v] + g[v][u]){
				d[u] = d[v] + g[v][u];
				pq.emplace(d[u], u);
			}
		}
	}
	cout << fixed << setprecision(12) << d[1] << endl;
}

Measured memory_bytes: 12400
import java.util.*;
public class Main {
	public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      int k=sc.nextInt();
      int[] p=new int[n];
      for(int i=0;i<n;i++){
      	p[i]=sc.nextInt();
      }
      int sum=0;
      Arrays.sort(p);
      for(int i=0;i<k;i++){
      	sum+=p[i];
      }
      System.out.println(sum);
	}
}

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

long long N, M, color[100000];
vector<int> G[100000];

bool dfs(int now, int c){
	color[now] = c;
	for(int i=0; i<G[now].size(); i++){
		if(color[G[now][i]] == c) return false;
		if(color[G[now][i]] == 0 && !dfs(G[now][i], -c)) return false;
	}
	return true;
}

int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	long long p = 0;
	if(dfs(0, 1)){
		for(int i=0; i<N; i++){
			if(color[i] == 1) p++;
		}
		cout << p*(N-p) - M << endl;
	}else{
		cout << N*(N-1)/2 - M << endl;
	}
	return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

#ifdef OJ
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#else
#define debug(x)
#define debugv(x)
#endif

#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 998244353; //1e9+7;
const int MAXN = 2e5+3;
const int INF = 1e9;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    //int ntest; cin >> ntest; while(ntest--) 
    {
        int n; cin >> n;
        vector<LL> v(n);
        fori(i,n) {
            cin >> v[i];
            if(v[i] == 0) RETURN(0);
        }
        LL ans = 1;
        fori(i,n) {
            LL a = v[i];
            LL mx = (LL)1e18/a;
            if(ans > mx) RETURN(-1);
            ans *= a;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3992
<?php
  
  $a = fgets(STDIN);
  $b = 500;
  $c = 5;

  $a500 = intdiv($a, $b);
  $ans1 = $a500 * 1000;
  $amari =  $a - ($a500 * 500);
  $ans2 = 0;
  if ($amari != 0){
    $ans2 = 5 * intdiv($amari,5);
  }

  echo $ans1 + $ans2;


Measured memory_bytes: 4604
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int k = scan.nextInt();
    long sum = 0;

    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int l = 1; l <= k; l++) {
          int first = gcd(Math.max(i, j), Math.min(i, j));
          int res = gcd(Math.max(first, l), Math.min(first, l));
          sum += res;
        }
      }
    }

    System.out.println(sum);

  }

  private static int gcd(int a, int b) {
    int r = a % b;
    if (r == 0) {
      return b;
    } else {
      return gcd(b, r);
    }
  }

}

Measured memory_bytes: 36052
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)

bool debug=true;

/*    *************************************
	  * Written in New Computer           *
	  * The following code belongs to     *
	  * XiaoGeNintendo of HellHoleStudios *
	  *************************************
*/
template<typename T1,typename T2>ostream& operator<<(ostream& os,pair<T1,T2> ptt){
	os<<ptt.first<<","<<ptt.second;
	return os;
}
template<typename T>ostream& operator<<(ostream& os,vector<T> vt){
	os<<"{";
	for(int i=0;i<vt.size();i++){
		os<<vt[i]<<" ";
	}
	os<<"}";
	return os;
}

int x[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(int argc,char* argv[]){
	int k;
	cin>>k;
	cout<<x[k-1]<<endl;
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
    public static void Main()
    {
        HashSet<int> set = new HashSet<int>();
        set.Add(GetInt());
        set.Add(GetInt());
        set.Add(GetInt());
        Console.WriteLine(set.Count);
    }
}

public static class MyIO
{
    private static string[] args = null;
    private static int num = -1;
    private static int used = -1;

    private static string getArg()
    {
        if (used == num)
        {
            args = Console.ReadLine().Split(' ');
            num = args.Length;
            used = 0;
        }
        return args[used++];
    }

    public static int GetInt() { return int.Parse(getArg()); }
    public static long GetLong() { return long.Parse(getArg()); }
    public static double GetDouble() { return double.Parse(getArg()); }
    public static string GetString() { return getArg(); }
}


Measured memory_bytes: 11348
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		Map<String,Integer> map = new HashMap<String,Integer>();
		map.put("SUN", 7);
		map.put("MON", 6);
		map.put("TUE", 5);
		map.put("WED", 4);
		map.put("THU", 3);
		map.put("FRI", 2);
		map.put("SAT", 1);

		System.out.println(map.get(sc.next()));

	}
}

Measured memory_bytes: 22996
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 15, inf = 1e9;
char cn[cm], * ci = cn, ct;

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


	fread(cn, 1, cm, stdin);

	int N = 0, M = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
	while ((ct = *ci++) >= '0') M = M * 10 + ct - '0';
	
	int E[100][100];
	rep(i, N) rep(j, N) E[i][j] = inf;

	rep(i, M) {
		int a = 0, b = 0, c = 0;
		while ((ct = *ci++) >= '0') a = a * 10 + ct - '0';
		while ((ct = *ci++) >= '0') b = b * 10 + ct - '0';
		while ((ct = *ci++) >= '0') c = c * 10 + ct - '0';
		a--;
		b--;
		E[a][b] = c;
		E[b][a] = c;
	}

	bool kotae[100][100] = {};
	rep(k, N) {
		rep(j, k) {
			rep(i, j) {
				if (E[i][j] > E[i][k] + E[j][k]) {
					E[i][j] = E[i][k] + E[j][k];
					kotae[i][j] = 1;
				}
			}
		}
		for (int j = k + 1; j < N; j++) {
			rep(i, k) {
				if (E[i][j] > E[i][k] + E[k][j]) {
					E[i][j] = E[i][k] + E[k][j];
					kotae[i][j] = 1;
				}
			}
			for (int i = k + 1; i < j; i++) {
				if (E[i][j] > E[k][i] + E[k][j]) {
					E[i][j] = E[k][i] + E[k][j];
					kotae[i][j] = 1;
				}
			}
		}
	}

	int kazu = 0;
	rep(i, N) rep(j, N) kazu += kotae[i][j];

	printf("%d", kazu - N * (N - 1) / 2 + M);

	Would you please return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
sw=[]
for _ in range(M):
    sw.append(list(map(int,input().split()))[1:])
p=[int(i) for i in input().split()]

ans=0
for i in range(1<<N):
    flg=True

    for c,s in enumerate(sw):
        s_on=0
        for bit in s:
            if ((i >> (bit-1)) & 1) == 1:
                s_on+=1
        if s_on%2!=p[c]:
            flg=False

    if flg:
        ans+=1

print(ans)

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

SUM = sum(A)
tmp = 0
for i in range(1,N,2):
    tmp += A[i]
ans = [0]*N
ans[0] = SUM - 2*tmp
for i in range(1,N):
    ans[i] = 2*A[i-1] - ans[i-1]
print(*ans)

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

using namespace std;

double W, H, x, y;

int main()
{
	cin >> W >> H >> x >> y;

	cout << W * H / 2.0 << " ";

	if (W == 2 * x && H == 2 * y) printf("1");
	else printf("0");

	return 0;
}

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

int main() {
	int Alice = 0;
	int Bob = 0;
	int N;
	cin >> N;
	vector<int> vec(N);

	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}

	sort(vec.begin(), vec.end(), greater<> ());

	for (int j = 0; j < N; j++) {
		if (j % 2 == 0) {
			Alice += vec.at(j);
		}
		else {
			Bob += vec.at(j);
		}
	}

	int Out = Alice - Bob;
	cout << Out;
}

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

int mx = 0x3f3f3f3f;
int cnt[3];
int n, c;
char ch;
int av;

int main() {
	while ((ch = getchar()) != '\n') {
		cnt[ch-97]++, n++;
	}
	for (int i = 0; i < 3; i++) {
		mx = min(mx, cnt[i]);
		av += !!cnt[i];
	}
	for (int i = 0; i < 3; i++) {
		if ((cnt[i] -= mx) > 1) {
			puts("NO");
			return 0;
		}
	}
	if ((av == 2 && n != 2) || (av == 1 && n > 1)) {
		puts("NO");
	} else {
		puts("YES");
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <boost/multiprecision/cpp_int.hpp>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

using namespace boost::multiprecision;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll A[100010];
cpp_int r[100010];

int main()
{
  std::cin >> N;

  rep( i, N+1 )
    std::cin >> A[i];

  cpp_int rb = 1;

  rep( i, N+1 )
  {
    rb -= A[i];
    r[i] = rb;

    if( (rb <= 0 && i != N) || (rb < 0 && i == N) )
    {
      std::cout << -1 << std::endl;

      return 0;
    }

    rb *= 2;
  }

  ll ans = A[N];
  ll p = A[N];

  repd( i, N )
  {
    ll mi = std::min( p, (ll)r[i] )+A[i];
    ans += mi;
    p = mi;
  }

  std::cout << ans << std::endl;

  return 0;
}

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

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

  vector<bool> tmp(K, false);
  vector<vector<bool>> dp_L(N, tmp), dp_R(N, tmp);
  dp_L[0][0] = dp_R[0][0] = true;

  for(ll i=0; i<N-1; ++i){
    dp_L[i+1] = dp_L[i];
    dp_R[i+1] = dp_R[i];
    ll aL = A[i], aR = A[N-1-i];
    if(aL<K){ for(ll j=0; j<K-aL; ++j) dp_L[i+1][j+aL] = dp_L[i][j]; }
    if(aR<K){ for(ll j=0; j<K-aR; ++j) dp_R[i+1][j+aR] = dp_R[i][j]; }
  }

  ll ans = 0;
  for(ll i=0; i<N; ++i) {
    vector<bool>& dl = dp_L[i];
    vector<bool>& dr = dp_R[N-1-i];

    bool noneed = true;
    ll ml = -K;
    for(ll j=0; j<K; ++j) {
      if (dl[j]) { ml = j; }
      if (dr[K-1-j] && j-ml<A[i]) {
        noneed = false;
        break;
      }
    }
    if (noneed) ++ans;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6912
#include<iostream>
#include<algorithm>
#include<set>

using namespace std;

int main(){
	int n;
	cin >> n;
	int P[100];
	for(int i=0; i<n; i++){
		cin >> P[i];
	}
	int ans = 0, tmp;
	for(int i=0; i<=100; i++){
		tmp = 0;
		for(int j=0; j<n; j++){
			if(P[j] >= i){
				tmp++;
			}
		}
		if(tmp >= i){
			ans = i;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;
signed main() {
	int N;
	cin >> N;
	vector<int> x(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	int res = 1;
	sort(x.begin(), x.end());
	int a = 0;
	for (int i = 0; i < N; i++) {
		if (i - a + 1 > (x[i] + 1) / 2) {
			res = (res*(i - a + 1)) % MOD;
			a++;
		}
	}
	while (a < N) {
		res = (res*(N-a)) % MOD;
		a++;
	}
	cout << res<< endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
vector<int> V[200050];
int arr[200050];
int lztg[200050];
void down(int now, int to)
{
	arr[to] = lztg[to] + now;
	int size = V[to].size();
	for(int i=0; i<size; i++)
		down(now + lztg[to], V[to][i]);
	return;
}
int main()
{
	int a, b;
	cin >> a >> b;
	memset(arr, 0, sizeof(arr));
	memset(lztg, 0, sizeof(lztg));
	for(int i=0; i<a-1; i++)
	{
		int c, d;
		cin >> c >> d;
		V[c].push_back(d);
	}
	for(int i=0; i<b; i++)
	{
		int c, d;
		cin >> c >> d;
		lztg[c] += d;
	}
	down(0, 1);
	for(int i=1; i<=a; i++)
		printf("%d ",arr[i]);
	return 0;
}

Measured memory_bytes: 24320
#include <iostream>

using namespace std;

int main() {
  int count_l[555555] = {};

  int N, Q;
  cin >> N >> Q;
  string s;
  cin >> s;
  int sum = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 2 && i + j < s.size(); j++) {
      if (s[i] == 'A' && s[i + j] == 'C') {
        sum++;
      }
      count_l[i + j] = sum;
    }
  }
  for (int q = 0; q < Q; q++) {
    int l, r;
    cin >> l >> r;
    cout << count_l[r-1] - count_l[l-1] << endl;
  }
}


Measured memory_bytes: 3200
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

  string s;
  cin >> s;

  int res = 0;
  string cur, ng;
  rep(i,s.size()) {
    cur.push_back(s[i]);
    if(cur != ng) {
      res++;
      ng = cur;
      cur = "";
    }
  }

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

Measured memory_bytes: 720
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	var n int
	var data []string

	if sc.Scan() {
		line := sc.Text()
		n, _ = strconv.Atoi(line)
	}

	if sc.Scan() {
		line := sc.Text()
		data = strings.Split(line, " ")
	}

	unMatch := 0
	for i := 1; i <= n; i++ {
		if data[i - 1] != strconv.Itoa(i) {
			unMatch++
		}
	}

	if unMatch == 0 || unMatch == 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 640
#include <cstdio>

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define iter_r(i, n) for (int i = n; i >= 1; --i)

#define NR 101000

int n, w[NR][4], odd[NR], oc, even[NR], ec;
bool t[NR];
void inc(int x) { for (; x <= n; x += x & -x) t[x] ^= 1; }
bool query(int x) { bool s = 0; for (; x; x -= x & -x) s ^= t[x]; return s; }

bool get_inv(int *a, int len) {
	iter(i, n) t[i] = 0;
	bool s = 0;
	iter_r(i, len) inc(a[i]), s ^= query(a[i] - 1);
//	printf("!%d %d\n", n, s);
	return s;
}

int getw(int a, int b, int c) {
	if (a + 1 == b && a + 2 == c && c % 3 == 0) return c / 3;
	if (a - 1 == b && a - 2 == c && a % 3 == 0) return -a / 3;
	return 0;
}

int main() {
	scanf("%d", &n);
	iter(k, 3) iter(i, n) scanf("%d", &w[i][k]);
	bool fo = 0, fe = 0;
	iter(i, n) {
		int tmp = getw(w[i][1], w[i][2], w[i][3]);
		if (tmp == 0) {
			puts("No");
			return 0;
		}
		if ((tmp % 2 + 2) % 2 != i % 2) {
			puts("No");
			return 0;
		}
		if (i % 2 == 1) {
			if (tmp < 0) tmp = -tmp, fo ^= 1;
			odd[++oc] = tmp;
		} else {
			if (tmp < 0) tmp = -tmp, fe ^= 1;
			even[++ec] = tmp;
		}
	}
	//iter(i, oc) printf("%d ", odd[i]); puts("");
	//iter(i, ec) printf("%d ", even[i]); puts("");
	//printf("%d %d\n", fo, fe);
	if (fe == get_inv(odd, oc) && fo == get_inv(even, ec)) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 2304