akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int>S(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  int ans=0;
   for(int i=0;i<N;i++){
     for(int j=i+1;j<N;j++){
       ans+=S[i]*S[j];
     }
   }
     cout<<ans<<endl;
}

Measured memory_bytes: 256
n = str(input())
s = len(n)
if s == 1:
     print(n)
elif s == 2:
     print(9)
elif s == 3:
     print(9 + int(n) - 99)
elif s == 4:
     print(9 + 900)
elif s == 5:
     print(909 + int(n) - 9999)
else:
     print(90909)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, M) = Read2Longs();
            var uft = new UnionFindTree(N);
            for (int i = 0; i < M; i++)
            {
                var (a, b) = Read2Longs();
                a--; b--;//インデックス変換
                uft.Union(a, b);
            }

            return Enumerable.Range(0, (int)N).Max(x => uft.GetSize(x));
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
    public class UnionFindTree
    {
        /// <summary>
        /// 親要素のインデックスを保持する
        /// 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ
        /// </summary>
        public long[] Parents { get; private set; }

        public UnionFindTree(long n)
        {
            Parents = new long[n];
            for (var i = 0; i < n; i++)
            {
                // 初期状態ではそれぞれが別のグループ(ルートは自分自身)
                // ルートなのでマイナスで要素数(1個)を保持する
                Parents[i] = -1;
            }
        }

        public bool Union(long x, long y)
        {
            var xRoot = Find(x);
            var yRoot = Find(y);

            // すでに同じグループの場合処理しない
            if (xRoot == yRoot) return false;

            // 要素数が少ないグループを多いほうに書き換えたい
            if (GetSize(xRoot) < GetSize(yRoot))
            {
                var tmp = xRoot;
                xRoot = yRoot;
                yRoot = tmp;
            }

            // まとめる先のグループの要素数を更新
            Parents[xRoot] += Parents[yRoot];

            // まとめられるグループのルートの親を書き換え
            Parents[yRoot] = xRoot;

            return true;
        }
        public bool IsUnited(long x, long y)
        {
            return Find(x) == Find(y);
        }
        public long Find(long x)
        {
            // 親がマイナスの場合は自分自身がルート
            if (Parents[x] < 0) return x;

            // ルートが見つかるまで再帰的に探す
            // 見つかったルートにつなぎかえる
            Parents[x] = Find(Parents[x]);

            return Parents[x];
        }
        public long GetSize(long x)
        {
            // ルート要素を取得して、サイズを取得して返す
            return -Parents[Find(x)];
        }
    }
}


Measured memory_bytes: 43000
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

  
int main() {
  ll N,D,A;
  cin >> N >> D >> A;
  vector<pair<ll,ll>> xh(N);
  rep(i,N) {
    ll h;
    cin >> xh[i].first >> h;
    xh[i].second = (h+A-1)/A;
  }

  sort(rng(xh));
  vl xs(N);
  rep(i,N) {
    xs[i] = xh[i].first;
  }
  vl eff(N,0);
  
  rep(i,N) {
    eff[i] = upper_bound(rng(xs),xs[i]+2*D) - (xs.begin()+i+1);
  }
  ll ans = 0;
  vl imos(N+1,0);
  ll cnt = 0;
  rep(i,N) {
    cnt += imos[i];
    ll s = cnt + xh[i].second;
    if(s>0) {
      imos[min(eff[i]+i+1,N)] += s;
      ans += s;
      cnt -= s;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> get(Q);
  vector<int> point(N, K-Q);

  for (int i; i < Q; i++){
    cin >> get.at(i);
  }
  for (int i; i < Q; i++){
    point.at(get.at(i)-1)++;
  }
  for (int i; i < N; i++) {
    if (point.at(i) < 1) {
      cout << "No";
      if (i != N-1) {
        cout << endl;
      }
    }
    else {
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 1408
import java.io.*;
import java.util.Stack;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] exp = br.readLine().split(" ");
        Stack<Integer> stack = new Stack<Integer>();

        for (int i = 0; i < exp.length; i++) {
            if (exp[i].equals("+")) {
                stack.push(stack.pop() + stack.pop());
            } else if (exp[i].equals("-")) {
                stack.push(-stack.pop() + stack.pop());
            } else if (exp[i].equals("*")) {
                stack.push(stack.pop() * stack.pop());
            } else {
                stack.push(Integer.parseInt(exp[i]));
            }
        }

        System.out.println(stack.pop());
    }
}

Measured memory_bytes: 24220
N = int(input())
sticks = sorted(list(map(int, input().split())))

def calc(N, sticks):
    sums = [0 for i in range(1002)]
    for stick in sticks:
        for i in range(stick + 1):
            sums[i] += 1
    total = 0
    for i in range(N):
        for j in range(N):
            if i == j: continue
            a, b = sticks[i], sticks[j]

            lo = abs(b-a)+1
            hi = min(a+b, 1001)
            
            val = sums[lo] - sums[hi] - (lo <= a) - (lo <= b)
            if val <= 0: continue
            total += val
    return total // 6


print(calc(N, sticks))


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

using namespace std;

    const int n = 1e5+5;
    int num;
    int act[n][3];
    int dyn[3][n];
    
    int init(int a, int i){
        
    	if(i == num) return 0;
    	
    	if(dyn[a][i] != -1) return dyn[a][i];
    	int& res = dyn[a][i];
    	
    	if(a==0){
    	    
    		res=max(res, init(1, i+1)+act[i][0]);
    		res=max(res, init(2, i+1)+act[i][0]);
    	}
    	
    	if(a==1){
    	    
    		res=max(res, init(0, i+1)+act[i][1]);
    		res=max(res, init(2, i+1)+act[i][1]);
    	}
    	
    	if(a==2){
    	    
    		res=max(res, init(0, i+1)+act[i][2]);
    		res=max(res, init(1, i+1)+act[i][2]);
    	}
    	
    	
    	return res;
    }
    
    int main(){
        
    	cin>>num;
    	for(int i=0; i<num; i++) cin>>act[i][0]>>act[i][1]>>act[i][2];
    	memset(dyn, -1, sizeof dyn);
    	cout<<max(init(0,0),max(init(1,0),init(2,0)))<<"\n";
    	return 0;
    	
    }
     

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a,b,c;
	string ans="NO";
	cin>>a>>b>>c;
	if(b-a==c-b)ans="YES";
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int N; cin >> N;
  vector<double> v(N);
  rep(i,N) cin >> v[i];
  double sum=0;
  rep(i,N){
    sum+=v[i];
  }
  double cnt=0;
  rep(i,N){
    cnt+=v[i];
    if(cnt>(sum/2)){
      double ans1=abs((cnt-v[i])-(sum-cnt+v[i]));
      double ans2=abs(cnt-(sum-cnt));
      double ans=min(ans1,ans2);
      cout << ans << endl;
      return 0;
    }
  }
  
}

Measured memory_bytes: 256
from itertools import combinations

n = int(input())
lList = list(map(int, input().split()))
cou = 0
combList = list(map(list, combinations(list(range(n)), 3)))
for [i, j, k] in combList:
    if lList[i] != lList[j] and lList[i]!=lList[k] and lList[j]!=lList[k]:
        if lList[i] + lList[j] > lList[k] and lList[i] + lList[k] > lList[j] and lList[j] + lList[k] > lList[i]:
            cou += 1
print(cou)

Measured memory_bytes: 25548
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		while (sc.hasNextLine() == true) {
			String line = sc.nextLine();

			int[][] map = new int[3][3];
			for (int i = 0; i < map.length; i++) {
				for (int j = 0; j < map.length; j++) {
					switch (line.charAt(i * 3 + j)) {
					case 'o':
						map[i][j] = 0;
						break;
					case 'x':
						map[i][j] = 1;
						break;
					case 's':
						map[i][j] = -1;
						break;
					}
				}
			}
			
			char[] sides = new char[2];
			sides[0] = 'o';
			sides[1] = 'x';

			char ans = 'd';
			for (int i = 0; i < map.length; i++) {
				if ((map[0][i] == map[1][i]) && (map[1][i] == map[2][i]) && (map[0][i] != -1)) {
					ans = sides[map[0][i]];
					break;
				}
			}
			for (int i = 0; i < map.length; i++) {
				if ((map[i][0] == map[i][1]) && (map[i][1] == map[i][2]) && (map[i][0] != -1)) {
					ans = sides[map[i][0]];
					break;
				}
			}
			
			if ((map[0][0] == map[1][1]) && (map[1][1] == map[2][2]) && (map[1][1] != -1)) ans = sides[map[1][1]];
			if ((map[0][2] == map[1][1]) && (map[1][1] == map[2][0]) && (map[1][1] != -1)) ans = sides[map[1][1]];
			
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 25892
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define int long long
int MOD = 2305266692540551LL;
int BASE = 4001;
signed main() {
  ios::sync_with_stdio(false);
  string S, T; cin >> S >> T;
  if(S.size() < T.size()) swap(S, T);
  int alpha[26];
  alpha[0] = 1;
  for(int i = 1; i < 26; ++i) {
    alpha[i] = (alpha[i - 1] * BASE) % MOD;
  }
  for(int l = (int)T.size(); l >= 1; --l) {
    set<int> u;
    int hash;
    hash = 0;
    REP(i,l) {
      hash += alpha[T[i] - 'a'];
      hash %= MOD;
    }
    u.insert(hash);
    // cerr << T.substr(0, l) << " => " << hash << endl;
    for(int i = 1; i < (int)T.size() - l + 1; ++i) {
      hash -= alpha[T[i - 1] - 'a'];
      if(hash < 0) hash += MOD;
      hash += alpha[T[i - 1 + l] - 'a'];
      hash %= MOD;
      u.insert(hash);
      // cerr << T.substr(i, l) << " => " << hash << endl;
    }

    hash = 0;
    REP(i,l) {
      hash += alpha[S[i] - 'a'];
      hash %= MOD;
    }
    if(u.count(hash)) {
      cout << l << endl;
      return 0;
    }
    // cerr << S.substr(0, l) << " => " << hash << endl;
    for(int i = 1; i < (int)S.size() - l + 1; ++i) {
      hash -= alpha[S[i - 1] - 'a'];
      if(hash < 0) hash += MOD;
      hash += alpha[S[i - 1 + l] - 'a'];
      hash %= MOD;
      // cerr << S.substr(i, l) << " => " << hash << endl;
      if(u.count(hash)) {
        cout << l << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
int main() {
    string str;
    cin >> str;
    vector<ll> num(4);
    for (ll i = 0; i < 4; ++i) {
        num[i] = str[i] - '0';
#ifdef SOURCE_TEST
        cout << num[i] << "\n";
#endif
    }
    for (ll i = 0; i < 1U << 3; ++i) {
        ll sum = num[0];
        for (ll j = 0; j < 3; ++j) {
            if (i & (1U << j)) {
#ifdef SOURCE_TEST
                cout << sum << "+=" << num[j + 1] << "\n";
#endif
                sum += num[j + 1];
            } else {
#ifdef SOURCE_TEST
                cout << sum << "-=" << num[j + 1] << "\n";
#endif
                sum -= num[j + 1];
            }
        }
#ifdef SOURCE_TEST
        cout << "ans==" << sum << endl;
#endif
        if (sum == 7) {
            cout << num[0];
            for (ll j = 0; j < 3; ++j) {
                if (i & (1U << j)) {
                    cout << "+";
                } else {
                    cout << "-";
                }
                cout << num[j + 1];
            }
            cout << "=7\n";
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3600
#include <cstdio>

int main()
{
	char s[5];

	scanf("%s", s);

	int i;

	int count = 0;

	for (i = 0; i < 3; i++)
	{
		if (s[i] == 'o')
			count++;
	}

	printf("%d",700 + count * 100);
}

Measured memory_bytes: 128
import math

def isprime(x):
	sq = int(math.sqrt(x))
	for i in range(2, sq + 1):
		if x % i == 0:
			return False
	return x != 1

array = []
N = int(raw_input())
for i in range(0, N):
	array.append(int(raw_input()))

count = 0
for i in array:
	if isprime(i):
		count += 1
print count

Measured memory_bytes: 5060
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> a(N);
  range(i, N) std::cin >> a[i];
  int tmp = 0, count = 0;
  range(i, N){
    if(a[i]!=tmp) tmp = a[i];
    else{
      count++;
      i++;
      tmp=a[min(N-1, i)];
    }
  }
  std::cout << count << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream&o,const pair<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
template<typename T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
V<pll> v, v2;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    ll x, y;
    cin >> x >> y;
    if (!x&&!y) continue;
    v.pb(mp(x, y));
    v2.pb(mp( x,  y));
    v2.pb(mp( x, -y));
    v2.pb(mp(-x,  y));
    v2.pb(mp(-x, -y));
  }
  ll ans = 0;
  for(auto a:v2){
    ll sx=0, sy=0;
    for(auto b:v){
      ll op = a.fi*b.se-a.se*b.fi;
      ll ip = a.fi*b.fi+a.se*b.se;
      if(op>0 || op==0&&ip>0) sx+=b.fi, sy+=b.se;
    }
    maxs(ans, sx*sx + sy*sy);
  }
  dout(sqrt(ans));
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    vector <vector<pii> > b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i].resize(a[i]);
        for (auto &j : b[i]) {
            cin >> j.y >> j.x;
            --j.y;
        }
    }
    int ans = 0;
    for (int i = 1; i < (1 << n); i++) {
        int res = 0;
        vector <int> used(n);
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                ++res;
                used[j] = 1;
            }
        }
        if (ans >= res) continue;
        bool ok = true;
        for (int j = 0; j < n; j++) {
            if (!used[j]) continue;
            for (auto &k : b[j]) {
                if (k.x) {
                    if (!used[k.y]) {
                        ok = false;
                    }
                }
                else {
                    if (used[k.y]) {
                        ok = false;
                    }
                }
            }
        }
        if (ok) ans = res;
    }
    cout << ans << '\n';
}


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

int main() {

  int counter =0;
  int dream=0;
  int dreamer=0;
  int eraser=0;
  int erase=0;
  int dream_erase=0;
  int dream_eraser=0;
  string str;
  cin >> str;

  //cout<<str.size()<<endl;

  for(int i=0;i<(int)str.size();i++){
    if((i+5)<=(int)str.size()){
    if(std::equal(str.begin()+i, str.begin()+i+5, "dream")){
      dream++;
    }}
    if((i+7)<=(int)str.size()){
    if(std::equal(str.begin()+i, str.begin()+i+7,  "dreamer")){
      dreamer++;
    }}
    if((i+5)<=(int)str.size()){
    if(std::equal(str.begin()+i, str.begin()+i+5,  "erase")){
        erase++;
    }}
    if((i+6)<=(int)str.size()){
    if(std::equal(str.begin()+i, str.begin()+i+6,  "eraser")){
      eraser++;
    }}
    if((i+11)<=(int)str.size()){
    if(std::equal(str.begin()+i, str.begin()+i+11,  "dreameraser")){
      dream_eraser++;
    }}
    if((i+10)<=(int)str.size()){
    if(std::equal(str.begin()+i, str.begin()+i+10,"dreamerase")){
      dream_erase++;
    }}
  }
  dream_erase = dream_erase - dream_eraser;
  eraser = eraser - dream_eraser;
  dreamer = dreamer - dream_erase - dream_eraser;
  dream = dream - dreamer - dream_erase - dream_eraser;
  erase = erase - eraser - dream_erase - dream_eraser;

  counter = dream *5 + dreamer*7 +erase*5 + eraser * 6 + dream_erase*10 + dream_eraser * 11;
  // cout <<counter << endl;
  if(counter == (int)str.size()){
      cout <<"YES" << endl;
        return 0;
  }
  cout << "NO" << endl;
    return 0;

}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[110000];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	int ret=n;
	
	for(int i=0;i<n-1;i++){
		if(in[i]!=in[i+1])ret=min(ret,max(i+1,n-1-i));
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 256
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const [[, quantum], ...tasks] = content
    .trim()
    .split('\n')
    .map(line => {
      const [name, time] = line.split(' ');
      return [name, +time];
    });
  
  let cur = 0;
  while (tasks.length > 0) {
    const task = tasks.shift();
    const time = Math.min(task[1], quantum);
    cur += time;
    task[1] -= time;

    if (task[1] > 0) {
      tasks.push(task);
    } else {
      console.log(task[0], cur);
    }
  }
});



Measured memory_bytes: 61632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

map< ll, int > prime_factor(ll n) {
    map< ll, int > ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

void solve(int ca){
    ll N; cin>>N;

    map<ll,int> p = prime_factor(N);

    ll ans=0;
    for(auto i:p){
        int tmp=0;
        int cnt=0;
        for (int j = 1; j < 50; ++j) {
            tmp+=j;
            cnt++;
            if(tmp>i.second){
                //cout<<i.first<<" "<<i.second<<" "<<cnt<<endl;
                ans+=(ll)cnt-1;
                break;
            }
        }
    }
    cout<<ans<<endl;


}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


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

int main(){
    char s[5];
    cin >>s;

    bitset<3> bit(0);
    for(int mask=0; mask <(1 << 3); mask++){
        bit = mask;
        int sum = s[0]-'0';
        string disp ="";
        disp+=s[0];
        for(int i=0; i<3; i++){
            if(bit[i]==1){
                sum+=s[i+1]-'0';
                disp+="+";
                disp+=s[i+1];
            }
            else{
                sum-=s[i+1]-'0';
                disp+="-";
                disp+=s[i+1];
            }
        }
        if(sum == 7){
            cout << disp+"=7" << endl;
            break;
        } 
            
    }
    return 0;
}

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

#ifdef LOCAL

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<template<class, class...> class C, class... A>
typename enable_if<!is_same<C<A...>, string>::value, ostream&>::type
operator<<(ostream& os, const C<A...> &c) {
	auto i = c.begin();
	while (i != c.end()) {
		os << " {"[i == c.begin()] << *i;
		os << ",}"[++i == c.end()];
	}
	return os;
}

#define debug(x) cerr << #x << " = " << x << endl;

#else
#define debug(...) {}
#endif

const int N = 1e6 + 5;

#define st first
#define nd second

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

vector<int> przerwy;
string slowo;

char slo[N];

int policz() {
	string rs = slowo;
	reverse(rs.begin(), rs.end());
	debug(slowo);
	debug(rs);
	if (rs != slowo) return -1;
	vector<int> rp = przerwy;
	reverse(rp.begin(), rp.end());
	long long wynik = 0;
	for (int i = 0; i < przerwy.size(); i ++) {
		wynik += abs(przerwy[i] - rp[i]);
	}
	return wynik / 2;
}

int main() {
	scanf("%s", slo);
	przerwy.resize(1);
	for (int i = 0; slo[i]; i ++) {
		if (slo[i] != 'x') {
			slowo.push_back(slo[i]);
			przerwy.push_back(0);
		}
		else {
			przerwy.back() ++;
		}
	}
	printf("%d\n", policz());
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    int tmp;
    int ret = 1;
    for (int i = 0; i < n; ++i)
    {
        cin >> tmp;
        if (tmp % 2 == 1)
        {
            ret *= 1;
        }
        else
        {
            ret *= 2;
        }
    }
    ret = pow(3, n) - ret;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	ll N;
	cin >> N;
	vector<int> V;
	while(N != 0){
		N--;
		V.pb(N%26);
		N /= 26;
	}
	for(int i = V.size()-1; i >= 0; i--){
		cout << (char)(V[i] + 'a');
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[]str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int X = int.Parse(str[1])-1;
		int Y = int.Parse(str[2])-1;
		long[]A = new long[N];
		for(var i=0;i<N;i++){
			for(var j=i+1;j<N;j++){
				if(i<=X && j<=X){
					A[Math.Abs(j-i)]++;
				} else if(i>=Y && j>=Y){
					A[Math.Abs(j-i)]++;
				} else if(i<=X && j>=Y){
					A[Math.Abs(X-i)+Math.Abs(Y-j)+1]++;
				} else {
                  	A[Math.Min(Math.Abs(i-j),Math.Abs(X-i)+1+Math.Abs(Y-j))]++;
                }
			}
		}
		for(var i=1;i<=N-1;i++){
			Console.WriteLine(A[i]);
		}
	}
}


Measured memory_bytes: 13116
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
 
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define int long long
 
int32_t main(){ fast;
	int k, a, b; cin>>k>>a>>b;
	for(int i = a; i <= b; i++){
		if(i % k == 0){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
}


Measured memory_bytes: 3644
#include <stdio.h>

int main(void){
    
    int n;
    scanf("%d",&n);

    int a[1000000];
    for(int i=1; i<=n+1; i++){
        scanf("%d",&a[i]);
    }

    int b[1000000];
    for(int i=1; i<=n; i++){
        scanf("%d",&b[i]);
    }

    long long cnt = 0;
    
    for(int i=1; i<=n; i++){
       if(a[i]+a[i+1]>=b[i]){
           cnt+=b[i];
           if(a[i]<=b[i]){
               a[i+1]=a[i]+a[i+1]-b[i];
           }
       }
       else{
            cnt+=a[i]+a[i+1];
            a[i+1]=0;
       }
    }

    printf("%lld\n", cnt);

    return 0;
}


Measured memory_bytes: 6528
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <iostream>
#include <climits>

using namespace std;

typedef long long ll;

ll A[200005];

int main(){

	int N;
	scanf("%d",&N);

	int i;
	for(i=0;i<N;i++){
	scanf(" %lld",&A[i]);
	}

	for(i=1;i<N;i++){
	A[i]+=A[i-1];
	}

	ll ans=LLONG_MAX;

	for(i=1;i<=N-3;i++){
	ll sum_l=A[i];
	ll sum_r=A[N-1]-A[i];

	int l,r;

	l=1;
	r=i;

	while(l<r){
	int mid=(l+r)/2;
	if(A[mid]>sum_l-A[mid]){
	r=mid;
	}
	else{
	l=mid+1;
	}
	}

	ll ma,mi;

	ll s11,s12,s21,s22;

	s11=llabs(A[l]-(sum_l-A[l]));
	s12=llabs(A[l-1]-(sum_l-A[l-1]));

	if(s11<s12){
	ma=max(A[l],sum_l-A[l]);
	mi=min(A[l],sum_l-A[l]);
	}
	else{
	ma=max(A[l-1],sum_l-A[l-1]);
	mi=min(A[l-1],sum_l-A[l-1]);
	}

	l=i+2;
	r=N-1;

	while(l<r){
	int mid=(l+r)/2;
	if(A[mid]-sum_l>sum_r-(A[mid]-sum_l)){
	r=mid;
	}
	else{
	l=mid+1;
	}
	}

	s21=llabs(A[l]-sum_l-(sum_r-(A[l]-sum_l)));
	s22=llabs(A[l-1]-sum_l-(sum_r-(A[l-1]-sum_l)));

	if(s21<s22){
	ma=max(ma,max(A[l]-sum_l,sum_r-(A[l]-sum_l)));
	mi=min(mi,min(A[l]-sum_l,sum_r-(A[l]-sum_l)));
	}
	else{
	ma=max(ma,max(A[l-1]-sum_l,sum_r-(A[l-1]-sum_l)));
	mi=min(mi,min(A[l-1]-sum_l,sum_r-(A[l-1]-sum_l)));
	}

	if(ans>ma-mi){ans=ma-mi;}

	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
    int n;
    char a[100];
    cin >> n;
    cin >> a;
    char *p=a;
    int ret=0;
    while(strstr(p,"ABC")!=NULL)
    {
        p=strstr(p,"ABC")+3;
        ret++;
    }
    cout << ret;
    return 0;
}


Measured memory_bytes: 256
n,h=map(int,input().split())
a=[];b=[]
for i in range(n):
  q,w=map(int,input().split())
  a+=[q]
  b+=[w]
m=max(a)
b=[i for i in b if i>=m]
b.sort(reverse=True)
x=0
for i in b:
  h-=i
  x+=1
  if h<=0:
    break
if h>0:
  x+=-(-h//m)
print(x)

Measured memory_bytes: 11752
#include <bits/stdc++.h>
using namespace std;
int n,i,j,a[200010],maxi,maxi2;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]>=maxi)
        {
            maxi2=maxi;
            maxi=a[i];
        }
        else if(a[i]>maxi2)
            maxi2=a[i];
    }
    for(i=1;i<=n;i++)
    {
        if(a[i]==maxi)
            cout<<maxi2<<'\n';
        else cout<<maxi<<'\n';
    }
    return 0;
}



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

using namespace std;

int main(){
    int N, A, B;
	int n;
  	cin >> N >> A >> B;
	
	int sum = 0;
	int digit_sum = 0;

	for(int i = 1; i <= N; i++){
		digit_sum = 0;
		n = i;
		do{
			digit_sum = digit_sum + n%10;
			n = (n-n%10)/10;
		}while(n > 0);
		
		if(A <= digit_sum && digit_sum <= B){
			sum = sum + i;
		}
	}

	cout << sum << endl;

	return 0;
}


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

int main(void) {
   
   int N;
   
   scanf("%d", &N);
   
   int x = (int)(N/1.08);
   
   if ((int)(x*1.08) == N) {
      printf("%d\n",x);
   }
   else if ((int)((x + 1)*1.08) == N) {
      printf("%d\n",x+1);
   }
   else {
      printf(":(\n");
   }
   
   
   
   return 0;
}


Measured memory_bytes: 128
N, A, B, C, D = map(int, input().split())
S = input()

s_cnt = 0
max_s_cnt = 0
pre_s = ''

goal = max(C, D)

if C < B:
  for i in range(A-1, C):
    if pre_s == "#":
      if S[i] == "#":
        print("No")
        exit()
    pre_s = S[i]
  for i in range(B-1, D):
    if pre_s == "#":
      if S[i] == "#":
        print("No")
        exit()
    pre_s = S[i]
  print("Yes")
  exit()

for i in range(A-1, goal):
  if pre_s == "#":
    if S[i] == "#":
      print("No")
      exit()
  if i >= B - 2 and i < D + 1:
    if S[i] == '.':
      s_cnt += 1
      if max_s_cnt < s_cnt:
        max_s_cnt = s_cnt
    else:
      s_cnt = 0
  pre_s = S[i]
#  print(max_s_cnt)
  
if C < D:
  print("Yes")
else:
  if max_s_cnt >= 3:
    print("Yes")
  else:
    print("No")
  


Measured memory_bytes: 3572
function Main(input) {
  var N = parseInt(input[0], 10);
  var d = input.slice(1).map(w => parseInt(w, 10));

  d.sort((a,b) => a - b);

  var half = N / 2;

  var diff = d[half] - d[half - 1];

  console.log(diff);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 27168
using System;
using System.Linq;

class Program {
    static void Main() {
        while(true) {
            string[] stdin = Console.ReadLine().Split();
            int m = int.Parse(stdin[0]);
            int f = int.Parse(stdin[1]);
            int r = int.Parse(stdin[2]);
            if(m == -1 && f == -1 && r == -1) break;
            char ans;
            if(m == -1 || f == -1) ans = 'F';
            else if(m + f >= 80) ans = 'A';
            else if(m + f >= 65) ans = 'B';
            else if(m + f >= 50) ans = 'C';
            else if(m + f >= 30) {
                if(r >= 50) ans = 'C';
                else ans = 'D';
            }else ans = 'F';
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17936
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

int N;
int fact(int x){
    if(x==0)return 1;
    int rev=1;
    for(int i=2;i<=x;i++){
        rev*=i;
    }
    return rev;
}
int func(vec v){
    int rev=0;
    set<int> S;
    for(int i=1;i<=N;i++){
        S.insert(i);
    }
    for(int i=0;i<N;i++){
        int k=0;
        for(int j=1;j<v[i];j++){
            auto itr=S.find(j);
            if(itr!=S.end()){k++;}
        }
        rev+=k*fact(N-i-1);
        S.erase(v[i]);
    }
    return rev;
}

int main(){
    cin>>N;
    vec P(N),Q(N);
    for(int i=0;i<N;i++){
        cin>>P[i];
    }
    for(int i=0;i<N;i++){
        cin>>Q[i];
    }
    cout<<abs(func(P)-func(Q))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
//#define endl "\n"
//#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
    return false;
}
bool cmp(int n, pair<int, int> const& p)
{
    return (p.first < n);
}
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e18;
ll const maxn = 2e5+1;

ll dis[maxn], vis[maxn];
vector<ll> nodes[maxn];

void dfs(ll x){
     ll parWgt = dis[x];

     vis[x]=1;
     for(auto ch : nodes[x]){
          if(vis[ch]==0){
               dis[ch]+=parWgt;
               dfs(ch);
          }
     }
}

void solve()
{    

     ll n,q; cin >> n >> q;
     f(i,1,n){
          ll u, v; cin >> u >> v;
          nodes[u].pb(v);
          nodes[v].pb(u);
     }

     f(i,0,q){
          ll p,x; cin >> p >> x;
          dis[p]+=x;
     }

     dfs(1);

     f(i,0,n)
          cout << dis[i+1] << " ";
     
}

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
          
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}

Measured memory_bytes: 27032
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#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>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    string S;
    READV(N);
    cin>>S;
    if (N%2==0)
    {
        FORI(i,0,N/2)
        {
            if(S[i]!=S[i+(N/2)])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<algorithm>
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long 
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    int n;
    in(n);
    int dp[n+1],ar[n+1];
    l(i,1,n+1)
    in(ar[i]);
    dp[1]=0;
    if(n!=1)
    dp[2]= abs(ar[2]-ar[1]);
    l(i,3,n+1)
    {
       dp[i]=min (dp[i-1]+abs(ar[i]-ar[i-1]),dp[i-2]+abs(ar[i]-ar[i-2]));
    }
    o(dp[n]);
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

struct node{
    int parent, left, right, sibling;
    int depth, height;
    node(){ parent=-1; depth=-2; height=-2; }
};

vector<node> tree;

int traverse(int id, int current_depth)
{
    if(id==-1){
        return -1;
    }
    auto nd=&tree[id];
    if(nd->parent!=-1){
        if(tree[nd->parent].left!=id){
            nd->sibling=tree[nd->parent].left;
        } else{
            nd->sibling=tree[nd->parent].right;
        }
    } else{
        nd->sibling=-1;
    }
    nd->depth=current_depth;
    nd->height=max(traverse(nd->left, current_depth+1),
                   traverse(nd->right, current_depth+1))+1;
    return nd->height;
}

int main()
{
    int n;
    scanf("%d", &n);
    tree=vector<node>(n);
    for(int i=0; i<n; i++){
        int id; scanf("%d", &id);
        auto it=&tree[id];
        scanf("%d %d", &it->left, &it->right);
        if(it->left!=-1){
            tree[it->left].parent=id;
        }
        if(it->right!=-1){
            tree[it->right].parent=id;
        }
    }

    for(auto it=tree.begin(); it!=tree.end(); it++){
        if(it->parent==-1){
            traverse(distance(tree.begin(), it), 0);
            break;
        }
    }

    for(int i=0; i<n; i++){
        auto it=&tree[i];
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
                i,
                it->parent,
                it->sibling,
                (it->left!=-1)+(it->right!=-1),
                it->depth,
                it->height);
        if(it->parent==-1){
            printf("root");
        } else if(it->left==-1 && it->right==-1){
            printf("leaf");
        } else{
            printf("internal node");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 2660
#include <stdio.h>

int main(int argc, char *argv[])
{
	int n;
	int i;
	int p;
	int p_max;
	int sum;

	scanf("%d", &n);

	p_max = 0;
	sum = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &p);
		if (p > p_max) {p_max = p;}
		sum += p;
	}

	sum -= p_max / 2;

	printf("%d\n", sum);


	return(0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  string s; cin >> s;
  string d[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  for (int i = 0; i < 7; i ++) {
    if (s == d[i]) {
      cout << 7 - i << endl;
    }
  }
}

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

int main() { /* ここに書く */
  
  string pd;
  cin >> pd;
  
  int size,a;
  size = pd.size();
  
  for(int i = 0; i<size ; i++){
    
    a = pd.at(i);
    
    if( a == 'P' ){
      cout << 'P' ;}
    
    else{
      cout << 'D' ;}
    
  }
  
  cout << endl;
  
}


Measured memory_bytes: 3724
s = gets.chomp.split("")
n = s.size
l = 0
r = 2
count = Array.new(26,0)
count[s[l].ord-'a'.ord] += 1
count[s[l+1].ord-'a'.ord] += 1
until r == n do
  count[s[r].ord-'a'.ord] += 1
  break if count[s[r].ord-'a'.ord] >= 2 || count[s[l].ord-'a'.ord] >= 2
  count[s[l].ord-'a'.ord] -= 1
  l += 1
  r += 1
end

if n == 2 then
  if s[0] == s[1] then
    puts "1 2"
  else
    puts "-1 -1"
  end
elsif r != n then
  puts "#{l+1} #{r+1}"
else
  puts "-1 -1"
end


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

def solve():
    H, W = list(map(int, input().split()))
    S = [None] * H

    for i in range(H):
        S[i] = input()
    
    ans = [["#" for w in range(W)] for h in range(H)]
    for h in range(H):
        for w in range(W):
            if S[h][w] == ".":
                bomb = 0
                if w-1 >= 0 and h-1 >= 0:
                    if S[h-1][w-1] == "#":
                        bomb += 1
                if h-1 >= 0:
                    if S[h-1][w] == "#":
                        bomb += 1
                if h-1 >= 0 and w+1 < W:
                    if S[h-1][w+1] == "#":
                        bomb += 1
                if w-1 >= 0:
                    if S[h][w-1] == "#":
                        bomb += 1
                if w+1 < W:
                    if S[h][w+1] == "#":
                        bomb += 1
                if h+1 < H and w-1 >= 0:
                    if S[h+1][w-1] == "#":
                        bomb += 1
                if h+1 < H:
                    if S[h+1][w] == "#":
                        bomb += 1
                if h+1 < H and w+1 < W:
                    if S[h+1][w+1] == "#":
                        bomb += 1
                ans[h][w] = bomb
    
    for h in range(H):
        for w in range(W):
            print(ans[h][w], end="")
        print()

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3572
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.arange(N+1)
total = A.sum()
three = A[3::3].sum()
five = A[5::5].sum()
fifteen = A[15::15].sum()
answer = total - (three+five) + fifteen
print(answer)


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

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

    vector<Int> A(N);
    rep(i,N) cin >> A[i];

    vector<Int> S = {A[0]};
    rep1(i,N-1) S.push_back(S[i-1]+A[i]);

    Int ans = 1e18;
    for(int i=2; i<N-1; i++){
        // 左側 [0, i) 
        Int left_sum = S[i-1];
        int mid_l = lower_bound(S.begin(), S.begin()+i, left_sum/2) - S.begin();

        pair<Int,Int> left = {S[mid_l], left_sum-S[mid_l]};
        if(mid_l != 0){
            pair<Int,Int> left2 = {S[mid_l-1], left_sum-S[mid_l-1]};
            if (abs(left2.first-left2.second) < abs(left.first-left.second)){
                left = left2;
            }
        }

        // 右側 [i,N)
        int mid_r = lower_bound(S.begin()+i, S.end(), (S.back() + left_sum)/2) - S.begin();
        pair<Int,Int> right = {S[mid_r] - left_sum, S.back()-S[mid_r]};
        if(mid_r != i){
            pair<Int,Int> right2 = {S[mid_r-1] - left_sum, S.back()-S[mid_r-1]};
            if (abs(right2.first-right2.second) < abs(right.first-right.second)){
                right = right2;
            }
        }

        Int M = max(left.first, max(left.second, max(right.first, right.second))); 
        Int m = min(left.first, min(left.second, min(right.first, right.second)));
        ans = min(ans, M-m);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3956